Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions examples/companion_radio/ui-new/UITask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion examples/companion_radio/ui-new/UITask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/companion_radio/ui-new/icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Loading