From 3f24eefcfaa2442b085dbb6834f4b441b1d0cb50 Mon Sep 17 00:00:00 2001 From: Luke Marzen <98473324+lmarzen@users.noreply.github.com> Date: Sat, 26 Oct 2024 22:17:56 -0500 Subject: [PATCH] fixed bug that would cause sleep durations to sometimes being twice as long as they should be --- platformio/src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platformio/src/main.cpp b/platformio/src/main.cpp index a09afc8d..50eb4b4c 100644 --- a/platformio/src/main.cpp +++ b/platformio/src/main.cpp @@ -77,7 +77,7 @@ void beginDeepSleep(unsigned long startTime, tm *timeInfo) // align wake time to nearest multiple of SLEEP_DURATION int sleepMinutes = SLEEP_DURATION - offsetMinutes; - if (offsetSeconds < 120 + if (desiredSleepSeconds - offsetSeconds < 120 || offsetSeconds / (float)desiredSleepSeconds > 0.95f) { // if we have a sleep time less than 2 minutes OR less 5% SLEEP_DURATION, // skip to next alignment @@ -101,7 +101,8 @@ void beginDeepSleep(unsigned long startTime, tm *timeInfo) } // add extra delay to compensate for esp32's with fast RTCs. - sleepDuration += 10ULL; + sleepDuration += 1ULL; + sleepDuration *= 1.0015f; #if DEBUG_LEVEL >= 1 printHeapUsage();