From 1eed75ea31ec7168dfb4d592d1a8d3e1735d6fca Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Thu, 22 Jan 2026 02:26:13 +0100 Subject: [PATCH 1/3] fix: short-press power button to wakeup --- src/main.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c0222e0d..12e4fbfb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -151,8 +151,15 @@ void enterNewActivity(Activity* activity) { currentActivity->onEnter(); } -// Verify long press on wake-up from deep sleep -void verifyWakeupLongPress() { +// Verify power button press duration on wake-up from deep sleep +// Pre-condition: isWakeupByPowerButton() == true +void verifyPowerButtonDuration() { + if (SETTINGS.getPowerButtonDuration() <= 10) { + // Fast path for short press + // Needed because inputManager.isPressed() may take up to ~500ms to return the correct state + return; + } + // Give the user up to 1000ms to start holding the power button, and must hold for SETTINGS.getPowerButtonDuration() const auto start = millis(); bool abort = false; @@ -165,6 +172,7 @@ void verifyWakeupLongPress() { inputManager.update(); // Verify the user has actually pressed + // Needed because inputManager.isPressed() may take up to ~500ms to return the correct state while (!inputManager.isPressed(InputManager::BTN_POWER) && millis() - start < 1000) { delay(10); // only wait 10ms each iteration to not delay too much in case of short configured duration. inputManager.update(); @@ -288,6 +296,11 @@ bool isWakeupAfterFlashing() { return isUsbConnected() && (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED) && (resetReason == ESP_RST_UNKNOWN); } +bool isWakeupByPowerButton() { + const auto wakeupCause = esp_sleep_get_wakeup_cause(); + return wakeupCause == ESP_SLEEP_WAKEUP_GPIO; +} + void setup() { t1 = millis(); @@ -322,9 +335,10 @@ void setup() { SETTINGS.loadFromFile(); KOREADER_STORE.loadFromFile(); - if (!isWakeupAfterFlashing()) { - // For normal wakeups (not immediately after flashing), verify long press - verifyWakeupLongPress(); + if (isWakeupByPowerButton()) { + // For normal wakeups, verify power button press duration + Serial.printf("[%lu] [ ] Verifying power button press duration\n", millis()); + verifyPowerButtonDuration(); } // First serial output only here to avoid timing inconsistencies for power button press duration verification From 1867b55f5296f8c365527f678a0444dce242adef Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Thu, 22 Jan 2026 11:25:20 +0100 Subject: [PATCH 2/3] apply suggestion --- src/CrossPointSettings.h | 5 ++++- src/main.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/CrossPointSettings.h b/src/CrossPointSettings.h index 8ce32a2c..1a5221a3 100644 --- a/src/CrossPointSettings.h +++ b/src/CrossPointSettings.h @@ -54,6 +54,8 @@ class CrossPointSettings { // Short power button press actions enum SHORT_PWRBTN { IGNORE = 0, SLEEP = 1, PAGE_TURN = 2 }; + static constexpr uint16_t SHORT_PRESS_DURATION_MS = 10; + static constexpr uint16_t LONG_PRESS_DURATION_MS = 400; // Hide battery percentage enum HIDE_BATTERY_PERCENTAGE { HIDE_NEVER = 0, HIDE_READER = 1, HIDE_ALWAYS = 2 }; @@ -101,7 +103,8 @@ class CrossPointSettings { static CrossPointSettings& getInstance() { return instance; } uint16_t getPowerButtonDuration() const { - return (shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::SLEEP) ? 10 : 400; + return (shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::SLEEP) + ? SHORT_PRESS_DURATION_MS : LONG_PRESS_DURATION_MS; } int getReaderFontId() const; diff --git a/src/main.cpp b/src/main.cpp index 12e4fbfb..b6370fac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -154,7 +154,7 @@ void enterNewActivity(Activity* activity) { // Verify power button press duration on wake-up from deep sleep // Pre-condition: isWakeupByPowerButton() == true void verifyPowerButtonDuration() { - if (SETTINGS.getPowerButtonDuration() <= 10) { + if (SETTINGS.getPowerButtonDuration() <= CrossPointSettings::SHORT_PRESS_DURATION_MS) { // Fast path for short press // Needed because inputManager.isPressed() may take up to ~500ms to return the correct state return; From bab513cc95ee4f62c72f3f5d724134556c8b06be Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Thu, 22 Jan 2026 12:18:00 +0100 Subject: [PATCH 3/3] fix clang-format --- src/CrossPointSettings.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CrossPointSettings.h b/src/CrossPointSettings.h index 1a5221a3..09257a7b 100644 --- a/src/CrossPointSettings.h +++ b/src/CrossPointSettings.h @@ -103,8 +103,7 @@ class CrossPointSettings { static CrossPointSettings& getInstance() { return instance; } uint16_t getPowerButtonDuration() const { - return (shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::SLEEP) - ? SHORT_PRESS_DURATION_MS : LONG_PRESS_DURATION_MS; + return (shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::SLEEP) ? SHORT_PRESS_DURATION_MS : LONG_PRESS_DURATION_MS; } int getReaderFontId() const;