diff --git a/src/hal/Power.cpp b/src/hal/Power.cpp index 043b90b..e9b2859 100644 --- a/src/hal/Power.cpp +++ b/src/hal/Power.cpp @@ -48,11 +48,22 @@ uint8_t Power::percentToPWM(uint8_t pct) const { void Power::activity() { _lastActivity = millis(); + if (_state == SCREEN_OFF) { + _justWokeFromOff = true; + } if (_state != ACTIVE) { setState(ACTIVE); } } +void Power::forceScreenOff() { + if (_justWokeFromOff) { + _justWokeFromOff = false; + return; + } + setState(SCREEN_OFF); +} + void Power::weakActivity() { _lastActivity = millis(); // Trackball wakes from DIM but not from SCREEN_OFF @@ -96,6 +107,8 @@ void Power::loop() { case SCREEN_OFF: break; } + + _justWokeFromOff = false; } void Power::setState(State newState) { diff --git a/src/hal/Power.h b/src/hal/Power.h index 565dbbf..2eb4740 100644 --- a/src/hal/Power.h +++ b/src/hal/Power.h @@ -15,6 +15,9 @@ public: void activity(); // Weak activity = trackball — wakes from DIM only, not SCREEN_OFF void weakActivity(); + // Manual screen-off; no-op if activity() just woke from SCREEN_OFF this tick + // so a single keypress can't both wake and re-sleep. + void forceScreenOff(); // Battery float batteryVoltage() const; @@ -57,4 +60,5 @@ private: static constexpr uint8_t DIM_PWM = 40; // ~15% PWM when dimmed bool _kbAutoOn = false; bool _kbAutoOff = false; + bool _justWokeFromOff = false; };