extmod/bluetooth: Support active scanning in BLE.gap_scan().

This adds an additional optional parameter to gap_scan() to select active
scanning, where scan responses are returned as well as normal scan results.
This parameter is False by default which retains the existing behaviour.
This commit is contained in:
Andrew Leech
2020-08-14 11:49:41 +10:00
committed by Damien George
parent 0bc2c1c105
commit a80a146858
5 changed files with 14 additions and 9 deletions

View File

@@ -609,6 +609,7 @@ STATIC mp_obj_t bluetooth_ble_gap_scan(size_t n_args, const mp_obj_t *args) {
mp_int_t duration_ms = 0;
mp_int_t interval_us = 1280000;
mp_int_t window_us = 11250;
bool active_scan = false;
if (n_args > 1) {
if (args[1] == mp_const_none) {
// scan(None) --> stop scan.
@@ -619,12 +620,15 @@ STATIC mp_obj_t bluetooth_ble_gap_scan(size_t n_args, const mp_obj_t *args) {
interval_us = mp_obj_get_int(args[2]);
if (n_args > 3) {
window_us = mp_obj_get_int(args[3]);
if (n_args > 4) {
active_scan = mp_obj_is_true(args[4]);
}
}
}
}
return bluetooth_handle_errno(mp_bluetooth_gap_scan_start(duration_ms, interval_us, window_us));
return bluetooth_handle_errno(mp_bluetooth_gap_scan_start(duration_ms, interval_us, window_us, active_scan));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_scan_obj, 1, 4, bluetooth_ble_gap_scan);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_scan_obj, 1, 5, bluetooth_ble_gap_scan);
#endif // MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
STATIC mp_obj_t bluetooth_ble_gap_disconnect(mp_obj_t self_in, mp_obj_t conn_handle_in) {