From 577bf0724a0002608259227a36246fa9a8017838 Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Sat, 18 Feb 2017 17:57:10 +0100 Subject: [PATCH] nrf5/modules: Updating ubluepy peripheral. Creating empty service list in constructor. Appending services to the list when added. Added new function for retreiving the service list; getServices(). --- nrf5/modules/ubluepy/ubluepy_peripheral.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nrf5/modules/ubluepy/ubluepy_peripheral.c b/nrf5/modules/ubluepy/ubluepy_peripheral.c index 9e8372dd6a..6428d171a8 100644 --- a/nrf5/modules/ubluepy/ubluepy_peripheral.c +++ b/nrf5/modules/ubluepy/ubluepy_peripheral.c @@ -28,6 +28,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "py/objstr.h" +#include "py/objlist.h" #if MICROPY_PY_UBLUEPY @@ -91,6 +92,8 @@ STATIC mp_obj_t ubluepy_peripheral_make_new(const mp_obj_type_t *type, size_t n_ s->notif_handler = mp_const_none; s->conn_handle = 0xFFFF; + s->service_list = mp_obj_new_list(0, NULL); + return MP_OBJ_FROM_PTR(s); } @@ -201,20 +204,31 @@ STATIC mp_obj_t peripheral_add_service(mp_obj_t self_in, mp_obj_t service) { p_service->p_periph = self; + mp_obj_list_append(self->service_list, service); + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_peripheral_add_service_obj, peripheral_add_service); +/// \method disconnect() +/// disconnect connection. +/// +STATIC mp_obj_t peripheral_get_services(mp_obj_t self_in) { + ubluepy_peripheral_obj_t * self = MP_OBJ_TO_PTR(self_in); + + return self->service_list; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(ubluepy_peripheral_get_services_obj, peripheral_get_services); 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_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) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_getServices), (mp_obj_t)(&ubluepy_peripheral_get_services_obj) }, #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_disconnect), (mp_obj_t)(&ubluepy_peripheral_disconnect_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_getServices), (mp_obj_t)(&ubluepy_peripheral_get_services_obj) }, { MP_OBJ_NEW_QSTR(MP_QSTR_getServiceByUUID), (mp_obj_t)(&ubluepy_peripheral_get_service_by_uuid_obj) }, { MP_OBJ_NEW_QSTR(MP_QSTR_getCharacteristics), (mp_obj_t)(&ubluepy_peripheral_get_chars_obj) }, { MP_OBJ_NEW_QSTR(MP_QSTR_getDescriptors), (mp_obj_t)(&ubluepy_peripheral_get_descs_obj) },