Fix BLE apps not scanning: use ACI GAP procedures, not raw HCI
On device, scanning failed (BT Inspector showed the scan as stopped and found
nothing). The firmware's GAP layer is initialised by the bt service, and ST's
stack disallows raw hci_le_set_scan_* / hci_le_create_connection in that state.
Switch the shared central layer to the GAP procedures: aci_gap_start_
observation_proc / aci_gap_terminate_gap_proc(GAP_OBSERVATION_PROC) for
scanning, and aci_gap_create_connection (+ terminate the direct-connection proc
to cancel) for connecting, with a short settle after stopping observation.
Also surface the raw BLE status code on BT Inspector's scan screen ("err 0xNN")
so any remaining failure is diagnosable on device. Needs the gap command group
exported (BLE_API default is all).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LEaD4ZeAfvWLBUxXp8G11r
This commit is contained in:
@@ -66,6 +66,7 @@ typedef struct {
|
||||
BcDevice devs[BC_MAX_DEVICES];
|
||||
size_t count, sel, top;
|
||||
bool scanning;
|
||||
uint8_t scan_err;
|
||||
} ScanModel;
|
||||
|
||||
typedef struct {
|
||||
@@ -328,7 +329,10 @@ static void scan_draw(Canvas* c, void* m_) {
|
||||
canvas_set_font(c, FontPrimary);
|
||||
canvas_draw_str(c, 2, 9, "BT Inspector");
|
||||
canvas_set_font(c, FontSecondary);
|
||||
furi_string_printf(s, m->scanning ? "%u found" : "%u (stopped)", (unsigned)m->count);
|
||||
if(m->scanning)
|
||||
furi_string_printf(s, "%u found", (unsigned)m->count);
|
||||
else
|
||||
furi_string_printf(s, "err 0x%02X", m->scan_err);
|
||||
canvas_draw_str_aligned(c, 126, 9, AlignRight, AlignBottom, furi_string_get_cstr(s));
|
||||
canvas_draw_line(c, 0, 11, 127, 11);
|
||||
if(!m->count) canvas_draw_str_aligned(c, 64, 40, AlignCenter, AlignCenter, "Scanning...");
|
||||
@@ -389,7 +393,8 @@ static void scan_enter(void* ctx) {
|
||||
app->cur_view = ViewScan;
|
||||
bool ok = bc_scan_start(app->bc);
|
||||
if(!ok) app_log(app, "SCAN START FAILED 0x%02X", bc_last_error(app->bc));
|
||||
with_view_model(app->scan_view, ScanModel * m, { m->scanning = ok; }, true);
|
||||
uint8_t err = ok ? 0 : bc_last_error(app->bc);
|
||||
with_view_model(app->scan_view, ScanModel * m, { m->scanning = ok; m->scan_err = err; }, true);
|
||||
}
|
||||
|
||||
// ---- page view (scrollable text with optional buttons) -----------------------
|
||||
|
||||
Reference in New Issue
Block a user