MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / getPairedPeers

Function getPairedPeers

Tactility/Source/bluetooth/Bluetooth.cpp:359–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357}
358
359std::vector<PeerRecord> getPairedPeers() {
360 auto stored = settings::loadAll();
361 std::vector<PeerRecord> result;
362 result.reserve(stored.size());
363 std::array<uint8_t, 6> connected_addr = {};
364 bool hid_host_connected = hidHostGetConnectedPeer(connected_addr);
365 for (const auto& device : stored) {
366 PeerRecord record;
367 record.addr = device.addr;
368 record.name = device.name;
369 record.rssi = 0;
370 record.paired = true;
371 record.profileId = device.profileId;
372 record.connected = hid_host_connected && device.addr == connected_addr;
373 result.push_back(std::move(record));
374 }
375 // Synthesize fallback: LittleFS readdir can lag behind fwrite by one tick, so the
376 // connected peer may not appear in loadAll() yet. Always ensure it is in the list.
377 if (hid_host_connected) {
378 bool found = false;
379 for (const auto& r : result) {
380 if (r.addr == connected_addr) { found = true; break; }
381 }
382 if (!found) {
383 PeerRecord record;
384 record.addr = connected_addr;
385 record.rssi = 0;
386 record.paired = true;
387 record.connected = true;
388 record.profileId = BT_PROFILE_HID_HOST;
389 // Try to get the name from the scan cache.
390 {
391 auto lock = scan_cache_mutex.asScopedLock();
392 lock.lock();
393 for (const auto& sr : scan_results_cache) {
394 if (sr.addr == connected_addr) { record.name = sr.name; break; }
395 }
396 }
397 result.push_back(std::move(record));
398 }
399 }
400 return result;
401}
402
403void pair(const std::array<uint8_t, 6>& /*addr*/) {
404 // Pairing is handled automatically during connection by NimBLE SM.

Callers 2

updatePairedPeersMethod · 0.50
isCurrentlyConnectedMethod · 0.50

Calls 4

loadAllFunction · 0.85
hidHostGetConnectedPeerFunction · 0.85
asScopedLockMethod · 0.80
lockMethod · 0.45

Tested by

no test coverage detected