From f25268b699e6b2e8fc522d68d6dc140b237250ab Mon Sep 17 00:00:00 2001 From: Alejandro Ramirez <4050651+got-root@users.noreply.github.com> Date: Fri, 13 Mar 2026 15:12:59 -0500 Subject: [PATCH] fix: apply persisted GPS enabled setting on boot for companion radio The companion_radio example was not restoring the GPS enabled/disabled preference from flash after reboot. The preference was being saved correctly when toggled via the mobile app, but on boot, sensors.begin() -> initBasicGPS() unconditionally sets gps_active=false and nothing subsequently restored the persisted state. Added applyGpsPrefs() (matching the pattern in simple_repeater, simple_sensor, and simple_room_server) and call it from main.cpp after sensors.begin() to ensure the GPS hardware is initialized before the saved preference is applied. --- examples/companion_radio/MyMesh.h | 6 ++++++ examples/companion_radio/main.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 4d77b5ab7a..33f3135f89 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -163,6 +163,12 @@ class MyMesh : public BaseChatMesh, public DataStoreHost { public: void savePrefs() { _store->savePrefs(_prefs, sensors.node_lat, sensors.node_lon); } +#if ENV_INCLUDE_GPS == 1 + void applyGpsPrefs() { + sensors.setSettingValue("gps", _prefs.gps_enabled ? "1" : "0"); + } +#endif + private: void writeOKFrame(); void writeErrFrame(uint8_t err_code); diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index eff9efca47..876dc9c33c 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -213,6 +213,10 @@ void setup() { sensors.begin(); +#if ENV_INCLUDE_GPS == 1 + the_mesh.applyGpsPrefs(); +#endif + #ifdef DISPLAY_CLASS ui_task.begin(disp, &sensors, the_mesh.getNodePrefs()); // still want to pass this in as dependency, as prefs might be moved #endif