mirror of https://github.com/nirenjan/libx52.git
feat: Add disconnected flag to event handler
This change allows a raw event to be sent to all the event handler callbacks so that when a device is disconnected, the callback routines can reset their internal states.master
parent
008e72ea74
commit
4528495f61
|
|
@ -38,7 +38,7 @@ int x52d_register_event_handler(uint64_t mask, x52_event_handler_fn fn)
|
|||
return -1;
|
||||
}
|
||||
|
||||
atomic_store(&handlers[ticket].mask, mask);
|
||||
atomic_store(&handlers[ticket].mask, mask | LIBX52IO_REPORT_DEVICE_DISCONNECTED);
|
||||
atomic_store(&handlers[ticket].fn, fn);
|
||||
|
||||
return ticket;
|
||||
|
|
@ -61,15 +61,18 @@ int x52d_update_event_handler_mask(int handler, uint64_t new_mask)
|
|||
}
|
||||
|
||||
void x52d_dispatch_event(libx52io_report *prev, libx52io_report *curr)
|
||||
{
|
||||
uint64_t changed = libx52io_compare_reports(prev, curr);
|
||||
x52d_dispatch_event_raw(changed, prev, curr);
|
||||
}
|
||||
|
||||
void x52d_dispatch_event_raw(uint64_t changed, libx52io_report *prev, libx52io_report *curr)
|
||||
{
|
||||
int current_limit = atomic_load(&num_handlers);
|
||||
if (current_limit >= MAX_EVENT_HANDLERS) {
|
||||
current_limit = MAX_EVENT_HANDLERS;
|
||||
}
|
||||
|
||||
uint64_t changed = libx52io_compare_reports(prev, curr);
|
||||
|
||||
|
||||
for (int i = 0; i < current_limit; i++) {
|
||||
x52_event_handler_fn callback = atomic_load(&handlers[i].fn);
|
||||
if (callback == NULL) {
|
||||
|
|
|
|||
|
|
@ -19,5 +19,6 @@ typedef void (*x52_event_handler_fn)(uint64_t changed,
|
|||
int x52d_register_event_handler(uint64_t mask, x52_event_handler_fn fn);
|
||||
int x52d_update_event_handler_mask(int handler, uint64_t new_mask);
|
||||
void x52d_dispatch_event(libx52io_report *prev, libx52io_report *curr);
|
||||
void x52d_dispatch_event_raw(uint64_t changed, libx52io_report *prev, libx52io_report *curr);
|
||||
|
||||
#endif // !defined X52D_EVENT_HANDLER_H
|
||||
|
|
|
|||
|
|
@ -336,6 +336,10 @@ typedef struct libx52io_report libx52io_report;
|
|||
#define LIBX52IO_REPORT_BTN_MODE_3 (1ULL << (LIBX52IO_AXIS_MAX + LIBX52IO_BTN_MODE_3))
|
||||
#define LIBX52IO_REPORT_MODE (1ULL << (LIBX52IO_AXIS_MAX + LIBX52IO_BUTTON_MAX))
|
||||
#define LIBX52IO_REPORT_HAT (1ULL << (LIBX52IO_AXIS_MAX + LIBX52IO_BUTTON_MAX + 1))
|
||||
|
||||
/* High bits are used to flag events */
|
||||
#define LIBX52IO_REPORT_DEVICE_DISCONNECTED (1ULL << 63)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue