From f184177ec3e331e19f0c6bc6626a2365c44c1064 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 18 Mar 2017 00:23:56 +0100 Subject: [PATCH] Instead of releasing immediately, delay it until loop() When releasing immediately, other keys that may affect us (such as Shift) may not be handled yet. So lets wait with the release until the next loop. Addresses #6, at least partially. Signed-off-by: Gergely Nagy --- src/Kaleidoscope/TapDance.cpp | 14 +++++++++++--- src/Kaleidoscope/TapDance.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Kaleidoscope/TapDance.cpp b/src/Kaleidoscope/TapDance.cpp index b9793bb3..157a5116 100644 --- a/src/Kaleidoscope/TapDance.cpp +++ b/src/Kaleidoscope/TapDance.cpp @@ -27,6 +27,7 @@ namespace KaleidoscopePlugins { uint8_t TapDance::tapCount[16]; uint16_t TapDance::pressedState; uint16_t TapDance::triggeredState; + uint16_t TapDance::releaseNextState; Key TapDance::lastTapDanceKey; byte TapDance::lastTapDanceRow; byte TapDance::lastTapDanceCol; @@ -72,14 +73,12 @@ namespace KaleidoscopePlugins { Key TapDance::release (uint8_t tapDanceIndex) { - tapDanceAction (tapDanceIndex, lastTapDanceRow, lastTapDanceCol, tapCount[tapDanceIndex], Release); - endTime = 0; - tapCount[tapDanceIndex] = 0; lastTapDanceKey.raw = Key_NoKey.raw; bitClear (pressedState, tapDanceIndex); bitClear (triggeredState, tapDanceIndex); + bitWrite (releaseNextState, tapDanceIndex, 1); return Key_NoKey; } @@ -208,6 +207,15 @@ namespace KaleidoscopePlugins { if (!postClear) return; + for (uint8_t i = 0; i < 16; i++) { + if (!bitRead (releaseNextState, i)) + continue; + + tapDanceAction (i, lastTapDanceRow, lastTapDanceCol, tapCount[i], Release); + tapCount[i] = 0; + bitClear (releaseNextState, i); + } + if (!isActive ()) return; diff --git a/src/Kaleidoscope/TapDance.h b/src/Kaleidoscope/TapDance.h index d545065d..e7545c4b 100644 --- a/src/Kaleidoscope/TapDance.h +++ b/src/Kaleidoscope/TapDance.h @@ -52,6 +52,7 @@ namespace KaleidoscopePlugins { static uint8_t tapCount[16]; static uint16_t pressedState; static uint16_t triggeredState; + static uint16_t releaseNextState; static Key lastTapDanceKey; static byte lastTapDanceRow; static byte lastTapDanceCol;