Use standard timeout checker for Leader

Also, change timestamp from four bytes to two.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/642/head
Michael Richters 6 years ago
parent 2c75dceedf
commit dfdb1c2e25

@ -23,7 +23,7 @@ namespace plugin {
// --- state --- // --- state ---
Key Leader::sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1]; Key Leader::sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1];
uint8_t Leader::sequence_pos_; uint8_t Leader::sequence_pos_;
uint32_t Leader::end_time_; uint16_t Leader::start_time_ = 0;
uint16_t Leader::time_out = 1000; uint16_t Leader::time_out = 1000;
const Leader::dictionary_t *Leader::dictionary; const Leader::dictionary_t *Leader::dictionary;
@ -93,7 +93,7 @@ EventHandlerResult Leader::onKeyswitchEvent(Key &mapped_key, byte row, byte col,
if (keyToggledOff(keyState)) { if (keyToggledOff(keyState)) {
// not active, but a leader key = start the sequence on key release! // 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_pos_ = 0;
sequence_[sequence_pos_].raw = mapped_key.raw; sequence_[sequence_pos_].raw = mapped_key.raw;
} }
@ -112,7 +112,7 @@ EventHandlerResult Leader::onKeyswitchEvent(Key &mapped_key, byte row, byte col,
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
end_time_ = millis() + time_out; start_time_ = Kaleidoscope.millisAtCycleStart();
sequence_[sequence_pos_].raw = mapped_key.raw; sequence_[sequence_pos_].raw = mapped_key.raw;
action_index = lookup(); action_index = lookup();
@ -142,7 +142,7 @@ EventHandlerResult Leader::afterEachCycle() {
if (!isActive()) if (!isActive())
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (millis() >= end_time_) if (Kaleidoscope.hasTimeExpired(start_time_, time_out))
reset(); reset();
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -52,7 +52,7 @@ class Leader : public kaleidoscope::Plugin {
private: private:
static Key sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1]; static Key sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1];
static uint8_t sequence_pos_; static uint8_t sequence_pos_;
static uint32_t end_time_; static uint16_t start_time_;
static int8_t lookup(void); static int8_t lookup(void);
}; };

Loading…
Cancel
Save