diff --git a/lib/hal/HalPowerManager.cpp b/lib/hal/HalPowerManager.cpp index c09158a7..16df2518 100644 --- a/lib/hal/HalPowerManager.cpp +++ b/lib/hal/HalPowerManager.cpp @@ -64,6 +64,14 @@ void HalPowerManager::setPowerSaving(bool enabled) { void HalPowerManager::startDeepSleep(HalGPIO& gpio, bool keepClockAlive) const { LOG_DBG("PWR", "startDeepSleep: isPressed=%d, rawPin=%d, keepClock=%d", gpio.isPressed(HalGPIO::BTN_POWER), digitalRead(InputManager::POWER_BUTTON_PIN) == LOW, keepClockAlive); + +#ifdef ENABLE_SERIAL_LOG + // Tear down HWCDC so the host sees a clean disconnect and the peripheral + // doesn't hold power domains that interfere with USB-powered GPIO wake. + // logSerial is the raw HWCDC reference; Serial is the MySerialImpl proxy + // (which doesn't expose end()). + logSerial.end(); +#endif // Perform all hardware preparation immediately (while the button may still be held) // so the user gets instant visual feedback (display already off). Only block for // button release at the very end, right before entering sleep. @@ -96,7 +104,6 @@ void HalPowerManager::startDeepSleep(HalGPIO& gpio, bool keepClockAlive) const { // regardless of the wakeup source configuration. // When keepClockAlive is true, this is the actual wakeup mechanism since the MCU stays powered. esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW); - LOG_DBG("PWR", "startDeepSleep: entering deep sleep now"); // Enter Deep Sleep esp_deep_sleep_start(); } diff --git a/src/main.cpp b/src/main.cpp index bdf1833a..64b46191 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -165,7 +166,12 @@ void enterDeepSleep() { APP_STATE.readerActivityLoadCount = 0; } APP_STATE.saveToFile(); - + // Tear down WiFi so the modem power domain isn't held alive across deep sleep. + // Wake from deep sleep is effectively a chip reset, so no state needs to survive. + if (WiFi.getMode() != WIFI_MODE_NULL) { + WiFi.disconnect(true); + WiFi.mode(WIFI_OFF); + } activityManager.goToSleep(); halTiltSensor.deepSleep();