nrf5/modules: Adding two new functions to ubluepy peripheral class to set specific handlers for notificaitons and connection related events.
This commit is contained in:
parent
ec517a37f6
commit
db75b5535c
|
@ -93,6 +93,8 @@ typedef struct _ubluepy_delegate_obj_t {
|
||||||
typedef struct _ubluepy_peripheral_obj_t {
|
typedef struct _ubluepy_peripheral_obj_t {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
mp_obj_t delegate;
|
mp_obj_t delegate;
|
||||||
|
mp_obj_t notif_handler;
|
||||||
|
mp_obj_t conn_handler;
|
||||||
} ubluepy_peripheral_obj_t;
|
} ubluepy_peripheral_obj_t;
|
||||||
|
|
||||||
typedef struct _ubluepy_advertise_data_t {
|
typedef struct _ubluepy_advertise_data_t {
|
||||||
|
|
|
@ -84,6 +84,30 @@ STATIC mp_obj_t peripheral_with_delegate(mp_obj_t self_in, mp_obj_t delegate) {
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_with_delegate_obj, peripheral_with_delegate);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_with_delegate_obj, peripheral_with_delegate);
|
||||||
|
|
||||||
|
/// \method setNotificationHandler(func)
|
||||||
|
/// Set handler for Bluetooth LE notification events.
|
||||||
|
///
|
||||||
|
STATIC mp_obj_t peripheral_set_notif_handler(mp_obj_t self_in, mp_obj_t func) {
|
||||||
|
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
|
self->notif_handler = func;
|
||||||
|
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_notif_handler_obj, peripheral_set_notif_handler);
|
||||||
|
|
||||||
|
/// \method setConnectionHandler(func)
|
||||||
|
/// Set handler for Bluetooth LE connection events.
|
||||||
|
///
|
||||||
|
STATIC mp_obj_t peripheral_set_conn_handler(mp_obj_t self_in, mp_obj_t func) {
|
||||||
|
ubluepy_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
|
self->conn_handler = func;
|
||||||
|
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_set_conn_handler_obj, peripheral_set_conn_handler);
|
||||||
|
|
||||||
/// \method advertise(device_name, [service=[service1, service2, ...]], [data=bytearray])
|
/// \method advertise(device_name, [service=[service1, service2, ...]], [data=bytearray])
|
||||||
/// Start advertising.
|
/// Start advertising.
|
||||||
///
|
///
|
||||||
|
@ -162,6 +186,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_add_service_obj, peripheral_
|
||||||
|
|
||||||
STATIC const mp_map_elem_t ubluepy_peripheral_locals_dict_table[] = {
|
STATIC const mp_map_elem_t ubluepy_peripheral_locals_dict_table[] = {
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_withDelegate), (mp_obj_t)(&ubluepy_peripheral_with_delegate_obj) },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_withDelegate), (mp_obj_t)(&ubluepy_peripheral_with_delegate_obj) },
|
||||||
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_setNotificationHandler), (mp_obj_t)(&ubluepy_peripheral_set_notif_handler_obj) },
|
||||||
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_setConnectionHandler), (mp_obj_t)(&ubluepy_peripheral_set_conn_handler_obj) },
|
||||||
#if MICROPY_PY_UBLUEPY_CENTRAL
|
#if MICROPY_PY_UBLUEPY_CENTRAL
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)(&ubluepy_peripheral_connect_obj) },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)(&ubluepy_peripheral_connect_obj) },
|
||||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_disconnect), (mp_obj_t)(&ubluepy_peripheral_disconnect_obj) },
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_disconnect), (mp_obj_t)(&ubluepy_peripheral_disconnect_obj) },
|
||||||
|
|
Loading…
Reference in New Issue