From 3d25b7be287567475490d5bbbabf9b4e1367ca2e Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 21 Feb 2017 12:44:05 +0100 Subject: [PATCH] Improved timeout handling Instead of calculating the time delta each time we check for a timeout, pre-calculate the projected ending time, and compare against that. Signed-off-by: Gergely Nagy --- src/Kaleidoscope/LED-Stalker.cpp | 7 +++---- src/Kaleidoscope/LED-Stalker.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Kaleidoscope/LED-Stalker.cpp b/src/Kaleidoscope/LED-Stalker.cpp index 02cf86a0..7c0fa655 100644 --- a/src/Kaleidoscope/LED-Stalker.cpp +++ b/src/Kaleidoscope/LED-Stalker.cpp @@ -23,7 +23,7 @@ namespace KaleidoscopePlugins { uint8_t StalkerEffect::map[ROWS][COLS]; StalkerEffect::ColorComputer *StalkerEffect::colorComputer; uint16_t StalkerEffect::stepLength = 50; - uint32_t StalkerEffect::stepStartTime; + uint32_t StalkerEffect::stepEndTime; StalkerEffect::StalkerEffect (void) { } @@ -37,7 +37,6 @@ namespace KaleidoscopePlugins { StalkerEffect::begin (void) { event_handler_hook_use (eventHandlerHook); loop_hook_use (loopHook); - stepStartTime = millis (); } Key @@ -60,7 +59,7 @@ namespace KaleidoscopePlugins { if (!colorComputer) return; - bool timeOut = (millis () - stepStartTime) >= stepLength; + bool timeOut = millis () >= stepEndTime; for (byte r = 0; r < ROWS; r++) { for (byte c = 0; c < COLS; c++) { @@ -86,7 +85,7 @@ namespace KaleidoscopePlugins { } if (timeOut) - stepStartTime = millis (); + stepEndTime = millis () + stepLength; } namespace Stalker { diff --git a/src/Kaleidoscope/LED-Stalker.h b/src/Kaleidoscope/LED-Stalker.h index af108a8a..7b670aaf 100644 --- a/src/Kaleidoscope/LED-Stalker.h +++ b/src/Kaleidoscope/LED-Stalker.h @@ -37,7 +37,7 @@ namespace KaleidoscopePlugins { static uint16_t stepLength; private: - static uint32_t stepStartTime; + static uint32_t stepEndTime; static ColorComputer *colorComputer; static uint8_t map[ROWS][COLS];