Skip to content

Enhance BLE reconnect handling and decouple UI updates#110

Open
zjwhitehead wants to merge 4 commits intomasterfrom
ble-pairing
Open

Enhance BLE reconnect handling and decouple UI updates#110
zjwhitehead wants to merge 4 commits intomasterfrom
ble-pairing

Conversation

@zjwhitehead
Copy link
Copy Markdown
Member

This pull request introduces a "reconnect window" feature for BLE advertising, refines the BLE pairing mode logic, and improves BLE status icon handling in the UI. The reconnect window allows previously bonded devices a 5-minute period after boot or disconnect to reconnect before reverting to whitelist-only advertising. BLE status icon updates are now more robust and better synchronized with BLE state.

BLE Core Logic Improvements:

  • Added a reconnect window mechanism: after boot or disconnect (if bonds exist), advertising remains open for 5 minutes to allow bonded devices to reconnect (reconnectWindowActive, associated timers, and logic in ble_core.cpp). [1] [2] [3] [4]
  • Modified advertising logic to use the reconnect window: advertising only starts for bonded devices if the reconnect window is active, otherwise, it is restricted (shouldAdvertiseWhilePowered, startAdvertising). [1] [2]
  • Removed pairing-mode manufacturer data from advertising payloads, simplifying BLE advertising data. [1] [2]
  • Added isBLEPairingModeActive() for UI and logic integration. [1] [2]

UI and BLE Status Icon Handling:

  • Added showBLEStatusIcon() and hideBLEStatusIcon() to control the BLE icon, and improved icon state synchronization in updateLvglMainScreen to reflect actual BLE connection and pairing mode status. [1] [2] [3]
  • Refactored pairing icon flashing logic: now uses the new status icon functions and ensures the icon state is always correct, even after missed events.

Configuration and Code Cleanups:

  • Disabled auto-pairing on boot by default in platformio.ini (commented out BLE_PAIR_ON_BOOT).
  • Removed redundant includes and unnecessary icon flashing calls from BLE logic and button handler. [1] [2]

These changes improve user experience by providing a grace period for device reconnection, ensuring the BLE status icon accurately reflects BLE state, and cleaning up advertising and configuration logic.

Introduce a 5-minute reconnect window and UI status control for BLE advertising/connection handling. Adds reconnect window timer/flag and init logic so whitelist advertising after boot or disconnect only runs while the reconnect window is active; advertising logic now checks reconnectWindowActive instead of relying solely on bond count. Add updateBLEStatusIcon(), showBLEStatusIcon(), and hideBLEStatusIcon() and wire status updates across BLE lifecycle events; LVGL changes centralize pairing/status icon show/hide and make stopBLEPairingIconFlash delegate to hideBLEStatusIcon. Remove some legacy scan-response manufacturer payload code paths and stop triggering the pairing-icon flash from the main button handler. Also comment out the BLE_PAIR_ON_BOOT build flag in platformio.ini.
Remove direct UI calls from BLE core and move BLE pairing icon management into the LVGL UI task. Added isBLEPairingModeActive() to ble_core.h/.cpp so the UI can query pairing state, removed updateBLEStatusIcon() and its calls from ble_core.cpp to decouple BLE logic from display code, and updated lvgl_updates.cpp to include BLE headers and keep the pairing icon in sync (managing the flash timer and visibility). This reduces cross-module coupling and ensures missed callback updates are recovered by the UI task.
Remove the reconnect-window feature and related state/timers from the BLE core (kReconnectWindowTicks, gReconnectWindowTimer, reconnectWindowActive and associated functions). Advertising logic is simplified so bonded devices may always reconnect via whitelist advertising (shouldAdvertiseWhilePowered now checks NimBLEDevice::getNumBonds()). Cleanup removes timer management and reconnect-window handling from connection callbacks, setup, and pairing transition, reducing complexity and reliance on a 5-minute reconnect timer.
Capture and remove the LVGL splash screen to avoid leftover objects and force an initial repaint of the main screen before other tasks contend for SPI. Added a splash_screen pointer (lv_screen_active()), invalidate and refresh the main_display immediately (lv_obj_invalidate + lv_refr_now), and delete the splash screen if it differs from the main screen. Also cleaned up .vscode/extensions.json by removing a duplicate PlatformIO recommendation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant