rds/multi-bond-support#6
Merged
Merged
Conversation
Add ability to bond with up to 4 MouthPad devices simultaneously. Users can quickly switch between bonded devices without re-pairing. Changes: - Replace single bond tracking with multi-bond array (MAX_BONDED_DEVICES=4) - Add bonded_device struct with address, name, last_seen timestamp - Implement bond management functions: * ble_central_is_device_bonded() - check if device is bonded * ble_central_add_bonded_device() - add new bond to list * ble_central_remove_bonded_device() - remove specific bond * ble_central_get_bonded_devices() - get all bonded devices - Update clear_bonded_device() to clear ALL bonds - Update bt_foreach_bond() callback to populate multi-bond array - Add mutex protection for thread-safe bond list access - Add scanning mode enum (NORMAL vs ADDITIONAL) for future use Note: Settings persistence and additional scan mode to be implemented next
Update settings handlers to save/load multiple bonded device names: - Parse bond_X/name and bond_X/addr keys from settings - Save device names when bonds are added or updated - Load device names on startup for all bonded devices - Clear all bond settings when bonds are cleared Settings are stored as: ble_central/bond_0/name ble_central/bond_1/name ... Device addresses are populated by bt_foreach_bond() and don't need to be saved to settings separately.
Add ability to scan for additional MouthPad devices via button press. Users can now bond multiple devices and quickly switch between them. Button behavior: - Single press: Start ADDITIONAL scan (10 second timeout) * Disconnects current device (keeps bond) * Scans for NEW devices only (ignores already-bonded) * Auto-returns to NORMAL mode after timeout or new bond - Hold (2s): Clear ALL bonds (unchanged) Scan modes: - NORMAL: Connect to any bonded device (first seen) - ADDITIONAL: Only connect to NEW unbonded devices Changes: - Add ble_central_start_additional_scan() function - Implement 10-second timeout with countdown display - Update scan_filter_match() to check bond status based on mode - Add check_additional_scan_timeout() for automatic mode switching - Wire button CLICK event to start additional scan - Update all old single-bond references to use new multi-bond API - Fix pairing_complete to use ble_central_add_bonded_device() - Auto-switch to NORMAL mode after successful new bond Phase 1 complete - ready for testing!
Add comprehensive bonded device display functionality: - display_bonded_devices() function in ble_central.c that logs all bonded devices with names and addresses during initialization - Shell command 'bonds' to query bonded devices on demand via serial console - Called automatically after settings load to verify multi-bond state This helps verify multi-bond functionality during testing and provides visibility into which devices are currently bonded.
- Remove duplicate struct bonded_device definition (use header definition) - Add forward declaration for check_additional_scan_timeout() - Remove unused variables (next, filter_mode) - Remove unused try_add_address_filter() function - Initialize bonded_devices array to zero at startup to prevent corrupted entries
The ble_central_get_bonded_devices() function was copying valid entries sequentially but leaving unused array slots untouched. When called from the shell command with an uninitialized stack array, this caused garbage data to appear as phantom bonded devices. Now properly zeros the entire output array before copying valid entries.
Move settings_load() before bt_foreach_bond() to match the working single-bond implementation. The BT stack needs settings loaded before it can enumerate existing bonds. Fixes bond restoration after reboot for multi-bond support.
- Always connect to bonded devices when available - Immediately accept unbonded devices if no bonded ones advertising - Remove timeout-based delay, use dynamic availability check - Track bonded device advertising per scan session
- Remove button click trigger for additional scan mode - Auto-fallback to unbonded devices when no bonds available - Reset scan mode to NORMAL when clearing bonds - Add delay after disconnect before clearing bonds - Add yields between flash operations to prevent blocking
Always restart scanning on connection failure, not just when default_conn matches. Fixes issue where connection timeouts would leave the device stuck without scanning.
- Save both addresses and names to persistent settings when bonding - Load addresses from settings before loading names (fixes name loss) - Track bond count when loading from settings - Ensures bond order consistency across reboots
Remove is_valid check when loading names - addresses and names can load in any order from settings subsystem
- Store DIS info with device address in key - Add functions to load/clear DIS per address - Load device names from DIS info when enumerating bonds - Save DIS with current connection address - Still need to remove old name/address storage code
Settings keys can't have parentheses. Changed from 'F0_1A_5F_52_2A_3E_(random)' to clean hex 'F01A5F522A3E_1'
- Load DIS info for specific device (connected or first bonded) - Use settings_load_one() instead of settings_runtime_get() - Prefer connected device, fallback to first bonded device
There was a problem hiding this comment.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
When adding a 5th bonded device: - Find the device with the oldest last_seen timestamp - Clear its DIS info from storage - Unpair it from the BT stack - Clear its settings entries - Replace it with the new device This ensures we always maintain the 4 most recently used bonds.
ble_central_remove_bonded_device now properly cleans up: - DIS info from persistent storage - Settings entries (bond_N/name and bond_N/addr) - In-memory bonded_devices array This prevents removed devices from reappearing after reboot.
Increase key buffer from 32 to 64 bytes to prevent truncation warnings when formatting settings keys like 'ble_central/bond_X/name'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds multiple bond support.
Previously only one MP^ could be bonded at a time. And then it would only re-connect to that one bonded device.
Now the dongle will attempt to re-connect to previous bonds and if not found then auto-bond to any un-bonded advertising MP.
Note
Enable bonding with up to 4 devices, prefer reconnecting to known devices, add a timed additional-scan for new devices, persist per-device DIS info, and expose a shell command to list bonds.
src/ble_central.*):MAX_BONDED_DEVICES=4withstruct bonded_device, mutex protection, and APIs:ble_central_is_device_bonded,add/remove/get_bonded_devices,clear_bonded_device,get_bonded_device_addr.addr/nameundersettings(ble_central/bond_X/*); load settings beforebt_foreach_bond; display restored bonds at boot.SCAN_MODE_NORMAL(prefer bonded) andSCAN_MODE_ADDITIONAL(only new devices) with 10s timeout; indicator reflects mode; always restart scan on connection failure.is_scanning/is_connecting/is_connected) andmark_services_ready.src/ble_dis.*):ble_dis/<addr>/info); new APIsble_dis_load_info_for_addr,ble_dis_clear_saved_for_addr;ble_dis_clear_savednow only clears cache; save DIS on discovery/name read.src/main.c):bondsshell command to list bonded devices; delay 500ms before clearing bonds; DeviceInfo response now loads DIS info for the connected or first bonded device.prj.conf):CONFIG_BT_MAX_PAIRED=4(was 1).Written by Cursor Bugbot for commit 9fbf109. This will update automatically on new commits. Configure here.