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 <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent 68b3e2c5f2
commit 3d25b7be28

@ -23,7 +23,7 @@ namespace KaleidoscopePlugins {
uint8_t StalkerEffect::map[ROWS][COLS]; uint8_t StalkerEffect::map[ROWS][COLS];
StalkerEffect::ColorComputer *StalkerEffect::colorComputer; StalkerEffect::ColorComputer *StalkerEffect::colorComputer;
uint16_t StalkerEffect::stepLength = 50; uint16_t StalkerEffect::stepLength = 50;
uint32_t StalkerEffect::stepStartTime; uint32_t StalkerEffect::stepEndTime;
StalkerEffect::StalkerEffect (void) { StalkerEffect::StalkerEffect (void) {
} }
@ -37,7 +37,6 @@ namespace KaleidoscopePlugins {
StalkerEffect::begin (void) { StalkerEffect::begin (void) {
event_handler_hook_use (eventHandlerHook); event_handler_hook_use (eventHandlerHook);
loop_hook_use (loopHook); loop_hook_use (loopHook);
stepStartTime = millis ();
} }
Key Key
@ -60,7 +59,7 @@ namespace KaleidoscopePlugins {
if (!colorComputer) if (!colorComputer)
return; return;
bool timeOut = (millis () - stepStartTime) >= stepLength; bool timeOut = millis () >= stepEndTime;
for (byte r = 0; r < ROWS; r++) { for (byte r = 0; r < ROWS; r++) {
for (byte c = 0; c < COLS; c++) { for (byte c = 0; c < COLS; c++) {
@ -86,7 +85,7 @@ namespace KaleidoscopePlugins {
} }
if (timeOut) if (timeOut)
stepStartTime = millis (); stepEndTime = millis () + stepLength;
} }
namespace Stalker { namespace Stalker {

@ -37,7 +37,7 @@ namespace KaleidoscopePlugins {
static uint16_t stepLength; static uint16_t stepLength;
private: private:
static uint32_t stepStartTime; static uint32_t stepEndTime;
static ColorComputer *colorComputer; static ColorComputer *colorComputer;
static uint8_t map[ROWS][COLS]; static uint8_t map[ROWS][COLS];

Loading…
Cancel
Save