mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 22:57:50 +03:00
move isWakeupByPowerButton to HAL
This commit is contained in:
parent
5f6d4f208f
commit
a8f8525bc0
@ -43,3 +43,13 @@ bool HalGPIO::isUsbConnected() const {
|
|||||||
// U0RXD/GPIO20 reads HIGH when USB is connected
|
// U0RXD/GPIO20 reads HIGH when USB is connected
|
||||||
return digitalRead(UART0_RXD) == HIGH;
|
return digitalRead(UART0_RXD) == HIGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HalGPIO::isWakeupByPowerButton() const {
|
||||||
|
const auto wakeupCause = esp_sleep_get_wakeup_cause();
|
||||||
|
const auto resetReason = esp_reset_reason();
|
||||||
|
if (isUsbConnected()) {
|
||||||
|
return wakeupCause == ESP_SLEEP_WAKEUP_GPIO;
|
||||||
|
} else {
|
||||||
|
return (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED) && (resetReason == ESP_RST_POWERON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -47,6 +47,9 @@ class HalGPIO {
|
|||||||
// Check if USB is connected
|
// Check if USB is connected
|
||||||
bool isUsbConnected() const;
|
bool isUsbConnected() const;
|
||||||
|
|
||||||
|
// Check if wakeup was caused by power button press
|
||||||
|
bool isWakeupByPowerButton() const;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|||||||
12
src/main.cpp
12
src/main.cpp
@ -266,16 +266,6 @@ void setupDisplayAndFonts() {
|
|||||||
Serial.printf("[%lu] [ ] Fonts setup\n", millis());
|
Serial.printf("[%lu] [ ] Fonts setup\n", millis());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isWakeupByPowerButton() {
|
|
||||||
const auto wakeupCause = esp_sleep_get_wakeup_cause();
|
|
||||||
const auto resetReason = esp_reset_reason();
|
|
||||||
if (gpio.isUsbConnected()) {
|
|
||||||
return wakeupCause == ESP_SLEEP_WAKEUP_GPIO;
|
|
||||||
} else {
|
|
||||||
return (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED) && (resetReason == ESP_RST_POWERON);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
t1 = millis();
|
t1 = millis();
|
||||||
|
|
||||||
@ -304,7 +294,7 @@ void setup() {
|
|||||||
SETTINGS.loadFromFile();
|
SETTINGS.loadFromFile();
|
||||||
KOREADER_STORE.loadFromFile();
|
KOREADER_STORE.loadFromFile();
|
||||||
|
|
||||||
if (isWakeupByPowerButton()) {
|
if (gpio.isWakeupByPowerButton()) {
|
||||||
// For normal wakeups, verify power button press duration
|
// For normal wakeups, verify power button press duration
|
||||||
Serial.printf("[%lu] [ ] Verifying power button press duration\n", millis());
|
Serial.printf("[%lu] [ ] Verifying power button press duration\n", millis());
|
||||||
verifyPowerButtonDuration();
|
verifyPowerButtonDuration();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user