From e7fd8a326adc4ccb2939bb571030f0e5b8b71195 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Tue, 7 May 2019 11:11:10 -0500 Subject: [PATCH] Use standard timeout checker for IdleLEDs Also, remove unnecessary `onSetup()` hook function. Signed-off-by: Michael Richters --- src/kaleidoscope/plugin/IdleLEDs.cpp | 6 +++--- src/kaleidoscope/plugin/IdleLEDs.h | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/kaleidoscope/plugin/IdleLEDs.cpp b/src/kaleidoscope/plugin/IdleLEDs.cpp index 00918e60..449db057 100644 --- a/src/kaleidoscope/plugin/IdleLEDs.cpp +++ b/src/kaleidoscope/plugin/IdleLEDs.cpp @@ -22,11 +22,11 @@ namespace kaleidoscope { namespace plugin { uint16_t IdleLEDs::idle_time_limit = 600; // 10 minutes -uint32_t IdleLEDs::end_time_; +uint32_t IdleLEDs::start_time_ = 0; EventHandlerResult IdleLEDs::beforeEachCycle() { if (!::LEDControl.paused && - (Kaleidoscope.millisAtCycleStart() >= end_time_)) { + Kaleidoscope.hasTimeExpired(start_time_, uint32_t(idle_time_limit * 1000))) { ::LEDControl.set_all_leds_to(CRGB(0, 0, 0)); ::LEDControl.syncLeds(); @@ -43,7 +43,7 @@ EventHandlerResult IdleLEDs::onKeyswitchEvent(Key &mapped_key, byte row, byte co ::LEDControl.refreshAll(); } - end_time_ = Kaleidoscope.millisAtCycleStart() + (uint32_t)idle_time_limit * 1000; + start_time_ = Kaleidoscope.millisAtCycleStart(); return EventHandlerResult::OK; } diff --git a/src/kaleidoscope/plugin/IdleLEDs.h b/src/kaleidoscope/plugin/IdleLEDs.h index e6e307a4..19d27a51 100644 --- a/src/kaleidoscope/plugin/IdleLEDs.h +++ b/src/kaleidoscope/plugin/IdleLEDs.h @@ -28,15 +28,11 @@ class IdleLEDs: public kaleidoscope::Plugin { static uint16_t idle_time_limit; - EventHandlerResult onSetup() { - end_time_ = millis() + idle_time_limit * 1000; - return EventHandlerResult::OK; - } EventHandlerResult beforeEachCycle(); EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state); private: - static uint32_t end_time_; + static uint32_t start_time_; }; } }