Joystick feature updates (#16732)
* Joystick feature updates * Move new functions to joystick.h * Docszvecr-patch-1
parent
71ffb41c9b
commit
c05e8afe45
@ -1,13 +1,38 @@ |
|||||||
#include "joystick.h" |
#include "joystick.h" |
||||||
|
|
||||||
joystick_t joystick_status = {.buttons = {0}, |
// clang-format off
|
||||||
.axes = |
joystick_t joystick_status = { |
||||||
{ |
.buttons = {0}, |
||||||
|
.axes = { |
||||||
#if JOYSTICK_AXES_COUNT > 0 |
#if JOYSTICK_AXES_COUNT > 0 |
||||||
0 |
0 |
||||||
#endif |
#endif |
||||||
}, |
}, |
||||||
.status = 0}; |
.status = 0 |
||||||
|
}; |
||||||
|
// clang-format on
|
||||||
|
|
||||||
// array defining the reading of analog values for each axis
|
// array defining the reading of analog values for each axis
|
||||||
__attribute__((weak)) joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {}; |
__attribute__((weak)) joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {}; |
||||||
|
|
||||||
|
// to be implemented in the hid protocol library
|
||||||
|
void send_joystick_packet(joystick_t *joystick); |
||||||
|
|
||||||
|
void joystick_flush(void) { |
||||||
|
if ((joystick_status.status & JS_UPDATED) > 0) { |
||||||
|
send_joystick_packet(&joystick_status); |
||||||
|
joystick_status.status &= ~JS_UPDATED; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void register_joystick_button(uint8_t button) { |
||||||
|
joystick_status.buttons[button / 8] |= 1 << (button % 8); |
||||||
|
joystick_status.status |= JS_UPDATED; |
||||||
|
joystick_flush(); |
||||||
|
} |
||||||
|
|
||||||
|
void unregister_joystick_button(uint8_t button) { |
||||||
|
joystick_status.buttons[button / 8] &= ~(1 << (button % 8)); |
||||||
|
joystick_status.status |= JS_UPDATED; |
||||||
|
joystick_flush(); |
||||||
|
} |
||||||
|
Loading…
Reference in new issue