From 9e2de40b9b3fe4dda30fd560e59f4094782623ae Mon Sep 17 00:00:00 2001 From: awalol <61059886+awalol@users.noreply.github.com> Date: Sat, 16 May 2026 13:51:29 +0800 Subject: [PATCH] Add bt_get_signal_strength Comment Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/bt.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bt.cpp b/src/bt.cpp index c830099..527b5cb 100644 --- a/src/bt.cpp +++ b/src/bt.cpp @@ -77,12 +77,15 @@ bool bt_disconnect() { } void bt_get_signal_strength(int8_t *rssi) { - if (acl_handle != HCI_CON_HANDLE_INVALID) { - gap_read_rssi(acl_handle); - } + // gap_read_rssi() completes asynchronously, so this function can only + // return the last cached RSSI value. Trigger a refresh afterwards so a + // subsequent call can observe the updated value once the RSSI event arrives. if (rssi != nullptr) { *rssi = bt_rssi; } + if (acl_handle != HCI_CON_HANDLE_INVALID) { + gap_read_rssi(acl_handle); + } } void bt_l2cap_init() {