Skip to content

Commit 82dd6db

Browse files
committed
Switch bluetooth radio type at menu exit
Avoids multiple radio switching.
1 parent 31a3069 commit 82dd6db

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

Firmware/RTK_Everywhere/menuSystem.ino

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Display current system status
22
void menuSystem()
33
{
4+
BluetoothRadioType_e bluetoothUserChoice = settings.bluetoothRadioType;
5+
46
while (1)
57
{
68
systemPrintln();
@@ -180,11 +182,11 @@ void menuSystem()
180182
}
181183

182184
systemPrint("b) Set Bluetooth Mode: ");
183-
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE)
185+
if (bluetoothUserChoice == BLUETOOTH_RADIO_SPP_AND_BLE)
184186
systemPrintln("Dual");
185-
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP)
187+
else if (bluetoothUserChoice == BLUETOOTH_RADIO_SPP)
186188
systemPrintln("Classic");
187-
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
189+
else if (bluetoothUserChoice == BLUETOOTH_RADIO_BLE)
188190
systemPrintln("BLE");
189191
else
190192
systemPrintln("Off");
@@ -243,16 +245,14 @@ void menuSystem()
243245
else if (incoming == 'b')
244246
{
245247
// Change Bluetooth protocol
246-
bluetoothStop();
247-
if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_AND_BLE)
248-
settings.bluetoothRadioType = BLUETOOTH_RADIO_SPP;
249-
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP)
250-
settings.bluetoothRadioType = BLUETOOTH_RADIO_BLE;
251-
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
252-
settings.bluetoothRadioType = BLUETOOTH_RADIO_OFF;
253-
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_OFF)
254-
settings.bluetoothRadioType = BLUETOOTH_RADIO_SPP_AND_BLE;
255-
bluetoothStart();
248+
if (bluetoothUserChoice == BLUETOOTH_RADIO_SPP_AND_BLE)
249+
bluetoothUserChoice = BLUETOOTH_RADIO_SPP;
250+
else if (bluetoothUserChoice == BLUETOOTH_RADIO_SPP)
251+
bluetoothUserChoice = BLUETOOTH_RADIO_BLE;
252+
else if (bluetoothUserChoice == BLUETOOTH_RADIO_BLE)
253+
bluetoothUserChoice = BLUETOOTH_RADIO_OFF;
254+
else if (bluetoothUserChoice == BLUETOOTH_RADIO_OFF)
255+
bluetoothUserChoice = BLUETOOTH_RADIO_SPP_AND_BLE;
256256
}
257257
else if ((incoming == 'c') &&
258258
(present.fuelgauge_max17048 || present.fuelgauge_bq40z50 || present.charger_mp2762a))
@@ -382,6 +382,14 @@ void menuSystem()
382382
printUnknown(incoming);
383383
}
384384

385+
// Restart Bluetooth radio if settings have changed
386+
if (bluetoothUserChoice != settings.bluetoothRadioType)
387+
{
388+
bluetoothStop();
389+
settings.bluetoothRadioType = bluetoothUserChoice;
390+
bluetoothStart();
391+
}
392+
385393
clearBuffer(); // Empty buffer of any newline chars
386394
}
387395

0 commit comments

Comments
 (0)