ui: lock joystick with a Menu double-click

This commit is contained in:
quyenlt298 committed 2026-11-24 22:18:12 +07:00
1 parent f6cbc11c85
commit 03c92712b1
6 files changed
+90 -1

No files matched your search

+14
View File
@@ -520,6 +520,20 @@ Radio parameters are common to all roles and handled by `CommonRadioPrefs`.
--- ---
#### Button lock
**Usage:**
- `set ui.button_lock <state>`
- `get ui.button_lock`
**Parameters:**
- `state`: `1` (locked) or `0` (unlocked)
**Default:** `0`
**Note:** Only on boards with a joystick (e.g. Wio Tracker L1). Double-click the Menu button to lock, so the joystick can't be pressed by mistake in a pocket. While locked, a lock icon is shown and the joystick is ignored. To unlock, double-click Menu then press the joystick within 3 seconds. The lock is kept when the screen turns off and after a reboot.
---
#### Auto-off screen #### Auto-off screen
**Usage:** **Usage:**
- `set ui.auto_off_delay <delay>` - `set ui.auto_off_delay <delay>`
+10
View File
@@ -2342,6 +2342,16 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
sprintf(reply, "> %s", _prefs.ui_gps_action ? "once" : "toggle"); sprintf(reply, "> %s", _prefs.ui_gps_action ? "once" : "toggle");
return true; return true;
} }
if (memcmp(command, "set ui.button_lock", 18) == 0) {
_prefs.ui_button_lock = atoi(&command[18]) ? 1 : 0;
savePrefs();
sprintf(reply, "> now %d", _prefs.ui_button_lock);
return true;
}
if (memcmp(command, "get ui.button_lock", 18) == 0) {
sprintf(reply, "> %d", _prefs.ui_button_lock);
return true;
}
if (memcmp(command, "get ui.show_clock", 17) == 0) { if (memcmp(command, "get ui.show_clock", 17) == 0) {
sprintf(reply, "> %d", _prefs.ui_show_clock); sprintf(reply, "> %d", _prefs.ui_show_clock);
return true; return true;
+2
View File
@@ -97,6 +97,7 @@ public:
#else #else
uint8_t ui_gps_action = 0; uint8_t ui_gps_action = 0;
#endif #endif
uint8_t ui_button_lock = 0;
#endif #endif
private: private:
@@ -273,6 +274,7 @@ private:
def("off_keep_msgs", _parent->ui_auto_off_keep_msgs); def("off_keep_msgs", _parent->ui_auto_off_keep_msgs);
def("nd_name", _parent->ui_nd_name); def("nd_name", _parent->ui_nd_name);
def("gps_act", _parent->ui_gps_action); def("gps_act", _parent->ui_gps_action);
def("btn_lock", _parent->ui_button_lock);
} }
public: public:
UI_Prefs(NodePrefs* parent) : _parent(parent) {} UI_Prefs(NodePrefs* parent) : _parent(parent) {}
+52 -1
View File
@@ -211,6 +211,18 @@ class HomeScreen : public UIScreen {
display.drawXbm(iconX - (charging ? 18 : 9), iconY + 1, muted_icon, 8, 8); display.drawXbm(iconX - (charging ? 18 : 9), iconY + 1, muted_icon, 8, 8);
} }
#endif #endif
#if UI_HAS_JOYSTICK
// show lock icon left of the other icons when buttons are locked
if (_node_prefs->ui_button_lock) {
int x = iconX - (charging ? 18 : 9);
#ifdef PIN_BUZZER
if (_task->isBuzzerQuiet()) x -= 9;
#endif
display.setColor(UIColor::title_txt);
display.drawXbm(x, iconY + 1, lock_icon, 8, 8);
}
#endif
} }
CayenneLPP sensors_lpp; CayenneLPP sensors_lpp;
@@ -1003,25 +1015,38 @@ void UITask::loop() {
char c = 0; char c = 0;
#if UI_HAS_JOYSTICK #if UI_HAS_JOYSTICK
int ev = user_btn.check(); int ev = user_btn.check();
if (_node_prefs->ui_button_lock) ev = handleLocked(ev, KEY_ENTER);
if (ev == BUTTON_EVENT_CLICK) { if (ev == BUTTON_EVENT_CLICK) {
c = checkDisplayOn(KEY_ENTER); c = checkDisplayOn(KEY_ENTER);
} else if (ev == BUTTON_EVENT_LONG_PRESS) { } else if (ev == BUTTON_EVENT_LONG_PRESS) {
c = handleLongPress(KEY_ENTER); // REVISIT: could be mapped to different key code c = handleLongPress(KEY_ENTER); // REVISIT: could be mapped to different key code
} }
ev = joystick_left.check(); ev = joystick_left.check();
if (_node_prefs->ui_button_lock) ev = handleLocked(ev, KEY_LEFT);
if (ev == BUTTON_EVENT_CLICK) { if (ev == BUTTON_EVENT_CLICK) {
c = checkDisplayOn(KEY_LEFT); c = checkDisplayOn(KEY_LEFT);
} else if (ev == BUTTON_EVENT_LONG_PRESS) { } else if (ev == BUTTON_EVENT_LONG_PRESS) {
c = handleLongPress(KEY_LEFT); c = handleLongPress(KEY_LEFT);
} }
ev = joystick_right.check(); ev = joystick_right.check();
if (_node_prefs->ui_button_lock) ev = handleLocked(ev, KEY_RIGHT);
if (ev == BUTTON_EVENT_CLICK) { if (ev == BUTTON_EVENT_CLICK) {
c = checkDisplayOn(KEY_RIGHT); c = checkDisplayOn(KEY_RIGHT);
} else if (ev == BUTTON_EVENT_LONG_PRESS) { } else if (ev == BUTTON_EVENT_LONG_PRESS) {
c = handleLongPress(KEY_RIGHT); c = handleLongPress(KEY_RIGHT);
} }
ev = back_btn.check(); ev = back_btn.check();
if (ev == BUTTON_EVENT_TRIPLE_CLICK) { if (_node_prefs->ui_button_lock && ev != BUTTON_EVENT_NONE) {
checkDisplayOn(0);
if (ev == BUTTON_EVENT_DOUBLE_CLICK) { // unlock needs a joystick press within 3 sec
_unlock_until = millis() + 3000;
showAlert("Now press joystick", 3000);
} else {
showAlert("Locked: Menu x2", 1200);
}
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
lockButtons(true);
} else if (ev == BUTTON_EVENT_TRIPLE_CLICK) {
c = handleTripleClick(KEY_SELECT); c = handleTripleClick(KEY_SELECT);
} }
#elif defined(PIN_USER_BTN) #elif defined(PIN_USER_BTN)
@@ -1236,6 +1261,32 @@ char UITask::handleTripleClick(char c) {
return c; return c;
} }
#if UI_HAS_JOYSTICK
// buttons locked: ignore the joystick, except a press just after Menu double-click (unlock)
int UITask::handleLocked(int ev, char key) {
if (ev == BUTTON_EVENT_NONE) return ev;
if (ev == BUTTON_EVENT_LONG_PRESS && millis() - ui_started_at < 8000) return ev; // keep CLI/rescue
if (_display != NULL && _display->isOn()) { // if screen is off, leave it off
if (key == KEY_ENTER && ev == BUTTON_EVENT_CLICK && millis() < _unlock_until) {
lockButtons(false);
} else {
checkDisplayOn(0);
showAlert("Locked: Menu x2", 1200);
}
}
return BUTTON_EVENT_NONE;
}
void UITask::lockButtons(bool lock) {
_node_prefs->ui_button_lock = lock;
_unlock_until = 0;
the_mesh->savePrefs(); // keep the lock after a reboot
checkDisplayOn(0);
showAlert(lock ? "Keys locked" : "Unlocked", 800);
}
#endif
bool UITask::getGPSState() { bool UITask::getGPSState() {
if (_sensors != NULL) { if (_sensors != NULL) {
int num = _sensors->getNumSettings(); int num = _sensors->getNumSettings();
+7
View File
@@ -75,6 +75,9 @@ class UITask : public AbstractUITask {
#ifdef PIN_USER_BTN_ANA #ifdef PIN_USER_BTN_ANA
unsigned long _analogue_pin_read_millis = millis(); unsigned long _analogue_pin_read_millis = millis();
#endif #endif
#if UI_HAS_JOYSTICK
unsigned long _unlock_until = 0;
#endif
UIScreen* splash; UIScreen* splash;
UIScreen* home; UIScreen* home;
@@ -88,6 +91,10 @@ class UITask : public AbstractUITask {
char handleLongPress(char c); char handleLongPress(char c);
char handleDoubleClick(char c); char handleDoubleClick(char c);
char handleTripleClick(char c); char handleTripleClick(char c);
#if UI_HAS_JOYSTICK
int handleLocked(int ev, char key);
void lockButtons(bool lock);
#endif
void setCurrScreen(UIScreen* c); void setCurrScreen(UIScreen* c);
+5
View File
@@ -121,6 +121,11 @@ static const uint8_t muted_icon[] = {
0x20, 0x6a, 0xea, 0xe4, 0xe4, 0xea, 0x6a, 0x20 0x20, 0x6a, 0xea, 0xe4, 0xe4, 0xea, 0x6a, 0x20
}; };
// small padlock, 8x8px, shown while the buttons are locked
static const uint8_t lock_icon[] = {
0x3c, 0x42, 0x42, 0xff, 0xff, 0xe7, 0xff, 0xff
};
// small lightning bolt, 8x8px, shown next to the battery icon while charging // small lightning bolt, 8x8px, shown next to the battery icon while charging
static const uint8_t charging_icon[] = { static const uint8_t charging_icon[] = {
0x18, 0x30, 0x60, 0xFC, 0x18, 0x30, 0x60, 0xC0 0x18, 0x30, 0x60, 0xFC, 0x18, 0x30, 0x60, 0xC0