From d3d51fd26644918ef3e524284c99b5e3632720f8 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 21 Jan 2017 20:08:08 +0100 Subject: [PATCH] Record and use the position of the tap-dance key, too To be able to change the LEDs under a tap-dance key - for example - we need to know its position. For this reason, remember the position, and use it when injecting events, and pass them to `tapDanceAction`, too. Fixes #3. Signed-off-by: Gergely Nagy --- README.md | 5 +++-- src/Akela/TapDance.cpp | 24 +++++++++++++++--------- src/Akela/TapDance.h | 4 +++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7440480e..492065cf 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ particularly useful: > The `tapCount` and `tapDanceActions` parameters should be the same as the > similarly named parameters of the `tapDanceAction` function. -### `tapDanceAction(tapDanceIndex, tapCount, tapDanceAction)` +### `tapDanceAction(tapDanceIndex, row, col, tapCount, tapDanceAction)` > The heart of the tap-dance plugin is the handler method. This is called every > time any kind of tap-dance action is to be performed. See the @@ -126,7 +126,8 @@ particularly useful: > how this function is called. > > The `tapDanceIndex` and `tapCount` parameters help us choose which action to -> perform. +> perform. The `row` and `col` parameters tell us where the tap-dance key is on +> the keyboard. ## Further reading diff --git a/src/Akela/TapDance.cpp b/src/Akela/TapDance.cpp index 572ea3fb..d11da79f 100644 --- a/src/Akela/TapDance.cpp +++ b/src/Akela/TapDance.cpp @@ -28,6 +28,8 @@ namespace Akela { uint32_t TapDance::pressedState; uint32_t TapDance::triggeredState; Key TapDance::lastTapDanceKey; + byte TapDance::lastTapDanceRow; + byte TapDance::lastTapDanceCol; // --- helpers --- @@ -42,7 +44,7 @@ namespace Akela { TapDance::interrupt (void) { uint8_t idx = lastTapDanceKey.raw - TD_FIRST; - tapDanceAction (idx, tapCount[idx], Interrupt); + tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Interrupt); bitWrite (triggeredState, idx, 1); timer = 0; @@ -57,7 +59,7 @@ namespace Akela { TapDance::timeout (void) { uint8_t idx = lastTapDanceKey.raw - TD_FIRST; - tapDanceAction (idx, tapCount[idx], Timeout); + tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Timeout); bitWrite (triggeredState, idx, 1); if (bitRead (pressedState, idx)) @@ -70,7 +72,7 @@ namespace Akela { Key TapDance::release (uint8_t tapDanceIndex) { - tapDanceAction (tapDanceIndex, tapCount[tapDanceIndex], Release); + tapDanceAction (tapDanceIndex, lastTapDanceRow, lastTapDanceCol, tapCount[tapDanceIndex], Release); timer = 0; tapCount[tapDanceIndex] = 0; @@ -88,7 +90,7 @@ namespace Akela { tapCount[idx]++; timer = 0; - tapDanceAction (idx, tapCount[idx], Tap); + tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Tap); return Key_NoKey; } @@ -118,14 +120,14 @@ namespace Akela { break; case Interrupt: case Timeout: - handle_key_event (key, 255, 255, IS_PRESSED | INJECTED); + handle_key_event (key, lastTapDanceRow, lastTapDanceCol, IS_PRESSED | INJECTED); break; case Hold: - handle_key_event (key, 255, 255, IS_PRESSED | WAS_PRESSED | INJECTED); + handle_key_event (key, lastTapDanceRow, lastTapDanceCol, IS_PRESSED | WAS_PRESSED | INJECTED); break; case Release: Keyboard.sendReport (); - handle_key_event (key, 255, 255, WAS_PRESSED | INJECTED); + handle_key_event (key, lastTapDanceRow, lastTapDanceCol, WAS_PRESSED | INJECTED); break; } } @@ -167,6 +169,8 @@ namespace Akela { } lastTapDanceKey.raw = mappedKey.raw; + lastTapDanceRow = row; + lastTapDanceCol = col; return tap (); } else { if (key_toggled_off (keyState) && stillHeld (tapDanceIndex)) { @@ -186,13 +190,15 @@ namespace Akela { return Key_NoKey; lastTapDanceKey.raw = mappedKey.raw; + lastTapDanceRow = row; + lastTapDanceCol = col; bitSet (pressedState, tapDanceIndex); if (key_toggled_on (keyState)) return tap (); if (bitRead (triggeredState, tapDanceIndex)) - tapDanceAction (tapDanceIndex, tapCount[tapDanceIndex], Hold); + tapDanceAction (tapDanceIndex, row, col, tapCount[tapDanceIndex], Hold); return Key_NoKey; } @@ -215,7 +221,7 @@ namespace Akela { __attribute__((weak)) void -tapDanceAction (uint8_t tapDanceIndex, uint8_t tapCount, Akela::TapDance::ActionType tapDanceAction) { +tapDanceAction (uint8_t tapDanceIndex, byte row, byte col, uint8_t tapCount, Akela::TapDance::ActionType tapDanceAction) { } Akela::TapDance TapDance; diff --git a/src/Akela/TapDance.h b/src/Akela/TapDance.h index 97d918d3..fa3199d7 100644 --- a/src/Akela/TapDance.h +++ b/src/Akela/TapDance.h @@ -52,6 +52,8 @@ namespace Akela { static uint32_t pressedState; static uint32_t triggeredState; static Key lastTapDanceKey; + static byte lastTapDanceRow; + static byte lastTapDanceCol; static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); static void loopHook (bool postClear); @@ -63,6 +65,6 @@ namespace Akela { }; }; -void tapDanceAction (uint8_t tapDanceIndex, uint8_t tapCount, Akela::TapDance::ActionType tapDanceAction); +void tapDanceAction (uint8_t tapDanceIndex, byte row, byte col, uint8_t tapCount, Akela::TapDance::ActionType tapDanceAction); extern Akela::TapDance TapDance;