Add Power::forceScreenOff() for manual screen-off triggers

New public method that transitions to SCREEN_OFF on demand. A
_justWokeFromOff flag is set in activity() and cleared at the end
of loop() so a single keypress that woke the screen can't immediately
re-blank it via a hotkey/long-press handler running in the same tick.

Pure infrastructure — no UI binding included; consumers can wire it
to whatever input event they want (long-press, hotkey, etc.).
This commit is contained in:
drkhsh
2026-04-26 02:50:54 +02:00
parent 9cb5a4f3db
commit a8da0d8918
2 changed files with 17 additions and 0 deletions
+13
View File
@@ -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) {
+4
View File
@@ -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;
};