@@ -111,11 +111,20 @@ STATIC mp_obj_t char_read(mp_obj_t self_in) {
111111}
112112STATIC MP_DEFINE_CONST_FUN_OBJ_1 (ubluepy_characteristic_read_obj , char_read );
113113
114- /// \method write(data)
114+ /// \method write(data, [with_response=False] )
115115/// Write Characteristic value.
116116///
117- STATIC mp_obj_t char_write (mp_obj_t self_in , mp_obj_t data ) {
118- ubluepy_characteristic_obj_t * self = MP_OBJ_TO_PTR (self_in );
117+ STATIC mp_obj_t char_write (mp_uint_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
118+ ubluepy_characteristic_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
119+ mp_obj_t data = pos_args [1 ];
120+
121+ static const mp_arg_t allowed_args [] = {
122+ { MP_QSTR_with_response , MP_ARG_KW_ONLY | MP_ARG_BOOL , {.u_bool = false } },
123+ };
124+
125+ // parse args
126+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
127+ mp_arg_parse_all (n_args - 2 , pos_args + 2 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
119128
120129 mp_buffer_info_t bufinfo ;
121130 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) {
137146 }
138147 } else {
139148#if MICROPY_PY_UBLUEPY_CENTRAL
149+ bool with_response = args [0 ].u_bool ;
150+
140151 ble_drv_attr_c_write (self -> p_service -> p_periph -> conn_handle ,
141152 self -> handle ,
142153 bufinfo .len ,
143- bufinfo .buf );
154+ bufinfo .buf ,
155+ with_response );
144156#endif
145157 }
146158 return mp_const_none ;
147159}
148- STATIC MP_DEFINE_CONST_FUN_OBJ_2 (ubluepy_characteristic_write_obj , char_write );
149-
160+ STATIC MP_DEFINE_CONST_FUN_OBJ_KW (ubluepy_characteristic_write_obj , 2 , char_write );
150161
151162/// \method properties()
152163/// Read Characteristic value properties.
0 commit comments