@@ -268,20 +268,22 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable
268
268
supervisor_disable_tick ();
269
269
}
270
270
271
- // Stop any current activity; reset to known state.
271
+ // Enabling or disabling: stop any current activity; reset to known state.
272
272
check_hci_error (hci_reset ());
273
273
self -> now_advertising = false;
274
274
self -> extended_advertising = false;
275
275
self -> circuitpython_advertising = false;
276
276
self -> advertising_timeout_msecs = 0 ;
277
277
278
- // Reset list of known attributes.
279
- // Indices into the list are handles. Handle 0x0000 designates an invalid handle,
280
- // so store None there to skip it.
281
- self -> attributes = mp_obj_new_list (0 , NULL );
282
- bleio_adapter_add_attribute (self , mp_const_none );
283
- self -> last_added_service_handle = BLE_GATT_HANDLE_INVALID ;
284
- self -> last_added_characteristic_handle = BLE_GATT_HANDLE_INVALID ;
278
+ if (enabled ) {
279
+ // Reset list of known attributes.
280
+ // Indices into the list are handles. Handle 0x0000 designates an invalid handle,
281
+ // so store None there to skip it.
282
+ self -> attributes = mp_obj_new_list (0 , NULL );
283
+ bleio_adapter_add_attribute (self , mp_const_none );
284
+ self -> last_added_service_handle = BLE_GATT_HANDLE_INVALID ;
285
+ self -> last_added_characteristic_handle = BLE_GATT_HANDLE_INVALID ;
286
+ }
285
287
}
286
288
287
289
bool common_hal_bleio_adapter_get_enabled (bleio_adapter_obj_t * self ) {
@@ -392,9 +394,11 @@ mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t*
392
394
void common_hal_bleio_adapter_stop_scan (bleio_adapter_obj_t * self ) {
393
395
check_enabled (self );
394
396
395
- check_hci_error (hci_le_set_scan_enable (BT_HCI_LE_SCAN_DISABLE , BT_HCI_LE_SCAN_FILTER_DUP_DISABLE ));
396
- shared_module_bleio_scanresults_set_done (self -> scan_results , true);
397
- self -> scan_results = NULL ;
397
+ // If not already scanning, no problem.
398
+ if (hci_le_set_scan_enable (BT_HCI_LE_SCAN_DISABLE , BT_HCI_LE_SCAN_FILTER_DUP_DISABLE ) == HCI_OK ) {
399
+ shared_module_bleio_scanresults_set_done (self -> scan_results , true);
400
+ self -> scan_results = NULL ;
401
+ }
398
402
}
399
403
400
404
// typedef struct {
@@ -782,14 +786,13 @@ void bleio_adapter_gc_collect(bleio_adapter_obj_t* adapter) {
782
786
}
783
787
784
788
void bleio_adapter_reset (bleio_adapter_obj_t * adapter ) {
789
+
785
790
if (!common_hal_bleio_adapter_get_enabled (adapter )) {
786
791
return ;
787
792
}
788
793
789
- common_hal_bleio_adapter_stop_scan (adapter );
790
- if (adapter -> now_advertising ) {
791
- common_hal_bleio_adapter_stop_advertising (adapter );
792
- }
794
+ // Adapter will be reset.
795
+ common_hal_bleio_adapter_set_enabled (adapter , false);
793
796
794
797
adapter -> connection_objs = NULL ;
795
798
for (size_t i = 0 ; i < BLEIO_TOTAL_CONNECTION_COUNT ; i ++ ) {
@@ -801,6 +804,7 @@ void bleio_adapter_reset(bleio_adapter_obj_t* adapter) {
801
804
}
802
805
connection -> connection_obj = mp_const_none ;
803
806
}
807
+
804
808
}
805
809
806
810
void bleio_adapter_background (bleio_adapter_obj_t * adapter ) {
0 commit comments