From 0b0e061563174235bd5d3446ac314589e750b3ae Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Tue, 7 May 2019 11:16:55 -0500 Subject: [PATCH] Use standard timeout checker for OneShot Also, change timestamp from four bytes to two. Signed-off-by: Michael Richters --- src/kaleidoscope/plugin/OneShot.cpp | 8 ++++---- src/kaleidoscope/plugin/OneShot.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/kaleidoscope/plugin/OneShot.cpp b/src/kaleidoscope/plugin/OneShot.cpp index d3263ed9..7c4c05e4 100644 --- a/src/kaleidoscope/plugin/OneShot.cpp +++ b/src/kaleidoscope/plugin/OneShot.cpp @@ -22,7 +22,7 @@ namespace plugin { // ---- state --------- -uint32_t OneShot::start_time_ = 0; +uint16_t OneShot::start_time_ = 0; uint16_t OneShot::time_out = 2500; uint16_t OneShot::hold_time_out = 250; int16_t OneShot::double_tap_time_out = -1; @@ -113,7 +113,7 @@ EventHandlerResult OneShot::onKeyswitchEvent(Key &mapped_key, byte row, byte col } else { if (keyToggledOff(keyState)) { state_[idx].pressed = false; - if ((Kaleidoscope.millisAtCycleStart() - start_time_) >= hold_time_out) { + if (Kaleidoscope.hasTimeExpired(start_time_, hold_time_out)) { cancelOneShot(idx); should_cancel_ = false; } @@ -123,8 +123,8 @@ EventHandlerResult OneShot::onKeyswitchEvent(Key &mapped_key, byte row, byte col state_[idx].pressed = true; if (prev_key_ == mapped_key && isStickable(mapped_key)) { - if ((Kaleidoscope.millisAtCycleStart() - start_time_) <= - uint16_t((double_tap_time_out == -1) ? time_out : double_tap_time_out)) { + uint16_t dtto = (double_tap_time_out == -1) ? time_out : double_tap_time_out; + if (!Kaleidoscope.hasTimeExpired(start_time_, dtto)) { state_[idx].sticky = true; prev_key_ = mapped_key; } diff --git a/src/kaleidoscope/plugin/OneShot.h b/src/kaleidoscope/plugin/OneShot.h index fcdcfb46..1ffeb0c7 100644 --- a/src/kaleidoscope/plugin/OneShot.h +++ b/src/kaleidoscope/plugin/OneShot.h @@ -90,7 +90,7 @@ class OneShot : public kaleidoscope::Plugin { } key_state_t; static key_state_t state_[ONESHOT_KEY_COUNT]; - static uint32_t start_time_; + static uint16_t start_time_; static Key prev_key_; static bool should_cancel_; static bool should_cancel_stickies_; @@ -103,7 +103,7 @@ class OneShot : public kaleidoscope::Plugin { return key.raw >= ranges::OS_FIRST && key.raw <= ranges::OS_LAST; } static bool hasTimedOut() { - return Kaleidoscope.millisAtCycleStart() - start_time_ >= time_out; + return Kaleidoscope.hasTimeExpired(start_time_, time_out); } }; }