From 2c9a6c0bd2c0f039a7a7a59399e6b2260c75e3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Sun, 11 Feb 2018 04:09:15 +0100 Subject: [PATCH] Add doubleTapSwitchLayerReleaseTimeout and set it to 100ms. Resolves #79. --- right/src/usb_report_updater.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index 5e5e7a8..b466067 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -21,6 +21,7 @@ uint32_t UsbReportUpdateTime = 0; static uint32_t elapsedTime; uint16_t DoubleTapSwitchLayerTimeout = 250; +uint16_t DoubleTapSwitchLayerReleaseTimeout = 100; static bool activeMouseStates[ACTIVE_MOUSE_STATES_COUNT]; @@ -196,6 +197,7 @@ void applyKeyAction(key_state_t *keyState, key_action_t *action) { static key_state_t *doubleTapSwitchLayerKey; static uint32_t doubleTapSwitchLayerStartTime; + static uint32_t doubleTapSwitchLayerTriggerTime; if (keyState->suppressed) { return; @@ -234,9 +236,16 @@ void applyKeyAction(key_state_t *keyState, key_action_t *action) activeMouseStates[action->mouseAction] = true; break; case KeyActionType_SwitchLayer: + if (keyState->previous && doubleTapSwitchLayerKey == keyState && + Timer_GetElapsedTime(&doubleTapSwitchLayerTriggerTime) > DoubleTapSwitchLayerReleaseTimeout) + { + ToggledLayer = LayerId_Base; + } + if (!keyState->previous && previousLayer == LayerId_Base && action->switchLayer.mode == SwitchLayerMode_HoldAndDoubleTapToggle) { if (doubleTapSwitchLayerKey && Timer_GetElapsedTimeAndSetCurrent(&doubleTapSwitchLayerStartTime) < DoubleTapSwitchLayerTimeout) { ToggledLayer = action->switchLayer.layer; + doubleTapSwitchLayerTriggerTime = CurrentTime; } else { doubleTapSwitchLayerKey = keyState; }