From de1688389d28ff41b7bf70b1bfefe456744a6a4a Mon Sep 17 00:00:00 2001 From: dnaq Date: Fri, 24 Sep 2021 23:30:30 +0200 Subject: [PATCH] try not sending chord state when no updates have happened --- quantum/process_keycode/process_plover_hid.c | 2 +- tmk_core/protocol/lufa/lufa.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/quantum/process_keycode/process_plover_hid.c b/quantum/process_keycode/process_plover_hid.c index 2cd5c9d0a7..7d7f97cfc2 100644 --- a/quantum/process_keycode/process_plover_hid.c +++ b/quantum/process_keycode/process_plover_hid.c @@ -6,6 +6,6 @@ bool process_plover_hid(uint16_t keycode, keyrecord_t *record) { if (keycode < PLV__MIN || keycode > PLV__MAX) { return true; } - plover_hid_update((uint8_t)(keycode - PLV__MIN), record->event.pressed); + plover_hid_update(keycode - PLV__MIN, record->event.pressed); return false; } diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 02c6cd15e2..c15aa68dbf 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -214,19 +214,24 @@ static void raw_hid_task(void) { #endif #ifdef PLOVER_HID_ENABLE -static uint8_t plover_hid_current_report[PLOVER_HID_SIMPLE_REPORT_SIZE] = {1}; +static bool plover_hid_report_updated = false; +static uint8_t plover_hid_current_report[PLOVER_HID_SIMPLE_REPORT_SIZE] = {1, 0}; void plover_hid_update(uint8_t button, bool pressed) { if (pressed) { plover_hid_current_report[1 + button/8] |= (1 << (7 - (button % 8))); } else { - plover_hid_current_report[1 + button/8] &= (1 << (7 - (button % 8))); + plover_hid_current_report[1 + button/8] &= ~(1 << (7 - (button % 8))); } + plover_hid_report_updated = true; } void plover_hid_task(void) { if (USB_DeviceState != DEVICE_STATE_Configured) { return; } + if (!plover_hid_report_updated) { + return; + } uint8_t ep = Endpoint_GetCurrentEndpoint(); @@ -235,12 +240,14 @@ void plover_hid_task(void) { // Check to see if the host is ready to accept another packet if (Endpoint_IsINReady()) { // Write data - Endpoint_Write_Stream_LE(plover_hid_current_report, sizeof(plover_hid_current_report), NULL); + Endpoint_Write_Stream_LE(plover_hid_current_report, PLOVER_HID_SIMPLE_REPORT_SIZE, NULL); // Finalize The stream transfer to send the last packet Endpoint_ClearIN(); } Endpoint_SelectEndpoint(ep); + + plover_hid_report_updated = false; } #endif