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
+5 -13
View File
@@ -875,19 +875,11 @@ void EpubReaderActivity::render(RenderLock&& lock) {
built = buildSection();
const bool bleOk = bleinput::ensureStarted();
LOG_INF("ERS", "BLE restart after build: begin=%d", bleOk);
if (bleOk) {
// Show a connecting popup and give the bonded remote a moment to re-link so the
// user isn't left with an unresponsive remote and a silent pause. Bounded: a
// remote that needs a button press to re-advertise won't stall reading — it
// reconnects in the background after we return. The popup is drawn once (e-ink
// holds it) and the page render overwrites it when we resume.
GUI.drawPopup(renderer, tr(STR_BT_CONNECTING_POPUP));
const unsigned long deadline = millis() + 4000;
while (!BleHid.isConnected() && millis() < deadline) {
BleHid.poll();
delay(50);
}
}
// Hold the "BT Connecting..." popup until the remote re-links, then force the
// page render below onto the ghost-cleanup (HALF) path so the popup clears
// without ghosting the grayscale page.
bleinput::showConnectingUntilLinked(renderer, mappedInput);
requestGhostCleanup();
}
if (!built) {
LOG_ERR("ERS", "Failed to persist page data to SD");
@@ -86,6 +86,7 @@ class EpubReaderActivity final : public Activity {
void loop() override;
void render(RenderLock&& lock) override;
bool isReaderActivity() const override { return true; }
void requestGhostCleanup() override { pagesUntilFullRefresh = 1; }
ScreenshotInfo getScreenshotInfo() const override;
CrossPointPosition getCurrentPosition() const;
};
@@ -3,7 +3,6 @@
#include <GfxRenderer.h>
#include <I18n.h>
#include "BleInput.h"
#include "CrossPointSettings.h"
#include "MappedInputManager.h"
#include "components/UITheme.h"
@@ -80,13 +79,10 @@ void EpubReaderMenuActivity::loop() {
}
if (selectedAction == MenuAction::TOGGLE_BLUETOOTH) {
// Toggle in place and stay in the menu (no reader re-render needed).
// Just flip the preference and stay in the menu. The main-loop lifecycle check
// brings the BLE stack up/down to match (and shows the "BT Connecting..." popup),
// so start/stop has a single owner.
SETTINGS.bluetoothEnabled = SETTINGS.bluetoothEnabled ? 0 : 1;
if (SETTINGS.bluetoothEnabled) {
bleinput::ensureStarted();
} else {
bleinput::stop();
}
SETTINGS.saveToFile();
requestUpdate();
return;
@@ -49,5 +49,6 @@ class TxtReaderActivity final : public Activity {
void loop() override;
void render(RenderLock&&) override;
bool isReaderActivity() const override { return true; }
void requestGhostCleanup() override { pagesUntilFullRefresh = 1; }
ScreenshotInfo getScreenshotInfo() const override;
};
@@ -41,5 +41,6 @@ class XtcReaderActivity final : public Activity {
void loop() override;
void render(RenderLock&&) override;
bool isReaderActivity() const override { return true; }
void requestGhostCleanup() override { pagesUntilFullRefresh = 1; }
ScreenshotInfo getScreenshotInfo() const override;
};