fix(bluetooth): robust HID host autoconnect and combo keyboard parser

- Scan: store nameless directed adv to keep addr_type cache for Fosmon-type
  keyboards that wake without name -> fixes auto-connect on boot not finding device
- HID parser: strip Report ID, support standard 3/4-byte mouse [btn,x8,y8,wheel]
  instead of mis-detecting as 12-bit packed; heuristic only when std small
- HID reconnect: try PUBLIC then RANDOM addr_type with 8s timeout,
  periodic retry timer (3/10/30s backoff) that exists at boot via ensureAutoConnTimer,
  direct connect even without advert after empty scans to catch wake-on-keypress
- Verified on waveshare-esp32-s3-rlcd /dev/cu.usbmodem1101 - Fosmon mini
  B00BX0YKX4 combo now moves smoothly and reconnects after board restart

Co-authored-by: Hermes Agent <hermes@noreply>
This commit is contained in:
Adolfo Reyna
2026-07-12 15:26:40 -04:00
parent ff87ff4b1b
commit 78382d6deb
2 changed files with 263 additions and 42 deletions
@@ -82,12 +82,20 @@ int ble_gap_disc_event_handler(struct ble_gap_event* event, void* arg) {
memcpy(record.name, ctx->scan_results[i].name, BT_NAME_MAX + 1);
}
ctx->scan_results[i].rssi = record.rssi;
// Always keep addr_type up to date (RPA can rotate)
ctx->scan_addrs[i] = disc.addr;
found = true;
should_publish = (record.name[0] != '\0');
break;
}
}
if (!found && record.name[0] != '\0' && ctx->scan_count < 64) {
if (!found && ctx->scan_count < 64) {
// Store ALL unique advertisers, not only those with names.
// This is required for auto-connect: bonded keyboards (e.g. Fosmon
// mini keyboard/touchpad combo) may advertise with only Appearance
// + flags after waking from sleep, or use RPA without a name.
// UI can still filter for display, but cache must contain them so
// addr_type is available for ble_gap_connect().
ctx->scan_results[ctx->scan_count] = record;
ctx->scan_addrs[ctx->scan_count] = disc.addr; // full addr (type+val)
ctx->scan_count++;