diff options
| author | Ryan <fauxpark@gmail.com> | 2022-03-27 05:38:09 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-26 18:38:09 +0000 |
| commit | c05e8afe454bf3706d69314c251dc5266c557007 (patch) | |
| tree | 604b8b446d111f9d5307888e9ea61acf8fada14d /quantum/process_keycode/process_joystick.c | |
| parent | 71ffb41c9b7c87cbeb2b19bac058717436bcda23 (diff) | |
Joystick feature updates (#16732)
* Joystick feature updates
* Move new functions to joystick.h
* Docs
Diffstat (limited to 'quantum/process_keycode/process_joystick.c')
| -rw-r--r-- | quantum/process_keycode/process_joystick.c | 36 |
1 files changed, 10 insertions, 26 deletions
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 @@ | |||
| 6 | #include <string.h> | 6 | #include <string.h> |
| 7 | #include <math.h> | 7 | #include <math.h> |
| 8 | 8 | ||
| 9 | bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record); | ||
| 10 | |||
| 11 | bool process_joystick(uint16_t keycode, keyrecord_t *record) { | 9 | bool process_joystick(uint16_t keycode, keyrecord_t *record) { |
| 12 | if (process_joystick_buttons(keycode, record) && (joystick_status.status & JS_UPDATED) > 0) { | 10 | switch (keycode) { |
| 13 | send_joystick_packet(&joystick_status); | 11 | case JS_BUTTON0 ... JS_BUTTON_MAX: |
| 14 | joystick_status.status &= ~JS_UPDATED; | 12 | if (record->event.pressed) { |
| 13 | register_joystick_button(keycode - JS_BUTTON0); | ||
| 14 | } else { | ||
| 15 | unregister_joystick_button(keycode - JS_BUTTON0); | ||
| 16 | } | ||
| 17 | return false; | ||
| 15 | } | 18 | } |
| 16 | |||
| 17 | return true; | 19 | return true; |
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | __attribute__((weak)) void joystick_task(void) { | 22 | __attribute__((weak)) void joystick_task(void) { |
| 21 | if (process_joystick_analogread() && (joystick_status.status & JS_UPDATED)) { | 23 | if (process_joystick_analogread()) { |
| 22 | send_joystick_packet(&joystick_status); | 24 | joystick_flush(); |
| 23 | joystick_status.status &= ~JS_UPDATED; | ||
| 24 | } | 25 | } |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | bool process_joystick_buttons(uint16_t keycode, keyrecord_t *record) { | ||
| 28 | if (keycode < JS_BUTTON0 || keycode > JS_BUTTON_MAX) { | ||
| 29 | return true; | ||
| 30 | } else { | ||
| 31 | uint8_t button_idx = (keycode - JS_BUTTON0); | ||
| 32 | if (record->event.pressed) { | ||
| 33 | joystick_status.buttons[button_idx / 8] |= 1 << (button_idx % 8); | ||
| 34 | } else { | ||
| 35 | joystick_status.buttons[button_idx / 8] &= ~(1 << (button_idx % 8)); | ||
| 36 | } | ||
| 37 | |||
| 38 | joystick_status.status |= JS_UPDATED; | ||
| 39 | } | ||
| 40 | |||
| 41 | return true; | ||
| 42 | } | ||
| 43 | |||
| 44 | uint16_t savePinState(pin_t pin) { | 28 | uint16_t savePinState(pin_t pin) { |
| 45 | #ifdef __AVR__ | 29 | #ifdef __AVR__ |
| 46 | uint8_t pinNumber = pin & 0xF; | 30 | uint8_t pinNumber = pin & 0xF; |
