From 09afa0ec72ffa6fed9a988884b4c31befcd19c4d Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 21 Feb 2017 07:55:27 +0100 Subject: [PATCH] Improved timer checking code Instead of doing a substraction and a compare in the if check, whenever we reset the timer, add `syncDelay`, and compare against the timer only. Should result in marginally better performing code. Thanks @obra for the suggestion! Signed-off-by: Gergely Nagy --- src/Kaleidoscope-LEDControl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kaleidoscope-LEDControl.cpp b/src/Kaleidoscope-LEDControl.cpp index 35770a96..7e440afc 100644 --- a/src/Kaleidoscope-LEDControl.cpp +++ b/src/Kaleidoscope-LEDControl.cpp @@ -129,7 +129,7 @@ LEDControl_::begin (void) { event_handler_hook_use(eventHandler); loop_hook_use(loopHook); - syncTimer = millis(); + syncTimer = millis() + syncDelay; } Key @@ -148,9 +148,9 @@ LEDControl_::loopHook (bool postClear) { if (postClear) return; - if (millis() - syncTimer >= syncDelay) { + if (millis() > syncTimer) { led_sync(); - syncTimer = millis(); + syncTimer = millis() + syncDelay; } update(); }