From 3a54de372937d025d691e5d7fe5b2a1e85eab541 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 5 Jun 2023 13:37:46 +0200 Subject: [PATCH] Fix sleep bug --- src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b166fbc..cad8b4c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ RTC_DATA_ATTR uint32_t nextTimeToMeasureTemperatureSeconds = 0; // Indicate the time until the device should stay awake // Updated when button is pressed -uint32_t timeUntilSleep = 0; +uint32_t sleepStartAfterButtonPressOrConnection = 0; /** * @brief Check if enough time has passed for the next temperature measurement @@ -50,7 +50,7 @@ uint32_t secondsUntilNextTemperatureMeasurement() { void deepSleepUntilNextTemperatureMeasurement() { uint32_t seconds = secondsUntilNextTemperatureMeasurement(); - if (seconds = 0) { + if (seconds == 0) { // The time until next measurement is too short, // so don't sleep and just wait a little // May run the loop multiple times until the time is elapsed @@ -75,14 +75,14 @@ bool wakeupButtonIsPressed() { } void updateStayAwakeTime() { - timeUntilSleep = time(NULL) + wakeupDurationAfterButtonPress; + sleepStartAfterButtonPressOrConnection = time(NULL) + wakeupDurationAfterButtonPress; } bool shouldGoToSleep() { - if (timeUntilSleep > time(NULL)) { + if (bluetoothIsConnected()) { return false; } - if (bluetoothIsConnected()) { + if (time(NULL) <= sleepStartAfterButtonPressOrConnection) { return false; } return true;