diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 94a8ee3ef..b53b18b0c 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -132,11 +132,19 @@ class HomeScreen : public UIScreen { int fillWidth = (batteryPercentage * (iconWidth - 4)) / 100; display.fillRect(iconX + 2, iconY + 2, fillWidth, iconHeight - 4); + int statusIconX = iconX - 9; + + if (_task->isScreenLocked()) { + display.setColor(DisplayDriver::YELLOW); + display.drawXbm(statusIconX, iconY + 1, lock_icon, 8, 8); + statusIconX -= 9; + } + // show muted icon if buzzer is muted #ifdef PIN_BUZZER if (_task->isBuzzerQuiet()) { display.setColor(DisplayDriver::RED); - display.drawXbm(iconX - 9, iconY + 1, muted_icon, 8, 8); + display.drawXbm(statusIconX, iconY + 1, muted_icon, 8, 8); } #endif } @@ -575,6 +583,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no ui_started_at = millis(); _alert_expiry = 0; + _screen_locked = false; splash = new SplashScreen(this); home = new HomeScreen(this, &rtc_clock, sensors, node_prefs); @@ -767,9 +776,17 @@ void UITask::loop() { #endif if (c != 0 && curr) { - curr->handleInput(c); - _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer - _next_refresh = 100; // trigger refresh + if (_screen_locked) { + // Always show the lock alert when input is attempted on a locked screen. + // This ensures the user immediately sees that the screen is locked, + // even if a previous alert is still active. + showAlert("Locked, long press", 2000); + _next_refresh = 100; + } else { + curr->handleInput(c); + _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer + _next_refresh = 100; // trigger refresh + } } userLedHandler(); @@ -849,9 +866,21 @@ char UITask::checkDisplayOn(char c) { } char UITask::handleLongPress(char c) { + if (_screen_locked) { + _screen_locked = false; + showAlert("Screen unlocked.", 1000); + _next_refresh = 0; + return 0; // consume unlock gesture + } + if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue the_mesh.enterCLIRescue(); c = 0; // consume event + } else { + _screen_locked = true; + showAlert("Locked, long press", 2000); + _next_refresh = 0; + c = 0; // consume lock gesture } return c; } @@ -863,6 +892,12 @@ char UITask::handleDoubleClick(char c) { } char UITask::handleTripleClick(char c) { + if (_screen_locked) { + showAlert("Locked, long press", 2000); + _next_refresh = 100; + return 0; + } + MESH_DEBUG_PRINTLN("UITask: triple click triggered"); checkDisplayOn(c); toggleBuzzer(); diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index a77ad6e7e..d56ddfb25 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -35,6 +35,8 @@ class UITask : public AbstractUITask { NodePrefs* _node_prefs; char _alert[80]; unsigned long _alert_expiry; + // Flag indicating whether the screen is locked to prevent accidental input + bool _screen_locked; int _msgcount; unsigned long ui_started_at, next_batt_chck; int next_backlight_btn_check = 0; @@ -65,7 +67,8 @@ class UITask : public AbstractUITask { public: - UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) { + UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL), + _screen_locked(false) { next_batt_chck = _next_refresh = 0; ui_started_at = 0; curr = NULL; @@ -77,6 +80,7 @@ class UITask : public AbstractUITask { int getMsgCount() const { return _msgcount; } bool hasDisplay() const { return _display != NULL; } bool isButtonPressed() const; + bool isScreenLocked() const { return _screen_locked; } bool isBuzzerQuiet() { #ifdef PIN_BUZZER diff --git a/examples/companion_radio/ui-new/icons.h b/examples/companion_radio/ui-new/icons.h index cbe237902..a17824c60 100644 --- a/examples/companion_radio/ui-new/icons.h +++ b/examples/companion_radio/ui-new/icons.h @@ -119,4 +119,8 @@ static const uint8_t advert_icon[] = { static const uint8_t muted_icon[] = { 0x20, 0x6a, 0xea, 0xe4, 0xe4, 0xea, 0x6a, 0x20 +}; + +static const uint8_t lock_icon[] = { + 0x3c, 0x66, 0x66, 0xff, 0xdb, 0xc3, 0xc3, 0xff }; \ No newline at end of file