diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 5367293f22..400aabc676 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -195,6 +195,17 @@ static void lsExit() t5BacklightWakeFromSleep(); } +/// Skip the BLE re-enable while a reboot/shutdown is armed: AdminModule tears BLE down before +/// scheduling the restart, and a state transition in that window would otherwise bring it back up. +static void setBluetoothEnableUnlessRestarting() +{ + if (rebootAtMsec || shutdownAtMsec) { + LOG_POWERFSM("Skip BLE enable, restart pending"); + return; + } + setBluetoothEnable(true); +} + static void nbEnter() { LOG_POWERFSM("State: nbEnter"); @@ -211,7 +222,7 @@ static void nbEnter() static void darkEnter() { LOG_POWERFSM("State: darkEnter"); - setBluetoothEnable(true); + setBluetoothEnableUnlessRestarting(); if (screen) screen->setOn(false); // Screen timeout enters DARK; ensure backlight also turns off. @@ -235,7 +246,7 @@ static void serialExit() { LOG_POWERFSM("State: serialExit"); // Turn bluetooth back on when we leave serial stream API - setBluetoothEnable(true); + setBluetoothEnableUnlessRestarting(); } static void powerEnter() @@ -248,7 +259,7 @@ static void powerEnter() } else { if (screen) screen->setOn(true); - setBluetoothEnable(true); + setBluetoothEnableUnlessRestarting(); // within enter() the function getState() returns the state we came from } } @@ -266,7 +277,7 @@ static void powerIdle() static void powerExit() { LOG_POWERFSM("State: powerExit"); - setBluetoothEnable(true); + setBluetoothEnableUnlessRestarting(); } static void onEnter() @@ -274,7 +285,7 @@ static void onEnter() LOG_POWERFSM("State: onEnter"); if (screen) screen->setOn(true); - setBluetoothEnable(true); + setBluetoothEnableUnlessRestarting(); } static void onIdle() diff --git a/src/platform/nrf52/NRF52Bluetooth.cpp b/src/platform/nrf52/NRF52Bluetooth.cpp index 85a29e05a9..608fb1b7bb 100644 --- a/src/platform/nrf52/NRF52Bluetooth.cpp +++ b/src/platform/nrf52/NRF52Bluetooth.cpp @@ -245,8 +245,12 @@ void NRF52Bluetooth::shutdown() // Shutdown bluetooth for minimum power draw LOG_INFO("Disable NRF52 bluetooth"); Bluefruit.Security.setPairPasskeyCallback(NRF52Bluetooth::onUnwantedPairing); // Actively refuse (during factory reset) - disconnect(); + + // Clear the auto-restart flag before dropping the link: our DISCONNECTED event is only processed + // after this callback returns and would re-start advertising. startAdv()/resumeAdvertising() re-set it. + Bluefruit.Advertising.restartOnDisconnect(false); Bluefruit.Advertising.stop(); + disconnect(); } void NRF52Bluetooth::startDisabled() {