extmod/modbluetooth: Make gap_disconnect not raise when disconnected.

Previously it raised OSError(MP_ENOTCONN) if the conn_handle was already
disconnected.  Now it returns True/False.
This commit is contained in:
Jim Mussared 2019-10-15 12:07:29 +11:00 committed by Damien George
parent ea315d7d58
commit 36502bdfdc
2 changed files with 11 additions and 1 deletions

View File

@ -262,6 +262,9 @@ Central Role (GATT Client)
On success, the ``_IRQ_PERIPHERAL_DISCONNECT`` event will be raised. On success, the ``_IRQ_PERIPHERAL_DISCONNECT`` event will be raised.
Returns ``False`` if the connection handle wasn't connected, and ``True``
otherwise.
.. method:: BLE.gattc_discover_services(conn_handle) .. method:: BLE.gattc_discover_services(conn_handle)
Query a connected peripheral for its services. Query a connected peripheral for its services.

View File

@ -27,6 +27,7 @@
#include "py/binary.h" #include "py/binary.h"
#include "py/misc.h" #include "py/misc.h"
#include "py/mperrno.h"
#include "py/obj.h" #include "py/obj.h"
#include "py/objstr.h" #include "py/objstr.h"
#include "py/objarray.h" #include "py/objarray.h"
@ -527,8 +528,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gap_scan_obj, 1, 4, blu
STATIC mp_obj_t bluetooth_ble_gap_disconnect(mp_obj_t self_in, mp_obj_t conn_handle_in) { STATIC mp_obj_t bluetooth_ble_gap_disconnect(mp_obj_t self_in, mp_obj_t conn_handle_in) {
uint16_t conn_handle = mp_obj_get_int(conn_handle_in); uint16_t conn_handle = mp_obj_get_int(conn_handle_in);
int err = mp_bluetooth_gap_disconnect(conn_handle); int err = mp_bluetooth_gap_disconnect(conn_handle);
if (err == 0) {
return mp_const_true;
} else if (err == MP_ENOTCONN) {
return mp_const_false;
} else {
return bluetooth_handle_errno(err); return bluetooth_handle_errno(err);
} }
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gap_disconnect_obj, bluetooth_ble_gap_disconnect); STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gap_disconnect_obj, bluetooth_ble_gap_disconnect);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------