idle: add IDLE_SLEEP_WHEN_CHARGING and IDLE_WAKE_ON_TOUCH
Addresses review feedback on #24: - New config IDLE_SLEEP_WHEN_CHARGING (default false): while USB is plugged in we don't enter sleep and we wake immediately if power comes back. Covers both "I like watching Clawd animations on my plugged-in desk device" and "alternative hardware without a battery is always on USB, sleep would be odd." - New config IDLE_WAKE_ON_TOUCH (default true): a touch on the dark panel wakes the device. The first touch is swallowed (mirrors the button wake-consumption), so tapping a dark screen wakes without also toggling splash<->usage. Set false to keep the original pets/sleeves-safe behaviour where touch is fully ignored while asleep. power.{h,cpp} grow a power_is_vbus_in() helper backed by pmu.isVbusIn() — distinct from isCharging() so the no-battery case ("plugged in, nothing to charge") is detected correctly.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "idle.h"
|
||||
#include "idle_cfg.h"
|
||||
#include "display_cfg.h" // declares `extern Arduino_CO5300 *gfx;`
|
||||
#include "power.h"
|
||||
|
||||
enum IdleState {
|
||||
STATE_AWAKE,
|
||||
@@ -69,6 +70,16 @@ bool idle_is_asleep(void) {
|
||||
void idle_tick(void) {
|
||||
uint32_t now = millis();
|
||||
|
||||
// While on USB power (if configured), don't sleep — and wake from sleep
|
||||
// when power comes back. Treats USB-in as continuous activity.
|
||||
if (!IDLE_SLEEP_WHEN_CHARGING && power_is_vbus_in()) {
|
||||
last_activity_ms = now;
|
||||
if (state == STATE_ASLEEP || state == STATE_FADING_OUT) {
|
||||
begin_fade(DISPLAY_DEFAULT_BRIGHTNESS, now);
|
||||
state = STATE_FADING_IN;
|
||||
}
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case STATE_AWAKE:
|
||||
if (now - last_activity_ms >= IDLE_TIMEOUT_MS) {
|
||||
|
||||
Reference in New Issue
Block a user