From 3d9a7ed02f4e50ee2eb541ac2f4d7f6f5b5d316e Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 14 Aug 2020 15:43:37 +1000 Subject: [PATCH] extmod/btstack: Implement GAP scan duration_ms parameter. This commit makes scanning work when duration_ms is set to zero. Prior to this it would not work with duration_ms set to zero. --- extmod/btstack/modbluetooth_btstack.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c index c7269d33ed..89e396dfd0 100644 --- a/extmod/btstack/modbluetooth_btstack.c +++ b/extmod/btstack/modbluetooth_btstack.c @@ -889,7 +889,7 @@ int mp_bluetooth_gap_disconnect(uint16_t conn_handle) { #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE STATIC btstack_timer_source_t scan_duration_timeout; -STATIC void hci_initialization_timeout_handler(btstack_timer_source_t *ds) { +STATIC void scan_duration_timeout_handler(btstack_timer_source_t *ds) { (void)ds; mp_bluetooth_gap_scan_stop(); } @@ -897,9 +897,11 @@ STATIC void hci_initialization_timeout_handler(btstack_timer_source_t *ds) { int mp_bluetooth_gap_scan_start(int32_t duration_ms, int32_t interval_us, int32_t window_us) { DEBUG_EVENT_printf("mp_bluetooth_gap_scan_start\n"); - btstack_run_loop_set_timer(&scan_duration_timeout, duration_ms); - btstack_run_loop_set_timer_handler(&scan_duration_timeout, hci_initialization_timeout_handler); - btstack_run_loop_add_timer(&scan_duration_timeout); + if (duration_ms > 0) { + btstack_run_loop_set_timer(&scan_duration_timeout, duration_ms); + btstack_run_loop_set_timer_handler(&scan_duration_timeout, scan_duration_timeout_handler); + btstack_run_loop_add_timer(&scan_duration_timeout); + } // 0 = passive scan (we don't handle scan response). gap_set_scan_parameters(0, interval_us / 625, window_us / 625);