diff options
| author | Glenn Ruben Bakke <glennbakke@gmail.com> | 2017-05-30 19:32:26 +0200 |
|---|---|---|
| committer | Glenn Ruben Bakke <glennbakke@gmail.com> | 2017-05-30 19:32:26 +0200 |
| commit | 1eb8792fa54fe9e7d06dd0043475771558d25d3a (patch) | |
| tree | e0c8a41e7077c5ed543e31c94c0b26d20c2382e9 | |
| parent | 66db0791927daf63b8b68da9b5851bf72a5c7024 (diff) | |
nrf5/modules/ubluepy: Updating characteristic write method to take in an additional keyword, 'with_response'. Default value is False. Only activated in central role.
| -rw-r--r-- | nrf5/modules/ubluepy/ubluepy_characteristic.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/nrf5/modules/ubluepy/ubluepy_characteristic.c b/nrf5/modules/ubluepy/ubluepy_characteristic.c index 18b58809f..ea3f9b29e 100644 --- a/nrf5/modules/ubluepy/ubluepy_characteristic.c +++ b/nrf5/modules/ubluepy/ubluepy_characteristic.c @@ -111,11 +111,20 @@ STATIC mp_obj_t char_read(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_characteristic_read_obj, char_read); -/// \method write(data) +/// \method write(data, [with_response=False]) /// Write Characteristic value. /// -STATIC mp_obj_t char_write(mp_obj_t self_in, mp_obj_t data) { - ubluepy_characteristic_obj_t * self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t char_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + ubluepy_characteristic_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_obj_t data = pos_args[1]; + + static const mp_arg_t allowed_args[] = { + { MP_QSTR_with_response, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } }, + }; + + // parse args + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 2, pos_args + 2, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); @@ -137,16 +146,18 @@ STATIC mp_obj_t char_write(mp_obj_t self_in, mp_obj_t data) { } } else { #if MICROPY_PY_UBLUEPY_CENTRAL + bool with_response = args[0].u_bool; + ble_drv_attr_c_write(self->p_service->p_periph->conn_handle, self->handle, bufinfo.len, - bufinfo.buf); + bufinfo.buf, + with_response); #endif } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_characteristic_write_obj, char_write); - +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(ubluepy_characteristic_write_obj, 2, char_write); /// \method properties() /// Read Characteristic value properties. |
