From dfdb1c2e259fd2c9b475b1b99e4db07b4be3eb57 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Tue, 7 May 2019 11:14:45 -0500 Subject: [PATCH] Use standard timeout checker for Leader Also, change timestamp from four bytes to two. Signed-off-by: Michael Richters --- src/kaleidoscope/plugin/Leader.cpp | 8 ++++---- src/kaleidoscope/plugin/Leader.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/kaleidoscope/plugin/Leader.cpp b/src/kaleidoscope/plugin/Leader.cpp index 9deb4cd3..8c1d9069 100644 --- a/src/kaleidoscope/plugin/Leader.cpp +++ b/src/kaleidoscope/plugin/Leader.cpp @@ -23,7 +23,7 @@ namespace plugin { // --- state --- Key Leader::sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1]; uint8_t Leader::sequence_pos_; -uint32_t Leader::end_time_; +uint16_t Leader::start_time_ = 0; uint16_t Leader::time_out = 1000; const Leader::dictionary_t *Leader::dictionary; @@ -93,7 +93,7 @@ EventHandlerResult Leader::onKeyswitchEvent(Key &mapped_key, byte row, byte col, if (keyToggledOff(keyState)) { // not active, but a leader key = start the sequence on key release! - end_time_ = millis() + time_out; + start_time_ = Kaleidoscope.millisAtCycleStart(); sequence_pos_ = 0; sequence_[sequence_pos_].raw = mapped_key.raw; } @@ -112,7 +112,7 @@ EventHandlerResult Leader::onKeyswitchEvent(Key &mapped_key, byte row, byte col, return EventHandlerResult::OK; } - end_time_ = millis() + time_out; + start_time_ = Kaleidoscope.millisAtCycleStart(); sequence_[sequence_pos_].raw = mapped_key.raw; action_index = lookup(); @@ -142,7 +142,7 @@ EventHandlerResult Leader::afterEachCycle() { if (!isActive()) return EventHandlerResult::OK; - if (millis() >= end_time_) + if (Kaleidoscope.hasTimeExpired(start_time_, time_out)) reset(); return EventHandlerResult::OK; diff --git a/src/kaleidoscope/plugin/Leader.h b/src/kaleidoscope/plugin/Leader.h index d08e5717..d52db1bd 100644 --- a/src/kaleidoscope/plugin/Leader.h +++ b/src/kaleidoscope/plugin/Leader.h @@ -52,7 +52,7 @@ class Leader : public kaleidoscope::Plugin { private: static Key sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1]; static uint8_t sequence_pos_; - static uint32_t end_time_; + static uint16_t start_time_; static int8_t lookup(void); };