From 7173a51c1a283a5e1a2eebdb7cb04dd1eb07495b Mon Sep 17 00:00:00 2001 From: 9R Date: Thu, 6 Apr 2023 21:23:42 +0200 Subject: [PATCH] add last_wasd to stop register_keycode spam --- .../handwired/replicazeron/common/thumbstick.c | 17 ++++++++++------- .../handwired/replicazeron/common/thumbstick.h | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/keyboards/handwired/replicazeron/common/thumbstick.c b/keyboards/handwired/replicazeron/common/thumbstick.c index 1d5dfc270c7..a96d123c63d 100644 --- a/keyboards/handwired/replicazeron/common/thumbstick.c +++ b/keyboards/handwired/replicazeron/common/thumbstick.c @@ -18,6 +18,7 @@ void init_wasd_state (void) { wasd_state.w = wasd_state.a = wasd_state.s = wasd_state.d = false; + last_wasd_state = wasd_state; wasd_state.shift = false; } @@ -47,10 +48,10 @@ bool update_keystate(uint16_t angle_from, uint16_t angle_to, uint16_t angle) { return (angle_from < angle && angle <= angle_to); } -void update_keycode(uint16_t keycode, bool keystate) { - if (keystate) { +void update_keycode(uint16_t keycode, bool keystate, bool last_keystate) { + if (keystate && keystate != last_keystate) { register_code16(keycode); - } else { + } else if (!keystate) { unregister_code16(keycode); } } @@ -89,10 +90,12 @@ void thumbstick(controller_state_t controller_state) { dprintf("w: %2d a: %2d s: %2d d: %2d\n", wasd_state.w, wasd_state.a, wasd_state.s, wasd_state.d); #endif - update_keycode(KC_W, wasd_state.w); - update_keycode(KC_A, wasd_state.a); - update_keycode(KC_S, wasd_state.s); - update_keycode(KC_D, wasd_state.d); + update_keycode(KC_W, wasd_state.w, last_wasd_state.w); + update_keycode(KC_A, wasd_state.a, last_wasd_state.a); + update_keycode(KC_S, wasd_state.s, last_wasd_state.s); + update_keycode(KC_D, wasd_state.d, last_wasd_state.d); + + last_wasd_state = wasd_state ; // handle WASD-Shift mode if (controller_state.wasdShiftMode) { diff --git a/keyboards/handwired/replicazeron/common/thumbstick.h b/keyboards/handwired/replicazeron/common/thumbstick.h index 175d1df4fb9..7c784de4564 100644 --- a/keyboards/handwired/replicazeron/common/thumbstick.h +++ b/keyboards/handwired/replicazeron/common/thumbstick.h @@ -40,6 +40,7 @@ typedef struct { thumbstick_polar_position_t thumbstick_polar_position ; wasd_state_t wasd_state; +wasd_state_t last_wasd_state; void init_wasd_state(void); @@ -47,6 +48,6 @@ thumbstick_polar_position_t get_thumbstick_polar_position(int16_t x, int16_t y); bool update_keystate(uint16_t angle_from, uint16_t angle_to, uint16_t angle); -void update_keycode(uint16_t keycode, bool keystate); +void update_keycode(uint16_t keycode, bool keystate, bool last_keystate); void thumbstick(controller_state_t controller_state);