From 41d57b598add3219bcfa87a756ae4e06ce1f9f15 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 2 Feb 2017 09:58:54 +0100 Subject: [PATCH] Use a single accel counter Instead of calculating separate acceleration for the x and y axes, use only a single one, that applies to both axes. Thus, holding mouse up, and then pressing and holding right will move the mouse cursor in a straight diagonal line, instead of a curve. Signed-off-by: Gergely Nagy --- src/Keyboardio-MouseKeys.cpp | 25 ++++++++++++------------- src/MouseWrapper.cpp | 12 ++++-------- src/MouseWrapper.h | 4 ++-- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/Keyboardio-MouseKeys.cpp b/src/Keyboardio-MouseKeys.cpp index e8af08d7..9a61e123 100644 --- a/src/Keyboardio-MouseKeys.cpp +++ b/src/Keyboardio-MouseKeys.cpp @@ -12,27 +12,26 @@ static void loopHook(bool postClear) { return; } + if (mouseMoveIntent == 0) { + MouseWrapper.mouseActiveForCycles = 0; + return; + } + + if (MouseWrapper.mouseActiveForCycles < 255) + MouseWrapper.mouseActiveForCycles++; + if (mouseMoveIntent & KEY_MOUSE_UP) - MouseWrapper.move(0, -1); + MouseWrapper.move(0, -1); else if (mouseMoveIntent & KEY_MOUSE_DOWN) - MouseWrapper.move(0, 1); + MouseWrapper.move(0, 1); if (mouseMoveIntent & KEY_MOUSE_LEFT) - MouseWrapper.move(-1, 0); + MouseWrapper.move(-1, 0); else if (mouseMoveIntent & KEY_MOUSE_RIGHT) - MouseWrapper.move(1, 0); + MouseWrapper.move(1, 0); } static void handle_mouse_key_event(Key mappedKey, uint8_t keyState) { - if (key_toggled_off(keyState)) { - if (mappedKey.keyCode & KEY_MOUSE_UP || mappedKey.keyCode & KEY_MOUSE_DOWN) { - MouseWrapper.mouseActiveForCyclesY=0; - } - if (mappedKey.keyCode & KEY_MOUSE_LEFT || mappedKey.keyCode & KEY_MOUSE_RIGHT) { - MouseWrapper.mouseActiveForCyclesX=0; - } - } - if (!key_is_pressed(keyState)) return; diff --git a/src/MouseWrapper.cpp b/src/MouseWrapper.cpp index 8426f044..a8e8eaaf 100644 --- a/src/MouseWrapper.cpp +++ b/src/MouseWrapper.cpp @@ -103,18 +103,14 @@ void MouseWrapper_::move( int8_t x, int8_t y) { int16_t moveX =0; int16_t moveY = 0; if (x != 0 ) { - if (mouseActiveForCyclesX < 255) { mouseActiveForCyclesX++;} - moveX = (x * acceleration(mouseActiveForCyclesX)); + moveX = (x * acceleration(mouseActiveForCycles)); } if (y != 0) { - if (mouseActiveForCyclesY < 255) { mouseActiveForCyclesY++;} - moveY = (y * acceleration(mouseActiveForCyclesY)); - + moveY = (y * acceleration(mouseActiveForCycles)); } - - end_warping(); - Mouse.move(moveX, moveY, 0); + end_warping(); + Mouse.move(moveX, moveY, 0); } MouseWrapper_ MouseWrapper; diff --git a/src/MouseWrapper.h b/src/MouseWrapper.h index 4e8b7fd6..df2d98c8 100644 --- a/src/MouseWrapper.h +++ b/src/MouseWrapper.h @@ -37,8 +37,7 @@ class MouseWrapper_ { void warp(uint8_t warp_cmd); void press_button(uint8_t button); void release_button(uint8_t button); - uint8_t mouseActiveForCyclesX = 0; - uint8_t mouseActiveForCyclesY = 0; + uint8_t mouseActiveForCycles = 0; private: uint16_t next_width = 0; @@ -53,4 +52,5 @@ class MouseWrapper_ { void warp_jump(uint16_t left, uint16_t top, uint16_t height, uint16_t width); }; + extern MouseWrapper_ MouseWrapper;