From fa19951d56ca706ca057fa0b708812e3a7d289f3 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Tue, 7 May 2019 10:53:21 -0500 Subject: [PATCH] Use standard timeout checker for LEDControl In addition, the interval `syncDelay` was changed from a two-byte integer to a one-byte integer, because LED update intervals longer than 255ms would be user-visible. Signed-off-by: Michael Richters --- src/kaleidoscope/plugin/LEDControl.cpp | 13 +++---------- src/kaleidoscope/plugin/LEDControl.h | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/kaleidoscope/plugin/LEDControl.cpp b/src/kaleidoscope/plugin/LEDControl.cpp index 2dd9d590..aac66d20 100644 --- a/src/kaleidoscope/plugin/LEDControl.cpp +++ b/src/kaleidoscope/plugin/LEDControl.cpp @@ -28,8 +28,8 @@ static constexpr uint8_t uninitialized_mode_id = 255; uint8_t LEDControl::mode_id = uninitialized_mode_id; uint8_t LEDControl::num_led_modes_ = LEDModeManager::numLEDModes(); LEDMode *LEDControl::cur_led_mode_; -uint16_t LEDControl::syncDelay = 32; -uint16_t LEDControl::syncTimer; +uint8_t LEDControl::syncDelay = 32; +uint16_t LEDControl::syncTimer = 0; bool LEDControl::paused = false; LEDControl::LEDControl(void) { @@ -125,8 +125,6 @@ kaleidoscope::EventHandlerResult LEDControl::onSetup() { LEDModeManager::setupPersistentLEDModes(); - syncTimer = millis() + syncDelay; - if (mode_id == uninitialized_mode_id) { set_mode(0); } @@ -153,12 +151,7 @@ kaleidoscope::EventHandlerResult LEDControl::beforeReportingState(void) { if (paused) return kaleidoscope::EventHandlerResult::OK; - // unsigned subtraction means that as syncTimer rolls over - // the same interval is kept - uint16_t elapsed = Kaleidoscope.millisAtCycleStart() - syncTimer; - // on some platforms, the subtraction in the comparison results in a signed - // operation, resulting in syncLeds() no longer getting called. - if (elapsed > syncDelay) { + if (Kaleidoscope.hasTimeExpired(syncTimer, syncDelay)) { syncLeds(); syncTimer += syncDelay; update(); diff --git a/src/kaleidoscope/plugin/LEDControl.h b/src/kaleidoscope/plugin/LEDControl.h index 7a500057..4b4e2eb6 100644 --- a/src/kaleidoscope/plugin/LEDControl.h +++ b/src/kaleidoscope/plugin/LEDControl.h @@ -95,7 +95,7 @@ class LEDControl : public kaleidoscope::Plugin { // static void activate(LEDModeInterface *plugin); - static uint16_t syncDelay; + static uint8_t syncDelay; static bool paused; kaleidoscope::EventHandlerResult onSetup();