try not sending chord state when no updates have happened

This commit is contained in:
dnaq 2021-09-24 23:30:30 +02:00
parent ae191ab099
commit de1688389d
2 changed files with 11 additions and 4 deletions

View file

@ -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;
}

View file

@ -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