From 73caeff437a516eec12451bb7dad099067e24de4 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 26 Jan 2016 23:30:39 -0800 Subject: [PATCH] Simplify mouse movement code --- KeyboardioFirmware.h | 3 --- KeyboardioFirmware.ino | 7 ++----- mouse_movement.cpp | 13 ++++++------- mouse_movement.h | 4 ++-- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/KeyboardioFirmware.h b/KeyboardioFirmware.h index 786f7d73..b6c351e1 100644 --- a/KeyboardioFirmware.h +++ b/KeyboardioFirmware.h @@ -31,9 +31,6 @@ void setup(); #include "mouse_movement.h" #include "storage.h" -char x; -char y; - uint8_t matrixState[ROWS][COLS] = {0}; static const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_LIST }; diff --git a/KeyboardioFirmware.ino b/KeyboardioFirmware.ino index ecc16a07..447d854f 100644 --- a/KeyboardioFirmware.ino +++ b/KeyboardioFirmware.ino @@ -43,13 +43,10 @@ void setup() { void loop() { - x = 0; - y = 0; scan_matrix(); - LEDs.update_leds(temporary_keymap); Keyboard.sendReport(); Keyboard.releaseAll(); - move_mouse(x, y); + LEDs.update_leds(temporary_keymap); } @@ -62,7 +59,7 @@ void handle_synthetic_key_event(byte switchState, Key mappedKey) { warp_mouse(mappedKey); } } else { - handle_mouse_key_press(switchState, mappedKey, x, y); + handle_mouse_key_press(switchState, mappedKey); } } if (mappedKey.flags & IS_CONSUMER) { diff --git a/mouse_movement.cpp b/mouse_movement.cpp index 3518ce23..8ba1c742 100644 --- a/mouse_movement.cpp +++ b/mouse_movement.cpp @@ -89,7 +89,7 @@ double mouse_accel (double cycles) { return accel; } -void move_mouse( char x, char y) { +void move_mouse( int8_t x, int8_t y) { if (x != 0 || y != 0) { mouseActiveForCycles++; @@ -121,21 +121,20 @@ void move_mouse( char x, char y) { } -void handle_mouse_key_press(byte switchState, Key mappedKey, char &x, char &y) { - +void handle_mouse_key_press(byte switchState, Key mappedKey) { if (key_is_pressed(switchState)) { if (mappedKey.rawKey & MOUSE_UP) { - y -= 1; + move_mouse(0,-1); } if (mappedKey.rawKey & MOUSE_DN) { - y += 1; + move_mouse(0,1); } if (mappedKey.rawKey & MOUSE_L) { - x -= 1; + move_mouse(-1,0); } if (mappedKey.rawKey & MOUSE_R) { - x += 1 ; + move_mouse(1,0); } } } diff --git a/mouse_movement.h b/mouse_movement.h index a404b5a9..63695b5b 100644 --- a/mouse_movement.h +++ b/mouse_movement.h @@ -4,8 +4,8 @@ // Mouse-related 'public' API methods double mouse_accel (double cycles); -void handle_mouse_key_press(byte switchState, Key mappedKey, char &x, char &y); -void move_mouse( char x, char y); +void handle_mouse_key_press(byte switchState, Key mappedKey); +void move_mouse( int8_t x, int8_t y); void begin_warping(); void end_warping(); void warp_mouse(Key key);