diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2019-10-15 12:07:29 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-10-15 17:22:53 +1100 |
commit | 36502bdfdcd63b2bc87027380dc63098221e8b04 (patch) | |
tree | 3e62d5b937bf1a96225687076f6a21af2e76cffb /extmod/modbluetooth.c | |
parent | ea315d7d58e429d27c4d4fb4b98a432e86fdcae6 (diff) |
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.
Diffstat (limited to 'extmod/modbluetooth.c')
-rw-r--r-- | extmod/modbluetooth.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index cd8a2b070..640449925 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -27,6 +27,7 @@ #include "py/binary.h" #include "py/misc.h" +#include "py/mperrno.h" #include "py/obj.h" #include "py/objstr.h" #include "py/objarray.h" @@ -527,7 +528,13 @@ 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) { uint16_t conn_handle = mp_obj_get_int(conn_handle_in); int err = mp_bluetooth_gap_disconnect(conn_handle); - return bluetooth_handle_errno(err); + if (err == 0) { + return mp_const_true; + } else if (err == MP_ENOTCONN) { + return mp_const_false; + } else { + return bluetooth_handle_errno(err); + } } STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gap_disconnect_obj, bluetooth_ble_gap_disconnect); |