mirror of
https://github.com/ratspeak/ratdeck.git
synced 2026-08-05 18:39:26 +00:00
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:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user