|
|
@ -18,76 +18,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <Kaleidoscope-TapDance.h>
|
|
|
|
#include <Kaleidoscope-TapDance.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
namespace kaleidoscope {
|
|
|
|
|
|
|
|
|
|
|
|
// --- state ---
|
|
|
|
// --- state ---
|
|
|
|
uint32_t TapDance::endTime;
|
|
|
|
uint32_t TapDance::end_time_;
|
|
|
|
uint16_t TapDance::timeOut = 200;
|
|
|
|
uint16_t TapDance::time_out = 200;
|
|
|
|
uint8_t TapDance::tapCount[16];
|
|
|
|
uint8_t TapDance::tap_count_[16];
|
|
|
|
uint16_t TapDance::pressedState;
|
|
|
|
uint16_t TapDance::pressed_state_;
|
|
|
|
uint16_t TapDance::triggeredState;
|
|
|
|
uint16_t TapDance::triggered_state_;
|
|
|
|
uint16_t TapDance::releaseNextState;
|
|
|
|
uint16_t TapDance::release_next_state_;
|
|
|
|
Key TapDance::lastTapDanceKey;
|
|
|
|
Key TapDance::last_tap_dance_key_;
|
|
|
|
byte TapDance::lastTapDanceRow;
|
|
|
|
byte TapDance::last_tap_dance_row_;
|
|
|
|
byte TapDance::lastTapDanceCol;
|
|
|
|
byte TapDance::last_tap_dance_col_;
|
|
|
|
|
|
|
|
|
|
|
|
// --- helpers ---
|
|
|
|
// --- helpers ---
|
|
|
|
|
|
|
|
|
|
|
|
#define isTapDance(k) (k.raw >= Ranges::TD_FIRST && k.raw <= Ranges::TD_LAST)
|
|
|
|
#define isTapDance(k) (k.raw >= ranges::TD_FIRST && k.raw <= ranges::TD_LAST)
|
|
|
|
#define isInSeq(k) (lastTapDanceKey.raw == k.raw)
|
|
|
|
#define isInSeq(k) (last_tap_dance_key_.raw == k.raw)
|
|
|
|
#define stillHeld(idx) (tapCount[idx])
|
|
|
|
#define stillHeld(idx) (tap_count_[idx])
|
|
|
|
#define isActive() (lastTapDanceKey.raw != Key_NoKey.raw)
|
|
|
|
#define isActive() (last_tap_dance_key_.raw != Key_NoKey.raw)
|
|
|
|
|
|
|
|
|
|
|
|
// --- actions ---
|
|
|
|
// --- actions ---
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void TapDance::interrupt(void) {
|
|
|
|
TapDance::interrupt(void) {
|
|
|
|
uint8_t idx = last_tap_dance_key_.raw - ranges::TD_FIRST;
|
|
|
|
uint8_t idx = lastTapDanceKey.raw - Ranges::TD_FIRST;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tapDanceAction(idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Interrupt);
|
|
|
|
tapDanceAction(idx, last_tap_dance_row_, last_tap_dance_col_, tap_count_[idx], Interrupt);
|
|
|
|
bitWrite(triggeredState, idx, 1);
|
|
|
|
bitWrite(triggered_state_, idx, 1);
|
|
|
|
|
|
|
|
|
|
|
|
endTime = 0;
|
|
|
|
end_time_ = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (bitRead(pressedState, idx))
|
|
|
|
if (bitRead(pressed_state_, idx))
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
release(idx);
|
|
|
|
release(idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void TapDance::timeout(void) {
|
|
|
|
TapDance::timeout(void) {
|
|
|
|
uint8_t idx = last_tap_dance_key_.raw - ranges::TD_FIRST;
|
|
|
|
uint8_t idx = lastTapDanceKey.raw - Ranges::TD_FIRST;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tapDanceAction(idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Timeout);
|
|
|
|
tapDanceAction(idx, last_tap_dance_row_, last_tap_dance_col_, tap_count_[idx], Timeout);
|
|
|
|
bitWrite(triggeredState, idx, 1);
|
|
|
|
bitWrite(triggered_state_, idx, 1);
|
|
|
|
|
|
|
|
|
|
|
|
if (bitRead(pressedState, idx))
|
|
|
|
if (bitRead(pressed_state_, idx))
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
lastTapDanceKey.raw = Key_NoKey.raw;
|
|
|
|
last_tap_dance_key_.raw = Key_NoKey.raw;
|
|
|
|
|
|
|
|
|
|
|
|
release(idx);
|
|
|
|
release(idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
Key TapDance::release(uint8_t tap_dance_index) {
|
|
|
|
TapDance::release(uint8_t tapDanceIndex) {
|
|
|
|
end_time_ = 0;
|
|
|
|
endTime = 0;
|
|
|
|
last_tap_dance_key_.raw = Key_NoKey.raw;
|
|
|
|
lastTapDanceKey.raw = Key_NoKey.raw;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bitClear(pressedState, tapDanceIndex);
|
|
|
|
bitClear(pressed_state_, tap_dance_index);
|
|
|
|
bitClear(triggeredState, tapDanceIndex);
|
|
|
|
bitClear(triggered_state_, tap_dance_index);
|
|
|
|
bitWrite(releaseNextState, tapDanceIndex, 1);
|
|
|
|
bitWrite(release_next_state_, tap_dance_index, 1);
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
Key TapDance::tap(void) {
|
|
|
|
TapDance::tap(void) {
|
|
|
|
uint8_t idx = last_tap_dance_key_.raw - ranges::TD_FIRST;
|
|
|
|
uint8_t idx = lastTapDanceKey.raw - Ranges::TD_FIRST;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tapCount[idx]++;
|
|
|
|
tap_count_[idx]++;
|
|
|
|
endTime = millis() + timeOut;
|
|
|
|
end_time_ = millis() + time_out;
|
|
|
|
|
|
|
|
|
|
|
|
tapDanceAction(idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Tap);
|
|
|
|
tapDanceAction(idx, last_tap_dance_row_, last_tap_dance_col_, tap_count_[idx], Tap);
|
|
|
|
|
|
|
|
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -95,86 +92,82 @@ TapDance::tap(void) {
|
|
|
|
// --- api ---
|
|
|
|
// --- api ---
|
|
|
|
|
|
|
|
|
|
|
|
TapDance::TapDance(void) {
|
|
|
|
TapDance::TapDance(void) {
|
|
|
|
lastTapDanceKey.raw = Key_NoKey.raw;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void TapDance::begin(void) {
|
|
|
|
TapDance::begin(void) {
|
|
|
|
event_handler_hook_use(eventHandlerHook);
|
|
|
|
event_handler_hook_use(this->eventHandlerHook);
|
|
|
|
loop_hook_use(loopHook);
|
|
|
|
loop_hook_use(this->loopHook);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void TapDance::actionKeys(uint8_t tap_count, ActionType tap_dance_action, uint8_t max_keys, const Key tap_keys[]) {
|
|
|
|
TapDance::actionKeys(uint8_t tapCount, ActionType tapDanceAction, uint8_t maxKeys, const Key tapKeys[]) {
|
|
|
|
if (tap_count > max_keys)
|
|
|
|
if (tapCount > maxKeys)
|
|
|
|
tap_count = max_keys;
|
|
|
|
tapCount = maxKeys;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Key key;
|
|
|
|
Key key;
|
|
|
|
key.raw = pgm_read_word(&(tapKeys[tapCount - 1].raw));
|
|
|
|
key.raw = pgm_read_word(&(tap_keys[tap_count - 1].raw));
|
|
|
|
|
|
|
|
|
|
|
|
switch (tapDanceAction) {
|
|
|
|
switch (tap_dance_action) {
|
|
|
|
case Tap:
|
|
|
|
case Tap:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Interrupt:
|
|
|
|
case Interrupt:
|
|
|
|
case Timeout:
|
|
|
|
case Timeout:
|
|
|
|
handle_keyswitch_event(key, lastTapDanceRow, lastTapDanceCol, IS_PRESSED | INJECTED);
|
|
|
|
handle_keyswitch_event(key, last_tap_dance_row_, last_tap_dance_col_, IS_PRESSED | INJECTED);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Hold:
|
|
|
|
case Hold:
|
|
|
|
handle_keyswitch_event(key, lastTapDanceRow, lastTapDanceCol, IS_PRESSED | WAS_PRESSED | INJECTED);
|
|
|
|
handle_keyswitch_event(key, last_tap_dance_row_, last_tap_dance_col_, IS_PRESSED | WAS_PRESSED | INJECTED);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Release:
|
|
|
|
case Release:
|
|
|
|
Keyboard.sendReport();
|
|
|
|
Keyboard.sendReport();
|
|
|
|
handle_keyswitch_event(key, lastTapDanceRow, lastTapDanceCol, WAS_PRESSED | INJECTED);
|
|
|
|
handle_keyswitch_event(key, last_tap_dance_row_, last_tap_dance_col_, WAS_PRESSED | INJECTED);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --- hooks ---
|
|
|
|
// --- hooks ---
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
Key TapDance::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
|
|
|
|
TapDance::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
if (key_state & INJECTED)
|
|
|
|
if (keyState & INJECTED)
|
|
|
|
return mapped_key;
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!key_is_pressed(keyState) && !key_was_pressed(keyState)) {
|
|
|
|
if (!key_is_pressed(key_state) && !key_was_pressed(key_state)) {
|
|
|
|
if (isTapDance(mappedKey))
|
|
|
|
if (isTapDance(mapped_key))
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
return mappedKey;
|
|
|
|
return mapped_key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isTapDance(mappedKey)) {
|
|
|
|
if (!isTapDance(mapped_key)) {
|
|
|
|
if (!isActive())
|
|
|
|
if (!isActive())
|
|
|
|
return mappedKey;
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
|
|
|
|
if (key_toggled_on(keyState))
|
|
|
|
if (key_toggled_on(key_state))
|
|
|
|
interrupt();
|
|
|
|
interrupt();
|
|
|
|
|
|
|
|
|
|
|
|
return mappedKey;
|
|
|
|
return mapped_key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t tapDanceIndex = mappedKey.raw - Ranges::TD_FIRST;
|
|
|
|
uint8_t tap_dance_index = mapped_key.raw - ranges::TD_FIRST;
|
|
|
|
|
|
|
|
|
|
|
|
if (key_toggled_off(keyState))
|
|
|
|
if (key_toggled_off(key_state))
|
|
|
|
bitClear(pressedState, tapDanceIndex);
|
|
|
|
bitClear(pressed_state_, tap_dance_index);
|
|
|
|
|
|
|
|
|
|
|
|
if (!isInSeq(mappedKey)) {
|
|
|
|
if (!isInSeq(mapped_key)) {
|
|
|
|
if (!isActive()) {
|
|
|
|
if (!isActive()) {
|
|
|
|
if (bitRead(triggeredState, tapDanceIndex)) {
|
|
|
|
if (bitRead(triggered_state_, tap_dance_index)) {
|
|
|
|
if (key_toggled_off(keyState))
|
|
|
|
if (key_toggled_off(key_state))
|
|
|
|
return release(tapDanceIndex);
|
|
|
|
return release(tap_dance_index);
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lastTapDanceKey.raw = mappedKey.raw;
|
|
|
|
last_tap_dance_key_.raw = mapped_key.raw;
|
|
|
|
lastTapDanceRow = row;
|
|
|
|
last_tap_dance_row_ = row;
|
|
|
|
lastTapDanceCol = col;
|
|
|
|
last_tap_dance_col_ = col;
|
|
|
|
return tap();
|
|
|
|
return tap();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (key_toggled_off(keyState) && stillHeld(tapDanceIndex)) {
|
|
|
|
if (key_toggled_off(key_state) && stillHeld(tap_dance_index)) {
|
|
|
|
return release(tapDanceIndex);
|
|
|
|
return release(tap_dance_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!key_toggled_on(keyState))
|
|
|
|
if (!key_toggled_on(key_state))
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
|
|
|
|
|
|
|
|
interrupt();
|
|
|
|
interrupt();
|
|
|
@ -183,48 +176,48 @@ TapDance::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState)
|
|
|
|
|
|
|
|
|
|
|
|
// in sequence
|
|
|
|
// in sequence
|
|
|
|
|
|
|
|
|
|
|
|
if (key_toggled_off(keyState))
|
|
|
|
if (key_toggled_off(key_state))
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
|
|
|
|
|
|
|
|
lastTapDanceKey.raw = mappedKey.raw;
|
|
|
|
last_tap_dance_key_.raw = mapped_key.raw;
|
|
|
|
lastTapDanceRow = row;
|
|
|
|
last_tap_dance_row_ = row;
|
|
|
|
lastTapDanceCol = col;
|
|
|
|
last_tap_dance_col_ = col;
|
|
|
|
bitSet(pressedState, tapDanceIndex);
|
|
|
|
bitSet(pressed_state_, tap_dance_index);
|
|
|
|
|
|
|
|
|
|
|
|
if (key_toggled_on(keyState))
|
|
|
|
if (key_toggled_on(key_state))
|
|
|
|
return tap();
|
|
|
|
return tap();
|
|
|
|
|
|
|
|
|
|
|
|
if (bitRead(triggeredState, tapDanceIndex))
|
|
|
|
if (bitRead(triggered_state_, tap_dance_index))
|
|
|
|
tapDanceAction(tapDanceIndex, row, col, tapCount[tapDanceIndex], Hold);
|
|
|
|
tapDanceAction(tap_dance_index, row, col, tap_count_[tap_dance_index], Hold);
|
|
|
|
|
|
|
|
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
TapDance::loopHook(bool postClear) {
|
|
|
|
TapDance::loopHook(bool is_post_clear) {
|
|
|
|
if (!postClear)
|
|
|
|
if (!is_post_clear)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < 16; i++) {
|
|
|
|
for (uint8_t i = 0; i < 16; i++) {
|
|
|
|
if (!bitRead(releaseNextState, i))
|
|
|
|
if (!bitRead(release_next_state_, i))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
tapDanceAction(i, lastTapDanceRow, lastTapDanceCol, tapCount[i], Release);
|
|
|
|
tapDanceAction(i, last_tap_dance_row_, last_tap_dance_col_, tap_count_[i], Release);
|
|
|
|
tapCount[i] = 0;
|
|
|
|
tap_count_[i] = 0;
|
|
|
|
bitClear(releaseNextState, i);
|
|
|
|
bitClear(release_next_state_, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isActive())
|
|
|
|
if (!isActive())
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (endTime && millis() > endTime)
|
|
|
|
if (end_time_ && millis() > end_time_)
|
|
|
|
timeout();
|
|
|
|
timeout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace KaleidoscopePlugins
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__attribute__((weak))
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
|
|
tapDanceAction(uint8_t tapDanceIndex, byte row, byte col, uint8_t tapCount, KaleidoscopePlugins::TapDance::ActionType tapDanceAction) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KaleidoscopePlugins::TapDance TapDance;
|
|
|
|
__attribute__((weak)) void tapDanceAction(uint8_t tap_dance_index, byte row, byte col, uint8_t tap_count,
|
|
|
|
|
|
|
|
kaleidoscope::TapDance::ActionType tap_dance_action) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kaleidoscope::TapDance TapDance;
|
|
|
|