Long-press trackball blanks screen; suppress touch wakes when off

Two pocket-carry quality-of-life additions:

1. Long-press (1.2s) trackball click blanks the screen if no LVGL
   screen consumes the long-press. InputManager captures the power
   state at click DOWN (_clickFromScreenOn) and only emits the
   long-press if the screen was already on, so a long-press from
   SCREEN_OFF wakes without immediately re-blanking.

2. Touch events are ignored entirely while screen is off, preventing
   accidental wakes from pressure on the panel in a pocket/bag.
   Trackball click and keyboard keys still wake normally.

InputManager now holds a Power* injected via setPowerMgr() in setup.
This commit is contained in:
drkhsh
2026-04-26 02:50:54 +02:00
parent a8da0d8918
commit ef5d8ea189
3 changed files with 20 additions and 6 deletions
+11 -4
View File
@@ -85,11 +85,16 @@ void InputManager::update() {
_clickPending = true;
_longPressFired = false;
_clickStartMs = millis();
// Capture screen state BEFORE activity wakes it, so long-press
// doesn't blank a freshly-woken screen (wake-then-blank ping-pong)
_clickFromScreenOn = _powerMgr ? _powerMgr->isScreenOn() : true;
_activity = true;
_strongActivity = true; // Click wakes from screen off
} else if (!_longPressFired && millis() - _clickStartMs >= LONG_PRESS_MS) {
// Long press threshold reached
_longPress = true;
// Long press threshold reached — only emit if click started screen-on
if (_clickFromScreenOn) {
_longPress = true;
}
_longPressFired = true;
_hasKey = false; // Suppress any concurrent events
_activity = true;
@@ -117,8 +122,10 @@ void InputManager::update() {
}
}
// Touch activity check — throttled to ~50Hz
if (_touch) {
// Touch activity check — throttled to ~50Hz.
// Suppressed while screen is off (pocket-carry safety: prevents
// accidental wakes from pressure on the touch panel).
if (_touch && (!_powerMgr || _powerMgr->isScreenOn())) {
unsigned long now = millis();
if (now - _lastTouchPoll >= TOUCH_POLL_MS) {
_lastTouchPoll = now;
+4
View File
@@ -3,10 +3,12 @@
#include "hal/Keyboard.h"
#include "hal/Trackball.h"
#include "hal/TouchInput.h"
#include "hal/Power.h"
class InputManager {
public:
void begin(Keyboard* kb, Trackball* tb, TouchInput* touch);
void setPowerMgr(Power* pm) { _powerMgr = pm; }
void update();
// Keyboard events
@@ -26,6 +28,7 @@ private:
Keyboard* _kb = nullptr;
Trackball* _tb = nullptr;
TouchInput* _touch = nullptr;
Power* _powerMgr = nullptr;
bool _hasKey = false;
KeyEvent _keyEvent;
@@ -34,6 +37,7 @@ private:
bool _longPress = false;
bool _clickPending = false;
bool _longPressFired = false;
bool _clickFromScreenOn = true; // Captured at click DOWN to gate long-press
unsigned long _clickStartMs = 0;
unsigned long _lastClickDownMs = 0;
static constexpr unsigned long LONG_PRESS_MS = 1200;
+5 -2
View File
@@ -435,6 +435,7 @@ void setup() {
// Step 10: Input manager
inputManager.begin(&keyboard, &trackball, &touch);
inputManager.setPowerMgr(&powerMgr);
// Step 10.5: LVGL input drivers
LvInput::init(&keyboard, &trackball, &touch);
@@ -933,9 +934,11 @@ void loop() {
powerMgr.weakActivity(); // Trackball: wake from dim only
}
// 2. Long-press dispatch
// 2. Long-press dispatch — screen blanking is the default if no screen consumes it
if (inputManager.hadLongPress()) {
ui.handleLongPress();
if (!ui.handleLongPress()) {
powerMgr.forceScreenOff();
}
}
// 3. Key event dispatch