mirror of
https://github.com/correl/m5paper.git
synced 2024-12-27 20:06:24 +00:00
Use light sleep to save battery in tracker
This commit is contained in:
parent
971e8cf30e
commit
b4273f4bdf
1 changed files with 17 additions and 0 deletions
17
src/main.cpp
17
src/main.cpp
|
@ -350,6 +350,7 @@ public:
|
|||
}
|
||||
|
||||
M5.Display.endWrite();
|
||||
sleep();
|
||||
}
|
||||
|
||||
App::Choices loop () {
|
||||
|
@ -387,9 +388,25 @@ public:
|
|||
next_clock_update = next_minute(current_time);
|
||||
drawClock(current_time);
|
||||
drawBattery();
|
||||
} else {
|
||||
sleep();
|
||||
}
|
||||
return App::LifeTracker;
|
||||
}
|
||||
|
||||
void sleep() {
|
||||
const time_t current_time = time(nullptr);
|
||||
if (current_time >= next_clock_update) return;
|
||||
|
||||
int seconds = next_clock_update - current_time;
|
||||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_36, LOW); // Wake on touch
|
||||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_37, LOW); // Wake on button up
|
||||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_38, LOW); // Wake on button middle
|
||||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_39, LOW); // Wake on button down
|
||||
esp_sleep_enable_timer_wakeup(seconds * 1000); // Wake up at the next clock update (in microseconds)
|
||||
esp_light_sleep_start();
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
delete players[i];
|
||||
|
|
Loading…
Reference in a new issue