From 4214dcaf98258bedcc1f32c5ec948835ec0661e9 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 10 Sep 2026 23:50:00 +0100 Subject: [PATCH] Order scan lists by discovery time, not RSSI, so they stay still bc_snapshot re-sorted by RSSI every refresh, so entries jumped around as signal fluctuated. Sort by first-seen instead: the list is stable and new devices append at the bottom. Applies to every app that uses the shared snapshot (BT Inspector, HID Host, Sensor Dashboard, GATT Fuzzer). Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01LEaD4ZeAfvWLBUxXp8G11r --- libble/ble_central.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libble/ble_central.c b/libble/ble_central.c index 3d9cd10..2bd2776 100644 --- a/libble/ble_central.c +++ b/libble/ble_central.c @@ -351,10 +351,12 @@ size_t bc_snapshot(BleCentral* bc, BcDevice* out, size_t max) { d->logged = true; } furi_mutex_release(bc->mutex); - for(size_t i = 1; i < n; i++) { // insertion sort by RSSI, strongest first (n <= 32) + // Order by discovery time (first seen) so the list is stable and doesn't + // jump around as RSSI changes. Insertion sort, n <= 32. + for(size_t i = 1; i < n; i++) { BcDevice d = out[i]; size_t j = i; - while(j > 0 && out[j - 1].rssi < d.rssi) { + while(j > 0 && out[j - 1].first_seen > d.first_seen) { out[j] = out[j - 1]; j--; }