From 0854061e36be288e30af16b9a69f6e8520c42ff5 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Fri, 2 Aug 2024 17:29:59 +0200 Subject: [PATCH] =?UTF-8?q?=E2=8F=B1=EF=B8=8F=20Updates=20timing=20macro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp32/lib/ESP32-sveltekit/Timing.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/esp32/lib/ESP32-sveltekit/Timing.h b/esp32/lib/ESP32-sveltekit/Timing.h index 7616976..c993b0f 100644 --- a/esp32/lib/ESP32-sveltekit/Timing.h +++ b/esp32/lib/ESP32-sveltekit/Timing.h @@ -5,14 +5,14 @@ #define UNIQUE_VAR(base) CONCAT(base, __LINE__) -#define EXECUTE_EVERY_N_MS(n, code) \ - do { \ - static volatile unsigned long UNIQUE_VAR(lastExecution_) = ULONG_MAX; \ - unsigned long currentMillis = millis(); \ - if (currentMillis - UNIQUE_VAR(lastExecution_) >= n) { \ - code; \ - UNIQUE_VAR(lastExecution_) = currentMillis; \ - } \ +#define EXECUTE_EVERY_N_MS(n, code) \ + do { \ + static volatile unsigned long UNIQUE_VAR(lastExecution_) = 0; \ + unsigned long currentMillis = millis(); \ + if (UNIQUE_VAR(lastExecution_) == 0 || currentMillis - UNIQUE_VAR(lastExecution_) >= n) { \ + code; \ + UNIQUE_VAR(lastExecution_) = currentMillis; \ + } \ } while (0) #define TIME_IT(code) \