fix startDeepSleep()

This commit is contained in:
Xuan Son Nguyen 2026-01-23 16:32:21 +01:00
parent fa05eba8a1
commit 72c2da971d
3 changed files with 8 additions and 8 deletions

View File

@ -69,17 +69,17 @@ unsigned long HalInput::getHeldTime() const {
#endif #endif
} }
void HalInput::setupGpioWakeup() { void startDeepSleep(InputManager& inputMgr) {
#if CROSSPOINT_EMULATED == 0 #if CROSSPOINT_EMULATED == 0
esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW); esp_deep_sleep_enable_gpio_wakeup(1ULL << InputManager::POWER_BUTTON_PIN, ESP_GPIO_WAKEUP_GPIO_LOW);
// Ensure that the power button has been released to avoid immediately turning back on if you're holding it // Ensure that the power button has been released to avoid immediately turning back on if you're holding it
while (isPressed(InputManager::BTN_POWER)) { while (inputMgr.isPressed(InputManager::BTN_POWER)) {
delay(50); delay(50);
update(); inputMgr.update();
} }
// Enter Deep Sleep // Enter Deep Sleep
esp_deep_sleep_start(); esp_deep_sleep_start();
#else #else
// TODO Serial.println("[ ] GPIO wakeup setup skipped in emulation mode.");
#endif #endif
} }

View File

@ -23,8 +23,6 @@ class HalInput {
bool wasAnyReleased() const; bool wasAnyReleased() const;
unsigned long getHeldTime() const; unsigned long getHeldTime() const;
void setupGpioWakeup();
// Button indices // Button indices
static constexpr uint8_t BTN_BACK = 0; static constexpr uint8_t BTN_BACK = 0;
static constexpr uint8_t BTN_CONFIRM = 1; static constexpr uint8_t BTN_CONFIRM = 1;
@ -38,3 +36,5 @@ class HalInput {
#if CROSSPOINT_EMULATED == 1 #if CROSSPOINT_EMULATED == 1
using InputManager = HalInput; using InputManager = HalInput;
#endif #endif
void startDeepSleep(InputManager& inputMgr);

View File

@ -184,7 +184,7 @@ void verifyWakeupLongPress() {
if (abort) { if (abort) {
// Button released too early. Returning to sleep. // Button released too early. Returning to sleep.
// IMPORTANT: Re-arm the wakeup trigger before sleeping again // IMPORTANT: Re-arm the wakeup trigger before sleeping again
inputManager.setupGpioWakeup(); startDeepSleep(inputManager);
} }
} }
@ -207,7 +207,7 @@ void enterDeepSleep() {
einkDisplay.deepSleep(); einkDisplay.deepSleep();
Serial.printf("[%lu] [ ] Power button press calibration value: %lu ms\n", millis(), t2 - t1); Serial.printf("[%lu] [ ] Power button press calibration value: %lu ms\n", millis(), t2 - t1);
Serial.printf("[%lu] [ ] Entering deep sleep.\n", millis()); Serial.printf("[%lu] [ ] Entering deep sleep.\n", millis());
inputManager.setupGpioWakeup(); startDeepSleep(inputManager);
} }
void onGoHome(); void onGoHome();