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;