From 441812abcc1c38f361be0ab05f866bc0fbdb157e Mon Sep 17 00:00:00 2001 From: matt venn Date: Mon, 9 Jul 2018 14:06:52 +0200 Subject: [PATCH 1/2] fixed LED sync overflow bug --- src/Kaleidoscope-LEDControl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kaleidoscope-LEDControl.cpp b/src/Kaleidoscope-LEDControl.cpp index 4ae30a6d..a5f41d90 100644 --- a/src/Kaleidoscope-LEDControl.cpp +++ b/src/Kaleidoscope-LEDControl.cpp @@ -151,8 +151,8 @@ kaleidoscope::EventHandlerResult LEDControl::beforeReportingState(void) { if (paused) return kaleidoscope::EventHandlerResult::OK; - uint16_t current_time = millis(); - if ((current_time - syncTimer) > syncDelay) { + uint16_t elapsed = Kaleidoscope.millisAtCycleStart() - syncTimer; + if (elapsed > syncDelay) { syncLeds(); syncTimer += syncDelay; } From 76e8478ff6919eb1e463fa83cb36621ac5c86746 Mon Sep 17 00:00:00 2001 From: matt venn Date: Tue, 10 Jul 2018 09:47:38 +0200 Subject: [PATCH 2/2] code comments --- src/Kaleidoscope-LEDControl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Kaleidoscope-LEDControl.cpp b/src/Kaleidoscope-LEDControl.cpp index a5f41d90..80266a77 100644 --- a/src/Kaleidoscope-LEDControl.cpp +++ b/src/Kaleidoscope-LEDControl.cpp @@ -151,7 +151,11 @@ 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) { syncLeds(); syncTimer += syncDelay;