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.
This commit is contained in:
Jim Mussared 2020-08-14 15:43:37 +10:00 committed by Damien George
parent 2acc087880
commit 3d9a7ed02f

View File

@ -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);