ui: keep the button lock in UITask only, not in prefs
This commit is contained in:
1 parent
915b6acc27
commit
8f6140b7d3
5 files changed
+10
-33
No files matched your search
@@ -520,20 +520,6 @@ 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
|
||||
**Usage:**
|
||||
- `set ui.auto_off_delay <delay>`
|
||||
|
||||
@@ -2342,16 +2342,6 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
|
||||
sprintf(reply, "> %s", _prefs.ui_gps_action ? "once" : "toggle");
|
||||
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) {
|
||||
sprintf(reply, "> %d", _prefs.ui_show_clock);
|
||||
return true;
|
||||
|
||||
@@ -97,7 +97,6 @@ public:
|
||||
#else
|
||||
uint8_t ui_gps_action = 0;
|
||||
#endif
|
||||
uint8_t ui_button_lock = 0;
|
||||
#endif
|
||||
|
||||
private:
|
||||
@@ -274,7 +273,6 @@ private:
|
||||
def("off_keep_msgs", _parent->ui_auto_off_keep_msgs);
|
||||
def("nd_name", _parent->ui_nd_name);
|
||||
def("gps_act", _parent->ui_gps_action);
|
||||
def("btn_lock", _parent->ui_button_lock);
|
||||
}
|
||||
public:
|
||||
UI_Prefs(NodePrefs* parent) : _parent(parent) {}
|
||||
|
||||
@@ -214,7 +214,7 @@ class HomeScreen : public UIScreen {
|
||||
|
||||
#if UI_HAS_JOYSTICK
|
||||
// show lock icon left of the other icons when buttons are locked
|
||||
if (_node_prefs->ui_button_lock) {
|
||||
if (_task->isLocked()) {
|
||||
int x = iconX - (charging ? 18 : 9);
|
||||
#ifdef PIN_BUZZER
|
||||
if (_task->isBuzzerQuiet()) x -= 9;
|
||||
@@ -1015,28 +1015,28 @@ void UITask::loop() {
|
||||
char c = 0;
|
||||
#if UI_HAS_JOYSTICK
|
||||
int ev = user_btn.check();
|
||||
if (_node_prefs->ui_button_lock) ev = handleLocked(ev, KEY_ENTER);
|
||||
if (_locked) ev = handleLocked(ev, KEY_ENTER);
|
||||
if (ev == BUTTON_EVENT_CLICK) {
|
||||
c = checkDisplayOn(KEY_ENTER);
|
||||
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
|
||||
c = handleLongPress(KEY_ENTER); // REVISIT: could be mapped to different key code
|
||||
}
|
||||
ev = joystick_left.check();
|
||||
if (_node_prefs->ui_button_lock) ev = handleLocked(ev, KEY_LEFT);
|
||||
if (_locked) ev = handleLocked(ev, KEY_LEFT);
|
||||
if (ev == BUTTON_EVENT_CLICK) {
|
||||
c = checkDisplayOn(KEY_LEFT);
|
||||
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
|
||||
c = handleLongPress(KEY_LEFT);
|
||||
}
|
||||
ev = joystick_right.check();
|
||||
if (_node_prefs->ui_button_lock) ev = handleLocked(ev, KEY_RIGHT);
|
||||
if (_locked) ev = handleLocked(ev, KEY_RIGHT);
|
||||
if (ev == BUTTON_EVENT_CLICK) {
|
||||
c = checkDisplayOn(KEY_RIGHT);
|
||||
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
|
||||
c = handleLongPress(KEY_RIGHT);
|
||||
}
|
||||
ev = back_btn.check();
|
||||
if (_node_prefs->ui_button_lock && ev != BUTTON_EVENT_NONE
|
||||
if (_locked && ev != BUTTON_EVENT_NONE
|
||||
&& ev != BUTTON_EVENT_TRIPLE_CLICK) { // buzzer toggle still works while locked
|
||||
checkDisplayOn(0);
|
||||
if (ev == BUTTON_EVENT_DOUBLE_CLICK) { // unlock needs a joystick press within 3 sec
|
||||
@@ -1280,9 +1280,8 @@ int UITask::handleLocked(int ev, char key) {
|
||||
}
|
||||
|
||||
void UITask::lockButtons(bool lock) {
|
||||
_node_prefs->ui_button_lock = lock;
|
||||
_locked = lock;
|
||||
_unlock_until = 0;
|
||||
the_mesh->savePrefs(); // keep the lock after a reboot
|
||||
checkDisplayOn(0);
|
||||
showAlert(lock ? "Keys locked" : "Unlocked", 800);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ class UITask : public AbstractUITask {
|
||||
unsigned long _analogue_pin_read_millis = millis();
|
||||
#endif
|
||||
#if UI_HAS_JOYSTICK
|
||||
bool _locked = false;
|
||||
unsigned long _unlock_until = 0;
|
||||
#endif
|
||||
|
||||
@@ -113,6 +114,9 @@ public:
|
||||
int getMsgCount() const { return _msgcount; }
|
||||
bool hasDisplay() const { return _display != NULL; }
|
||||
bool isButtonPressed() const;
|
||||
#if UI_HAS_JOYSTICK
|
||||
bool isLocked() const { return _locked; }
|
||||
#endif
|
||||
|
||||
BaseChatMesh* getMesh() const { return the_mesh; }
|
||||
uint32_t getBLEPin() const { return _ble_pin; }
|
||||
|
||||
Reference in new issue
Block a user