nrf5/modules: Guarding callback to python event handler before issue the call in case it is not set.
This commit is contained in:
parent
18365135f7
commit
2fd55feb0c
@ -42,6 +42,7 @@ STATIC void ubluepy_peripheral_print(const mp_print_t *print, mp_obj_t o, mp_pri
|
|||||||
STATIC void event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t length, uint8_t * data) {
|
STATIC void event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t length, uint8_t * data) {
|
||||||
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
|
if (self->conn_handler != mp_const_none) {
|
||||||
mp_obj_t args[3];
|
mp_obj_t args[3];
|
||||||
mp_uint_t num_of_args = 3;
|
mp_uint_t num_of_args = 3;
|
||||||
args[0] = MP_OBJ_NEW_SMALL_INT(event_id);
|
args[0] = MP_OBJ_NEW_SMALL_INT(event_id);
|
||||||
@ -54,6 +55,7 @@ STATIC void event_handler(mp_obj_t self_in, uint16_t event_id, uint16_t length,
|
|||||||
|
|
||||||
// for now hard-code all events to conn_handler
|
// for now hard-code all events to conn_handler
|
||||||
mp_call_function_n_kw(self->conn_handler, num_of_args, 0, args);
|
mp_call_function_n_kw(self->conn_handler, num_of_args, 0, args);
|
||||||
|
}
|
||||||
|
|
||||||
(void)self;
|
(void)self;
|
||||||
}
|
}
|
||||||
@ -78,6 +80,10 @@ STATIC mp_obj_t ubluepy_peripheral_make_new(const mp_obj_type_t *type, size_t n_
|
|||||||
|
|
||||||
sd_event_handler_set(MP_OBJ_FROM_PTR(s), event_handler);
|
sd_event_handler_set(MP_OBJ_FROM_PTR(s), event_handler);
|
||||||
|
|
||||||
|
s->delegate = mp_const_none;
|
||||||
|
s->conn_handler = mp_const_none;
|
||||||
|
s->notif_handler = mp_const_none;
|
||||||
|
|
||||||
return MP_OBJ_FROM_PTR(s);
|
return MP_OBJ_FROM_PTR(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user