Use standard timeout checker for TapDance

Also, change timestamp from four bytes to two, and instead of using a special
timestamp value of zero to indicate that no timer is running, use
`last_tap_dance_key_`.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/642/head
Michael Richters 6 years ago
parent afcbb83bae
commit 7487d9ede6

@ -22,10 +22,10 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
// --- state --- // --- state ---
uint32_t TapDance::end_time_; uint16_t TapDance::start_time_;
uint16_t TapDance::time_out = 200; uint16_t TapDance::time_out = 200;
TapDance::TapDanceState TapDance::state_[TapDance::TAPDANCE_KEY_COUNT]; TapDance::TapDanceState TapDance::state_[TapDance::TAPDANCE_KEY_COUNT];
Key TapDance::last_tap_dance_key_; Key TapDance::last_tap_dance_key_ = Key_NoKey;
byte TapDance::last_tap_dance_row_; byte TapDance::last_tap_dance_row_;
byte TapDance::last_tap_dance_col_; byte TapDance::last_tap_dance_col_;
@ -37,7 +37,7 @@ void TapDance::interrupt(byte row, byte col) {
tapDanceAction(idx, last_tap_dance_row_, last_tap_dance_col_, state_[idx].count, Interrupt); tapDanceAction(idx, last_tap_dance_row_, last_tap_dance_col_, state_[idx].count, Interrupt);
state_[idx].triggered = true; state_[idx].triggered = true;
end_time_ = 0; last_tap_dance_key_ = Key_NoKey;
KeyboardHardware.maskKey(row, col); KeyboardHardware.maskKey(row, col);
kaleidoscope::hid::sendKeyboardReport(); kaleidoscope::hid::sendKeyboardReport();
@ -64,7 +64,6 @@ void TapDance::timeout(void) {
} }
void TapDance::release(uint8_t tap_dance_index) { void TapDance::release(uint8_t tap_dance_index) {
end_time_ = 0;
last_tap_dance_key_.raw = Key_NoKey.raw; last_tap_dance_key_.raw = Key_NoKey.raw;
state_[tap_dance_index].pressed = false; state_[tap_dance_index].pressed = false;
@ -76,7 +75,7 @@ void TapDance::tap(void) {
uint8_t idx = last_tap_dance_key_.raw - ranges::TD_FIRST; uint8_t idx = last_tap_dance_key_.raw - ranges::TD_FIRST;
state_[idx].count++; state_[idx].count++;
end_time_ = millis() + time_out; start_time_ = Kaleidoscope.millisAtCycleStart();
tapDanceAction(idx, last_tap_dance_row_, last_tap_dance_col_, state_[idx].count, Tap); tapDanceAction(idx, last_tap_dance_row_, last_tap_dance_col_, state_[idx].count, Tap);
} }
@ -198,7 +197,7 @@ EventHandlerResult TapDance::afterEachCycle() {
if (last_tap_dance_key_.raw == Key_NoKey.raw) if (last_tap_dance_key_.raw == Key_NoKey.raw)
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (end_time_ && millis() > end_time_) if (Kaleidoscope.hasTimeExpired(start_time_, time_out))
timeout(); timeout();
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -59,7 +59,7 @@ class TapDance : public kaleidoscope::Plugin {
}; };
static TapDanceState state_[TAPDANCE_KEY_COUNT]; static TapDanceState state_[TAPDANCE_KEY_COUNT];
static uint32_t end_time_; static uint16_t start_time_;
static Key last_tap_dance_key_; static Key last_tap_dance_key_;
static byte last_tap_dance_row_; static byte last_tap_dance_row_;
static byte last_tap_dance_col_; static byte last_tap_dance_col_;

Loading…
Cancel
Save