diff --git a/right/src/timer.c b/right/src/timer.c index 3efff86..c997310 100644 --- a/right/src/timer.c +++ b/right/src/timer.c @@ -24,9 +24,20 @@ void Timer_Init(void) PIT_StartTimer(PIT, PIT_TIMER_CHANNEL); } +void Timer_SetCurrentTime(uint32_t *time) +{ + *time = CurrentTime; +} + uint32_t Timer_GetElapsedTime(uint32_t *time) { uint32_t elapsedTime = CurrentTime - *time; + return elapsedTime; +} + +uint32_t Timer_GetElapsedTimeAndSetCurrent(uint32_t *time) +{ + uint32_t elapsedTime = Timer_GetElapsedTime(time); *time = CurrentTime; return elapsedTime; } diff --git a/right/src/timer.h b/right/src/timer.h index f44e242..012bb49 100644 --- a/right/src/timer.h +++ b/right/src/timer.h @@ -16,6 +16,8 @@ // Functions: void Timer_Init(void); + void Timer_SetCurrentTime(uint32_t *time); uint32_t Timer_GetElapsedTime(uint32_t *time); + uint32_t Timer_GetElapsedTimeAndSetCurrent(uint32_t *time); #endif diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index b42b14f..843f643 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -207,7 +207,7 @@ void applyKeyAction(key_state_t *keyState, key_action_t *action) case KeyActionType_SwitchLayer: if (!keyState->previous && previousLayer == LayerId_Base && action->switchLayer.mode == SwitchLayerMode_HoldAndDoubleTapToggle) { if (doubleTapSwitchLayerKey) { - if (Timer_GetElapsedTime(&doubleTapSwitchLayerStartTime) < DoubleTapSwitchLayerTimeout) { + if (Timer_GetElapsedTimeAndSetCurrent(&doubleTapSwitchLayerStartTime) < DoubleTapSwitchLayerTimeout) { ToggledLayer = action->switchLayer.layer; } doubleTapSwitchLayerKey = NULL; @@ -237,7 +237,7 @@ void updateActiveUsbReports(void) memset(activeMouseStates, 0, ACTIVE_MOUSE_STATES_COUNT); static uint8_t previousModifiers = 0; - elapsedTime = Timer_GetElapsedTime(&UsbReportUpdateTime); + elapsedTime = Timer_GetElapsedTimeAndSetCurrent(&UsbReportUpdateTime); basicScancodeIndex = 0; mediaScancodeIndex = 0; @@ -346,11 +346,19 @@ bool UsbSystemKeyboardReportEverSent = false; bool UsbMouseReportEverSentEverSent = false; uint32_t UsbReportUpdateCounter; +static uint32_t lastUsbUpdateTime; void UpdateUsbReports(void) { UsbReportUpdateCounter++; + if (Timer_GetElapsedTime(&lastUsbUpdateTime) > 100) { + UsbBasicKeyboardReportEverSent = false; + UsbMediaKeyboardReportEverSent = false; + UsbSystemKeyboardReportEverSent = false; + UsbMouseReportEverSentEverSent = false; + } + if (IsUsbBasicKeyboardReportSent) { UsbBasicKeyboardReportEverSent = true; } @@ -397,4 +405,6 @@ void UpdateUsbReports(void) IsUsbMediaKeyboardReportSent = false; IsUsbSystemKeyboardReportSent = false; IsUsbMouseReportSent = false; + + Timer_SetCurrentTime(&lastUsbUpdateTime); }