From a8da0d8918e21093df81656542fd5dc882d7d243 Mon Sep 17 00:00:00 2001 From: drkhsh Date: Sun, 26 Apr 2026 02:37:11 +0200 Subject: [PATCH] Add Power::forceScreenOff() for manual screen-off triggers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.). --- src/hal/Power.cpp | 13 +++++++++++++ src/hal/Power.h | 4 ++++ 2 files changed, 17 insertions(+) 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; };