From c05e8afe454bf3706d69314c251dc5266c557007 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 27 Mar 2022 05:38:09 +1100 Subject: Joystick feature updates (#16732) * Joystick feature updates * Move new functions to joystick.h * Docs --- quantum/process_keycode/process_joystick.c | 36 +++++++++--------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'quantum/process_keycode') diff --git a/quantum/process_keycode/process_joystick.c b/quantum/process_keycode/process_joystick.c index 2fb092c573..8c3e71616f 100644 --- a/quantum/process_keycode/process_joystick.c +++ b/quantum/process_keycode/process_joystick.c @@ -6,41 +6,25 @@ #include #include -bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record); - bool process_joystick(uint16_t keycode, keyrecord_t *record) { - if (process_joystick_buttons(keycode, record) && (joystick_status.status & JS_UPDATED) > 0) { - send_joystick_packet(&joystick_status); - joystick_status.status &= ~JS_UPDATED; + switch (keycode) { + case JS_BUTTON0 ... JS_BUTTON_MAX: + if (record->event.pressed) { + register_joystick_button(keycode - JS_BUTTON0); + } else { + unregister_joystick_button(keycode - JS_BUTTON0); + } + return false; } - return true; } __attribute__((weak)) void joystick_task(void) { - if (process_joystick_analogread() && (joystick_status.status & JS_UPDATED)) { - send_joystick_packet(&joystick_status); - joystick_status.status &= ~JS_UPDATED; + if (process_joystick_analogread()) { + joystick_flush(); } } -bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record) { - if (keycode < JS_BUTTON0 || keycode > JS_BUTTON_MAX) { - return true; - } else { - uint8_t button_idx = (keycode - JS_BUTTON0); - if (record->event.pressed) { - joystick_status.buttons[button_idx / 8] |= 1 << (button_idx % 8); - } else { - joystick_status.buttons[button_idx / 8] &= ~(1 << (button_idx % 8)); - } - - joystick_status.status |= JS_UPDATED; - } - - return true; -} - uint16_t savePinState(pin_t pin) { #ifdef __AVR__ uint8_t pinNumber = pin & 0xF; -- cgit v1.2.3