diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2021-07-23 15:12:26 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-08-14 22:21:55 +1000 |
commit | 1d9e489af3d00d737917b09c1f0d007705e970e9 (patch) | |
tree | accb081390ddda3bc2c9a36579480f0921934dbf /extmod/modbluetooth.c | |
parent | 5733c49174a200b59196f44377a1418a6c38c877 (diff) |
extmod/modbluetooth: Add send_update arg to gatts_write.
This allows the write to trigger a notification or indication, but only to
subscribed clients. This is different to gatts_notify/gatts_indicate,
which will unconditionally notify/indicate.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'extmod/modbluetooth.c')
-rw-r--r-- | extmod/modbluetooth.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/extmod/modbluetooth.c b/extmod/modbluetooth.c index bf8d071a9..cb153f70e 100644 --- a/extmod/modbluetooth.c +++ b/extmod/modbluetooth.c @@ -717,15 +717,17 @@ STATIC mp_obj_t bluetooth_ble_gatts_read(mp_obj_t self_in, mp_obj_t value_handle } STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gatts_read_obj, bluetooth_ble_gatts_read); -STATIC mp_obj_t bluetooth_ble_gatts_write(mp_obj_t self_in, mp_obj_t value_handle_in, mp_obj_t data) { - (void)self_in; +STATIC mp_obj_t bluetooth_ble_gatts_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); - int err = mp_bluetooth_gatts_write(mp_obj_get_int(value_handle_in), bufinfo.buf, bufinfo.len); - bluetooth_handle_errno(err); + mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ); + bool send_update = false; + if (n_args > 3) { + send_update = mp_obj_is_true(args[3]); + } + bluetooth_handle_errno(mp_bluetooth_gatts_write(mp_obj_get_int(args[1]), bufinfo.buf, bufinfo.len, send_update)); return MP_OBJ_NEW_SMALL_INT(bufinfo.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(bluetooth_ble_gatts_write_obj, bluetooth_ble_gatts_write); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bluetooth_ble_gatts_write_obj, 3, 4, bluetooth_ble_gatts_write); STATIC mp_obj_t bluetooth_ble_gatts_notify(size_t n_args, const mp_obj_t *args) { mp_int_t conn_handle = mp_obj_get_int(args[1]); |