diff --git a/examples/companion_radio/AbstractUITask.h b/examples/companion_radio/AbstractUITask.h index 3871f050..4e32fb23 100644 --- a/examples/companion_radio/AbstractUITask.h +++ b/examples/companion_radio/AbstractUITask.h @@ -64,8 +64,8 @@ public: bool isClientConnected() const { return _serial->isClientConnected(); } uint16_t getBattMilliVolts() const { return _board->getBattMilliVolts(); } bool isSerialEnabled() const { return _serial->isEnabled(); } - void enableSerial() { _serial->enable(); } - void disableSerial() { _serial->disable(); } + void enableSerial() { _serial->enable(); the_mesh.rememberBle(true); } + void disableSerial() { _serial->disable(); the_mesh.rememberBle(false); } virtual void notify(UIEventType t = UIEventType::none) = 0; // Single choke point for every controlled power-down (low-battery auto-off, // long-press power-off, and every board.reboot() caller too): flush diff --git a/examples/companion_radio/DataStore.cpp b/examples/companion_radio/DataStore.cpp index 7367469b..3e8925d7 100644 --- a/examples/companion_radio/DataStore.cpp +++ b/examples/companion_radio/DataStore.cpp @@ -332,6 +332,7 @@ static void sanitize(NodePrefs& p) { if (p.quiet_to > 23) p.quiet_to = 7; if (!battery::validCurve(p.batt_curve_mv)) memset(p.batt_curve_mv, 0, sizeof(p.batt_curve_mv)); flag(p.lock_compact, 0); + flag(p.ble_off, 0); } // The settings a firmware before 2.0 kept in /new_prefs that still matter diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index d3b2c37d..f9469d27 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -2047,7 +2047,7 @@ bool MyMesh::isValidClientRepeatFreq(uint32_t f) const { void MyMesh::startInterface(BaseSerialInterface &serial) { _serial = &serial; - serial.enable(); + if (!_prefs.ble_off) serial.enable(); } static bool isAllZero(const uint8_t* buf, size_t n) { diff --git a/examples/companion_radio/MyMesh.h b/examples/companion_radio/MyMesh.h index 94bfc09a..11ea8fb2 100644 --- a/examples/companion_radio/MyMesh.h +++ b/examples/companion_radio/MyMesh.h @@ -414,6 +414,12 @@ public: } void savePrefs() { _store->savePrefs(_prefs, sensors.node_lat, sensors.node_lon); } + // Bluetooth on/off as the user left it (NodePrefs::ble_off), kept over reboots. + void rememberBle(bool on) { + if (_prefs.ble_off == (on ? 0 : 1)) return; + _prefs.ble_off = on ? 0 : 1; + savePrefs(); + } void saveRTCTime() { _store->saveRTCTime(); } // Contact updates (new adverts, path/lastmod changes) are lazily debounced // (see dirty_contacts_expiry) to avoid wearing flash on every packet -- diff --git a/examples/companion_radio/NodePrefs.h b/examples/companion_radio/NodePrefs.h index 1622da15..b9e3d72d 100644 --- a/examples/companion_radio/NodePrefs.h +++ b/examples/companion_radio/NodePrefs.h @@ -520,6 +520,11 @@ struct NodePrefs { // persisted to file // clock fields as rows below. The L2 has its own lock screen. uint8_t lock_compact; + // ── Bluetooth ────────────────────────────────────────────────────────── + // 1 = the user switched Bluetooth off: it stays off after a reboot or + // hibernate (MyMesh::startInterface). USB keeps working either way. + uint8_t ble_off; + // Single source of truth for the live-share option tables (shared by the Map // UI labels and the auto-send engine in UITask). static const uint8_t LOC_SHARE_MOVE_COUNT = 4;