From b2e46335e5d97c12d1e7c957404e34723ee548f6 Mon Sep 17 00:00:00 2001 From: Florent Date: Sat, 7 Nov 2026 18:41:52 -0400 Subject: [PATCH] ui_task: let user choose if enter in gps screen toggles or triggers gps --- docs/companion_cli.md | 14 ++++++++++++++ examples/companion_radio/MyMesh.cpp | 12 ++++++++++++ examples/companion_radio/NodePrefs.h | 6 ++++++ examples/companion_radio/ui-new/UITask.cpp | 11 ++++++++++- examples/companion_radio/ui-new/UITask.h | 1 + 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/companion_cli.md b/docs/companion_cli.md index eecc5f82..6366d2a4 100644 --- a/docs/companion_cli.md +++ b/docs/companion_cli.md @@ -452,6 +452,20 @@ Radio parameters are common to all roles and handled by `CommonRadioPrefs`. --- +#### GPS key action +**Usage:** +- `set ui.gps_action ` +- `get ui.gps_action` + +**Parameters:** +- `action`: `toggle` (or `0`) to switch the GPS on and off, `once` (or `trigger`, `1`) to acquire a fix on demand, as `gps once` + +**Default:** `toggle`, or `once` on boards with a GPS switch + +**Note:** Only used by the `ui-new` screens for now. + +--- + #### Node discovery screen shows nodes names **Usage:** - `set ui.nd_name ` diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index d12c7b8a..e3ec01f3 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -2291,6 +2291,18 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* sprintf(reply, "> ui.nd_name is now %d", _prefs.ui_nd_name); return true; } + if (memcmp(command, "set ui.gps_action", 17) == 0) { + const char* v = &command[17]; + while (*v == ' ') v++; + _prefs.ui_gps_action = (memcmp(v, "once", 4) == 0 || memcmp(v, "trigger", 7) == 0 || *v == '1') ? 1 : 0; // anything else: toggle + savePrefs(); + sprintf(reply, "> now %s", _prefs.ui_gps_action ? "once" : "toggle"); + return true; + } + if (memcmp(command, "get ui.gps_action", 17) == 0) { + sprintf(reply, "> %s", _prefs.ui_gps_action ? "once" : "toggle"); + return true; + } if (memcmp(command, "get ui.show_clock", 17) == 0) { sprintf(reply, "> %d", _prefs.ui_show_clock); return true; diff --git a/examples/companion_radio/NodePrefs.h b/examples/companion_radio/NodePrefs.h index a54eca75..db019370 100644 --- a/examples/companion_radio/NodePrefs.h +++ b/examples/companion_radio/NodePrefs.h @@ -87,6 +87,11 @@ public: uint8_t ui_auto_off_keep_msgs = 1; uint8_t ui_max_partial = EINK_MAX_PARTIAL_REFRESH; uint8_t ui_nd_name = 1; +#ifdef PIN_GPS_SWITCH + uint8_t ui_gps_action = 1; +#else + uint8_t ui_gps_action = 0; +#endif #endif private: @@ -238,6 +243,7 @@ private: def("off_blank", _parent->ui_auto_off_blank); def("off_keep_msgs", _parent->ui_auto_off_keep_msgs); def("nd_name", _parent->ui_nd_name); + def("gps_act", _parent->ui_gps_action); } public: UI_Prefs(NodePrefs* parent) : _parent(parent) {} diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 6b6af33e..ee225341 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -632,7 +632,7 @@ public: } #if ENV_INCLUDE_GPS == 1 if (c == KEY_ENTER && _page == HomePage::GPS) { - _task->toggleGPS(); + if (_node_prefs->ui_gps_action == 1) _task->triggerGPS(); else _task->toggleGPS(); return true; } #endif @@ -1232,6 +1232,15 @@ void UITask::toggleGPS() { } } +void UITask::triggerGPS() { + LocationProvider* location = _sensors != NULL ? _sensors->getLocationProvider() : NULL; + if (location != NULL && !(location->hasHardwareEnableState() && !location->isHardwareEnabled()) + && location->startOnce()) { + notify(UIEventType::ack); + } + _next_refresh = 0; +} + void UITask::toggleBuzzer() { // Toggle buzzer quiet mode #ifdef PIN_BUZZER diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index 61831488..045b1060 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -114,6 +114,7 @@ public: void toggleBuzzer(); bool getGPSState(); void toggleGPS(); + void triggerGPS(); // MyMesh::Listener void onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, const char* text) override;