Add keepsBluetoothAlive hook to Activity base class

Introduces a virtual method allowing activities to indicate whether they need the BLE stack to remain active. This enables selective teardown of Bluetooth to free heap memory, with the Bluetooth settings screen being able to override this for pairing and scanning functionality.
This commit is contained in:
Justin Mitchell
2026-06-24 17:00:52 -04:00
parent d30fde2f4d
commit d6f5be6b7a
15 changed files with 112 additions and 39 deletions
@@ -6,6 +6,7 @@
#include <Logging.h>
#include <WiFi.h>
#include "BleInput.h"
#include "CrossPointSettings.h"
#include "MappedInputManager.h"
#include "WifiCredentialStore.h"
@@ -93,6 +94,11 @@ void WifiSelectionActivity::startWifiScan() {
networks.clear();
requestUpdate();
// Free the BLE stack before bringing WiFi up: the C3 has one radio and the two
// stacks can't both fit in heap. Reachable from the reader via KOReader sync, where
// BLE is still resident; a no-op when BLE is already off (launched from Settings).
bleinput::stop();
// Set WiFi mode to station
WiFi.mode(WIFI_STA);
WiFi.disconnect();
@@ -211,6 +217,7 @@ void WifiSelectionActivity::attemptConnection() {
connectionError.clear();
requestUpdate();
bleinput::stop(); // free the BLE stack before WiFi (shared C3 radio, tight heap)
WiFi.persistent(false); // Credentials are managed by WifiCredentialStore; suppress SDK NVS auto-connect
WiFi.mode(WIFI_STA);
WiFi.disconnect(true, true); // Abort any in-progress SDK auto-connect and clear NVS-saved SSID