diff --git a/src/input/InputManager.cpp b/src/input/InputManager.cpp index 5c659b3..aa7a103 100644 --- a/src/input/InputManager.cpp +++ b/src/input/InputManager.cpp @@ -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; diff --git a/src/input/InputManager.h b/src/input/InputManager.h index 341bc8e..923c6b3 100644 --- a/src/input/InputManager.h +++ b/src/input/InputManager.h @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 1e883a6..c1cd567 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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