fix: short-press power button to wakeup (#482)
Cherry-picked from upstream PR #482 Compatible with existing DICTIONARY option in SHORT_PWRBTN
This commit is contained in:
parent
ff0392b9d2
commit
6ffd19a7e8
28
src/main.cpp
28
src/main.cpp
@ -148,8 +148,15 @@ void enterNewActivity(Activity* activity) {
|
|||||||
logMemoryState("MAIN", "After onEnter");
|
logMemoryState("MAIN", "After onEnter");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify long press on wake-up from deep sleep
|
// Verify power button press duration on wake-up from deep sleep
|
||||||
void verifyWakeupLongPress() {
|
// Pre-condition: isWakeupByPowerButton() == true
|
||||||
|
void verifyPowerButtonDuration() {
|
||||||
|
if (SETTINGS.shortPwrBtn == CrossPointSettings::SHORT_PWRBTN::SLEEP) {
|
||||||
|
// 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()
|
// Give the user up to 1000ms to start holding the power button, and must hold for SETTINGS.getPowerButtonDuration()
|
||||||
const auto start = millis();
|
const auto start = millis();
|
||||||
bool abort = false;
|
bool abort = false;
|
||||||
@ -162,6 +169,7 @@ void verifyWakeupLongPress() {
|
|||||||
|
|
||||||
inputManager.update();
|
inputManager.update();
|
||||||
// Verify the user has actually pressed
|
// 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) {
|
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.
|
delay(10); // only wait 10ms each iteration to not delay too much in case of short configured duration.
|
||||||
inputManager.update();
|
inputManager.update();
|
||||||
@ -307,11 +315,14 @@ bool isUsbConnected() {
|
|||||||
return digitalRead(UART0_RXD) == HIGH;
|
return digitalRead(UART0_RXD) == HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isWakeupAfterFlashing() {
|
bool isWakeupByPowerButton() {
|
||||||
const auto wakeupCause = esp_sleep_get_wakeup_cause();
|
const auto wakeupCause = esp_sleep_get_wakeup_cause();
|
||||||
const auto resetReason = esp_reset_reason();
|
const auto resetReason = esp_reset_reason();
|
||||||
|
if (isUsbConnected()) {
|
||||||
return isUsbConnected() && (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED) && (resetReason == ESP_RST_UNKNOWN);
|
return wakeupCause == ESP_SLEEP_WAKEUP_GPIO;
|
||||||
|
} else {
|
||||||
|
return (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED) && (resetReason == ESP_RST_POWERON);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@ -347,9 +358,10 @@ void setup() {
|
|||||||
|
|
||||||
SETTINGS.loadFromFile();
|
SETTINGS.loadFromFile();
|
||||||
|
|
||||||
if (!isWakeupAfterFlashing()) {
|
if (isWakeupByPowerButton()) {
|
||||||
// For normal wakeups (not immediately after flashing), verify long press
|
// For normal wakeups, verify power button press duration
|
||||||
verifyWakeupLongPress();
|
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
|
// First serial output only here to avoid timing inconsistencies for power button press duration verification
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user