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 <gedankenexperimenter@gmail.com>
pull/642/head
Michael Richters 6 years ago
parent f46b4343d9
commit fa19951d56

@ -28,8 +28,8 @@ static constexpr uint8_t uninitialized_mode_id = 255;
uint8_t LEDControl::mode_id = uninitialized_mode_id; uint8_t LEDControl::mode_id = uninitialized_mode_id;
uint8_t LEDControl::num_led_modes_ = LEDModeManager::numLEDModes(); uint8_t LEDControl::num_led_modes_ = LEDModeManager::numLEDModes();
LEDMode *LEDControl::cur_led_mode_; LEDMode *LEDControl::cur_led_mode_;
uint16_t LEDControl::syncDelay = 32; uint8_t LEDControl::syncDelay = 32;
uint16_t LEDControl::syncTimer; uint16_t LEDControl::syncTimer = 0;
bool LEDControl::paused = false; bool LEDControl::paused = false;
LEDControl::LEDControl(void) { LEDControl::LEDControl(void) {
@ -125,8 +125,6 @@ kaleidoscope::EventHandlerResult LEDControl::onSetup() {
LEDModeManager::setupPersistentLEDModes(); LEDModeManager::setupPersistentLEDModes();
syncTimer = millis() + syncDelay;
if (mode_id == uninitialized_mode_id) { if (mode_id == uninitialized_mode_id) {
set_mode(0); set_mode(0);
} }
@ -153,12 +151,7 @@ kaleidoscope::EventHandlerResult LEDControl::beforeReportingState(void) {
if (paused) if (paused)
return kaleidoscope::EventHandlerResult::OK; return kaleidoscope::EventHandlerResult::OK;
// unsigned subtraction means that as syncTimer rolls over if (Kaleidoscope.hasTimeExpired(syncTimer, syncDelay)) {
// 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) {
syncLeds(); syncLeds();
syncTimer += syncDelay; syncTimer += syncDelay;
update(); update();

@ -95,7 +95,7 @@ class LEDControl : public kaleidoscope::Plugin {
// //
static void activate(LEDModeInterface *plugin); static void activate(LEDModeInterface *plugin);
static uint16_t syncDelay; static uint8_t syncDelay;
static bool paused; static bool paused;
kaleidoscope::EventHandlerResult onSetup(); kaleidoscope::EventHandlerResult onSetup();

Loading…
Cancel
Save