summaryrefslogtreecommitdiff
path: root/extmod/modbluetooth.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-11-29 12:48:38 +1100
committerDamien George <damien.p.george@gmail.com>2019-12-04 23:23:07 +1100
commit7aeafe2ae9f16af74d22604b3090641a664b2da2 (patch)
tree35b96bd1aa185aa8563cbdcb2c94e605c9d2c872 /extmod/modbluetooth.c
parent9a849cc7caee63560ecd2455a29615a44e2c809f (diff)
extmod/modbluetooth: Add optional 4th arg to gattc_write for write mode.
This allows the user to explicitly select the behaviour of the write to the remote peripheral. This is needed for peripherals that have characteristics with WRITE_NO_RESPONSE set (instead of normal WRITE). The function's signature is now: BLE.gattc_write(conn_handle, value_handle, data, mode=0) mode=0 means write without response, while mode=1 means write with response. The latter was the original behaviour so this commit is a change in behaviour of this method, and one should specify 1 as the 4th argument to get back the old behaviour. In the future there could be more modes supported, such as long writes.
Diffstat (limited to 'extmod/modbluetooth.c')
-rw-r--r--extmod/modbluetooth.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c
index 2293e0367..74f73c1f2 100644
--- a/extmod/modbluetooth.c
+++ b/extmod/modbluetooth.c
@@ -641,9 +641,13 @@ STATIC mp_obj_t bluetooth_ble_gattc_write(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t bufinfo = {0};
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
size_t len = bufinfo.len;
- return bluetooth_handle_errno(mp_bluetooth_gattc_write(conn_handle, value_handle, bufinfo.buf, &len));
+ unsigned int mode = MP_BLUETOOTH_WRITE_MODE_NO_RESPONSE;
+ if (n_args == 5) {
+ mode = mp_obj_get_int(args[4]);
+ }
+ return bluetooth_handle_errno(mp_bluetooth_gattc_write(conn_handle, value_handle, bufinfo.buf, &len, mode));
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_write_obj, 4, 4, bluetooth_ble_gattc_write);
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gattc_write_obj, 4, 5, bluetooth_ble_gattc_write);
#endif // MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE