diff --git a/src/Akela/TapDance.cpp b/src/Akela/TapDance.cpp index b57772fa..45a2d79f 100644 --- a/src/Akela/TapDance.cpp +++ b/src/Akela/TapDance.cpp @@ -22,8 +22,8 @@ using namespace Akela::Ranges; namespace Akela { // --- state --- - uint16_t TapDance::timer; - uint8_t TapDance::timeOut = 5; + uint32_t TapDance::startTime; + uint16_t TapDance::timeOut = 200; uint8_t TapDance::tapCount[32]; uint32_t TapDance::pressedState; uint32_t TapDance::triggeredState; @@ -47,7 +47,7 @@ namespace Akela { tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Interrupt); bitWrite (triggeredState, idx, 1); - timer = 0; + startTime = millis (); if (bitRead (pressedState, idx)) return; @@ -59,6 +59,8 @@ namespace Akela { TapDance::timeout (void) { uint8_t idx = lastTapDanceKey.raw - TD_FIRST; + startTime = 0; + tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Timeout); bitWrite (triggeredState, idx, 1); @@ -74,7 +76,7 @@ namespace Akela { TapDance::release (uint8_t tapDanceIndex) { tapDanceAction (tapDanceIndex, lastTapDanceRow, lastTapDanceCol, tapCount[tapDanceIndex], Release); - timer = 0; + startTime = 0; tapCount[tapDanceIndex] = 0; lastTapDanceKey.raw = Key_NoKey.raw; @@ -88,7 +90,7 @@ namespace Akela { uint8_t idx = lastTapDanceKey.raw - TD_FIRST; tapCount[idx]++; - timer = 0; + startTime = millis (); tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Tap); @@ -211,10 +213,7 @@ namespace Akela { if (!isActive ()) return; - if (timer < timeOut) - timer++; - - if (timer >= timeOut) + if (startTime && (millis () - startTime) >= timeOut) timeout(); } }; diff --git a/src/Akela/TapDance.h b/src/Akela/TapDance.h index 24b5cde8..07dfb1ca 100644 --- a/src/Akela/TapDance.h +++ b/src/Akela/TapDance.h @@ -42,12 +42,12 @@ namespace Akela { TapDance (void); virtual void begin (void) final; - static uint8_t timeOut; + static uint16_t timeOut; void actionKeys (uint8_t tapCount, ActionType tapDanceAction, uint8_t maxKeys, const Key tapKeys[]); private: - static uint16_t timer; + static uint32_t startTime; static uint8_t tapCount[32]; static uint32_t pressedState; static uint32_t triggeredState;