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 <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent e44aa0daee
commit d3d51fd266

@ -118,7 +118,7 @@ particularly useful:
> The `tapCount` and `tapDanceActions` parameters should be the same as the > The `tapCount` and `tapDanceActions` parameters should be the same as the
> similarly named parameters of the `tapDanceAction` function. > 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 > 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 > time any kind of tap-dance action is to be performed. See the
@ -126,7 +126,8 @@ particularly useful:
> how this function is called. > how this function is called.
> >
> The `tapDanceIndex` and `tapCount` parameters help us choose which action to > 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 ## Further reading

@ -28,6 +28,8 @@ namespace Akela {
uint32_t TapDance::pressedState; uint32_t TapDance::pressedState;
uint32_t TapDance::triggeredState; uint32_t TapDance::triggeredState;
Key TapDance::lastTapDanceKey; Key TapDance::lastTapDanceKey;
byte TapDance::lastTapDanceRow;
byte TapDance::lastTapDanceCol;
// --- helpers --- // --- helpers ---
@ -42,7 +44,7 @@ namespace Akela {
TapDance::interrupt (void) { TapDance::interrupt (void) {
uint8_t idx = lastTapDanceKey.raw - TD_FIRST; uint8_t idx = lastTapDanceKey.raw - TD_FIRST;
tapDanceAction (idx, tapCount[idx], Interrupt); tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Interrupt);
bitWrite (triggeredState, idx, 1); bitWrite (triggeredState, idx, 1);
timer = 0; timer = 0;
@ -57,7 +59,7 @@ namespace Akela {
TapDance::timeout (void) { TapDance::timeout (void) {
uint8_t idx = lastTapDanceKey.raw - TD_FIRST; uint8_t idx = lastTapDanceKey.raw - TD_FIRST;
tapDanceAction (idx, tapCount[idx], Timeout); tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Timeout);
bitWrite (triggeredState, idx, 1); bitWrite (triggeredState, idx, 1);
if (bitRead (pressedState, idx)) if (bitRead (pressedState, idx))
@ -70,7 +72,7 @@ namespace Akela {
Key Key
TapDance::release (uint8_t tapDanceIndex) { TapDance::release (uint8_t tapDanceIndex) {
tapDanceAction (tapDanceIndex, tapCount[tapDanceIndex], Release); tapDanceAction (tapDanceIndex, lastTapDanceRow, lastTapDanceCol, tapCount[tapDanceIndex], Release);
timer = 0; timer = 0;
tapCount[tapDanceIndex] = 0; tapCount[tapDanceIndex] = 0;
@ -88,7 +90,7 @@ namespace Akela {
tapCount[idx]++; tapCount[idx]++;
timer = 0; timer = 0;
tapDanceAction (idx, tapCount[idx], Tap); tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Tap);
return Key_NoKey; return Key_NoKey;
} }
@ -118,14 +120,14 @@ namespace Akela {
break; break;
case Interrupt: case Interrupt:
case Timeout: case Timeout:
handle_key_event (key, 255, 255, IS_PRESSED | INJECTED); handle_key_event (key, lastTapDanceRow, lastTapDanceCol, IS_PRESSED | INJECTED);
break; break;
case Hold: 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; break;
case Release: case Release:
Keyboard.sendReport (); Keyboard.sendReport ();
handle_key_event (key, 255, 255, WAS_PRESSED | INJECTED); handle_key_event (key, lastTapDanceRow, lastTapDanceCol, WAS_PRESSED | INJECTED);
break; break;
} }
} }
@ -167,6 +169,8 @@ namespace Akela {
} }
lastTapDanceKey.raw = mappedKey.raw; lastTapDanceKey.raw = mappedKey.raw;
lastTapDanceRow = row;
lastTapDanceCol = col;
return tap (); return tap ();
} else { } else {
if (key_toggled_off (keyState) && stillHeld (tapDanceIndex)) { if (key_toggled_off (keyState) && stillHeld (tapDanceIndex)) {
@ -186,13 +190,15 @@ namespace Akela {
return Key_NoKey; return Key_NoKey;
lastTapDanceKey.raw = mappedKey.raw; lastTapDanceKey.raw = mappedKey.raw;
lastTapDanceRow = row;
lastTapDanceCol = col;
bitSet (pressedState, tapDanceIndex); bitSet (pressedState, tapDanceIndex);
if (key_toggled_on (keyState)) if (key_toggled_on (keyState))
return tap (); return tap ();
if (bitRead (triggeredState, tapDanceIndex)) if (bitRead (triggeredState, tapDanceIndex))
tapDanceAction (tapDanceIndex, tapCount[tapDanceIndex], Hold); tapDanceAction (tapDanceIndex, row, col, tapCount[tapDanceIndex], Hold);
return Key_NoKey; return Key_NoKey;
} }
@ -215,7 +221,7 @@ namespace Akela {
__attribute__((weak)) __attribute__((weak))
void 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; Akela::TapDance TapDance;

@ -52,6 +52,8 @@ namespace Akela {
static uint32_t pressedState; static uint32_t pressedState;
static uint32_t triggeredState; static uint32_t triggeredState;
static Key lastTapDanceKey; static Key lastTapDanceKey;
static byte lastTapDanceRow;
static byte lastTapDanceCol;
static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState);
static void loopHook (bool postClear); 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; extern Akela::TapDance TapDance;

Loading…
Cancel
Save