NRF52 bluetooth cleanup and fix (#3328)
* NRF52 bluetooth cleanup. Fixes BLE not returning after serial PhoneAPI connection * Use new var name in esp32 arch
This commit is contained in:
@@ -210,8 +210,10 @@ void NRF52Bluetooth::shutdown()
|
||||
{
|
||||
// Shutdown bluetooth for minimum power draw
|
||||
LOG_INFO("Disable NRF52 bluetooth\n");
|
||||
if (connectionHandle != 0) {
|
||||
Bluefruit.disconnect(connectionHandle);
|
||||
}
|
||||
Bluefruit.Advertising.stop();
|
||||
Bluefruit.setTxPower(0); // Minimum power
|
||||
}
|
||||
|
||||
bool NRF52Bluetooth::isConnected()
|
||||
@@ -289,6 +291,14 @@ void NRF52Bluetooth::setup()
|
||||
}
|
||||
}
|
||||
|
||||
void NRF52Bluetooth::resumeAdverising()
|
||||
{
|
||||
Bluefruit.Advertising.restartOnDisconnect(true);
|
||||
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
||||
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||
Bluefruit.Advertising.start(0);
|
||||
}
|
||||
|
||||
/// Given a level between 0-100, update the BLE attribute
|
||||
void updateBatteryLevel(uint8_t level)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ class NRF52Bluetooth : BluetoothApi
|
||||
public:
|
||||
void setup();
|
||||
void shutdown();
|
||||
void resumeAdverising();
|
||||
void clearBonds();
|
||||
bool isConnected();
|
||||
int getRssi();
|
||||
@@ -17,4 +18,4 @@ class NRF52Bluetooth : BluetoothApi
|
||||
void convertToUint8(uint8_t target[4], uint32_t source);
|
||||
static bool onPairingPasskey(uint16_t conn_handle, uint8_t const passkey[6], bool match_request);
|
||||
static void onPairingCompleted(uint16_t conn_handle, uint8_t auth_status);
|
||||
};
|
||||
};
|
||||
@@ -63,28 +63,29 @@ static void initBrownout()
|
||||
// We don't bother with setting up brownout if soft device is disabled - because during production we always use softdevice
|
||||
}
|
||||
|
||||
static bool bleOn = false;
|
||||
static const bool useSoftDevice = true; // Set to false for easier debugging
|
||||
|
||||
void setBluetoothEnable(bool on)
|
||||
void setBluetoothEnable(bool enable)
|
||||
{
|
||||
if (on != bleOn && config.bluetooth.enabled == true) {
|
||||
if (on) {
|
||||
if (enable && config.bluetooth.enabled) {
|
||||
if (!useSoftDevice) {
|
||||
LOG_INFO("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
||||
} else {
|
||||
if (!nrf52Bluetooth) {
|
||||
if (!useSoftDevice)
|
||||
LOG_INFO("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
||||
else {
|
||||
nrf52Bluetooth = new NRF52Bluetooth();
|
||||
nrf52Bluetooth->setup();
|
||||
LOG_DEBUG("Initializing NRF52 Bluetooth\n");
|
||||
nrf52Bluetooth = new NRF52Bluetooth();
|
||||
nrf52Bluetooth->setup();
|
||||
|
||||
// We delay brownout init until after BLE because BLE starts soft device
|
||||
initBrownout();
|
||||
}
|
||||
// We delay brownout init until after BLE because BLE starts soft device
|
||||
initBrownout();
|
||||
} else {
|
||||
nrf52Bluetooth->resumeAdverising();
|
||||
}
|
||||
} else if (nrf52Bluetooth) {
|
||||
}
|
||||
} else {
|
||||
if (nrf52Bluetooth) {
|
||||
nrf52Bluetooth->shutdown();
|
||||
}
|
||||
bleOn = on;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user