Skip to content

Commit

Permalink
Move nullptr callbacks after end
Browse files Browse the repository at this point in the history
Callbacks do need to be set to nullptr but only after the radio isn't at risk of calling callback. Unregister all callbacks incase a different radio type is started.
  • Loading branch information
nseidle committed Jul 22, 2024
1 parent c142ce8 commit 31a3069
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Firmware/RTK_Everywhere/Bluetooth.ino
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ void bluetoothStart()
// }

// This function stops BT so that it can be restarted later
// It also releases as many system resources as possible so that WiFi/caster is more stable
void bluetoothStop()
{
#ifdef COMPILE_BT
Expand All @@ -438,22 +437,26 @@ void bluetoothStop()
bluetoothSerialBle->flush(); // Complete any transfers
bluetoothSerialBle->disconnect(); // Drop any clients
bluetoothSerialBle->end(); // Release resources
bluetoothSerialBle->register_callback(nullptr);

bluetoothSerialSpp->flush(); // Complete any transfers
bluetoothSerialSpp->disconnect(); // Drop any clients
bluetoothSerialSpp->end(); // Release resources
bluetoothSerialSpp->register_callback(nullptr);
}
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP)
{
bluetoothSerialSpp->flush(); // Complete any transfers
bluetoothSerialSpp->disconnect(); // Drop any clients
bluetoothSerialSpp->end(); // Release resources
bluetoothSerialSpp->register_callback(nullptr);
}
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
{
bluetoothSerialBle->flush(); // Complete any transfers
bluetoothSerialBle->disconnect(); // Drop any clients
bluetoothSerialBle->end(); // Release resources
bluetoothSerialBle->register_callback(nullptr);
}

log_d("Bluetooth turned off");
Expand Down

0 comments on commit 31a3069

Please sign in to comment.