From 85b47caa732bcfdf977fdf0606e47744d4493110 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Tue, 7 May 2019 11:03:41 -0500 Subject: [PATCH] Use standard timeout checker for LED-BootGreeting Alos, don't bother to set `start_time` in `onSetup()`; it's unnecessary. Instead, call `findLed()` there. Signed-off-by: Michael Richters --- .../plugin/LEDEffect-BootGreeting.cpp | 16 ++++++---------- src/kaleidoscope/plugin/LEDEffect-BootGreeting.h | 1 + 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/kaleidoscope/plugin/LEDEffect-BootGreeting.cpp b/src/kaleidoscope/plugin/LEDEffect-BootGreeting.cpp index ecda8ba3..a1e744c8 100644 --- a/src/kaleidoscope/plugin/LEDEffect-BootGreeting.cpp +++ b/src/kaleidoscope/plugin/LEDEffect-BootGreeting.cpp @@ -60,6 +60,11 @@ void BootGreetingEffect::findLed(void) { done_ = true; } +EventHandlerResult BootGreetingEffect::onSetup() { + findLed(); + return EventHandlerResult::OK; +} + EventHandlerResult BootGreetingEffect::afterEachCycle() { if (!Kaleidoscope.has_leds) return EventHandlerResult::OK; @@ -69,17 +74,8 @@ EventHandlerResult BootGreetingEffect::afterEachCycle() { return EventHandlerResult::OK; } - //If the start time isn't set, set the start time and - //find the LEDs. - if (start_time == 0) { - start_time = millis(); - findLed(); - //the first time, don't do anything. - return EventHandlerResult::OK; - } - //Only run for 'timeout' milliseconds - if ((millis() - start_time) > timeout) { + if (Kaleidoscope.hasTimeExpired(start_time, timeout)) { done_ = true; ::LEDControl.refreshAt(row_, col_); return EventHandlerResult::OK; diff --git a/src/kaleidoscope/plugin/LEDEffect-BootGreeting.h b/src/kaleidoscope/plugin/LEDEffect-BootGreeting.h index aeeae501..7dcbbf86 100644 --- a/src/kaleidoscope/plugin/LEDEffect-BootGreeting.h +++ b/src/kaleidoscope/plugin/LEDEffect-BootGreeting.h @@ -32,6 +32,7 @@ class BootGreetingEffect : public kaleidoscope::Plugin { static uint8_t hue; static uint16_t timeout; + EventHandlerResult onSetup(); EventHandlerResult afterEachCycle(); private: