@@ -1648,6 +1648,16 @@ STATIC void gap_event_dump(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t
1648
1648
}
1649
1649
#endif // EVENT_DEBUG
1650
1650
1651
+ STATIC void network_bluetooth_disconnect_helper (network_bluetooth_connection_obj_t * connection ) {
1652
+ network_bluetooth_obj_t * bluetooth = network_bluetooth_get_singleton ();
1653
+ if (connection != MP_OBJ_NULL && connection -> conn_id != -1 ) {
1654
+ esp_ble_gattc_close (bluetooth -> gattc_interface , connection -> conn_id );
1655
+ network_bluetooth_del_connection_by_bda (connection -> bda );
1656
+ connection -> conn_id = -1 ;
1657
+ connection -> services = mp_obj_new_list (0 , NULL );
1658
+ }
1659
+ }
1660
+
1651
1661
STATIC mp_obj_t network_bluetooth_callback_queue_handler (mp_obj_t arg ) {
1652
1662
network_bluetooth_obj_t * bluetooth = network_bluetooth_get_singleton ();
1653
1663
@@ -1908,10 +1918,7 @@ STATIC mp_obj_t network_bluetooth_callback_queue_handler(mp_obj_t arg) {
1908
1918
1909
1919
case NETWORK_BLUETOOTH_GATTC_CLOSE :
1910
1920
{
1911
- network_bluetooth_connection_obj_t * conn = network_bluetooth_find_connection_by_conn_id (cbdata .gattc_open_close .conn_id );
1912
- if (conn != MP_OBJ_NULL ) {
1913
- conn -> conn_id = -1 ;
1914
- }
1921
+ network_bluetooth_disconnect_helper (network_bluetooth_find_connection_by_conn_id (cbdata .gattc_open_close .conn_id ));
1915
1922
}
1916
1923
break ;
1917
1924
@@ -2297,9 +2304,9 @@ STATIC void network_bluetooth_adv_updated() {
2297
2304
esp_ble_gap_config_adv_data (& self -> adv_data );
2298
2305
2299
2306
// Restart will be handled in network_bluetooth_gap_event_handler
2300
-
2301
2307
}
2302
2308
2309
+
2303
2310
/******************************************************************************/
2304
2311
// MicroPython bindings for network_bluetooth
2305
2312
//
@@ -2890,14 +2897,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_bluetooth_connection_is_connected_obj,
2890
2897
// conn.disconnect()
2891
2898
2892
2899
STATIC mp_obj_t network_bluetooth_connection_disconnect (mp_obj_t self_in ) {
2893
- network_bluetooth_obj_t * bluetooth = network_bluetooth_get_singleton ();
2894
- network_bluetooth_connection_obj_t * connection = (network_bluetooth_connection_obj_t * ) self_in ;
2895
- if (connection -> conn_id != -1 ) {
2896
- esp_ble_gattc_close (bluetooth -> gattc_interface , connection -> conn_id );
2897
- network_bluetooth_del_connection_by_bda (connection -> bda );
2898
- connection -> conn_id = -1 ;
2899
- connection -> services = mp_obj_new_list (0 , NULL );
2900
- }
2900
+ network_bluetooth_disconnect_helper (self_in );
2901
2901
return mp_const_none ;
2902
2902
}
2903
2903
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (network_bluetooth_connection_disconnect_obj , network_bluetooth_connection_disconnect );
0 commit comments