From a44439011507249cf69e9efb44acbaec06f9f4b8 Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Tue, 14 Mar 2017 21:28:42 +0100 Subject: [PATCH] nrf5/modules/ubluepy: Create new adv report list for each individual scan. Create a new ScanEntry object instance on each advertisment event recieved and append this to the current adv_report list. --- nrf5/modules/ubluepy/ubluepy_scanner.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nrf5/modules/ubluepy/ubluepy_scanner.c b/nrf5/modules/ubluepy/ubluepy_scanner.c index 8b3545bb57..393d1f1f00 100644 --- a/nrf5/modules/ubluepy/ubluepy_scanner.c +++ b/nrf5/modules/ubluepy/ubluepy_scanner.c @@ -38,7 +38,10 @@ STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_data_t * data) { ubluepy_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_obj_list_append(self->adv_reports, MP_OBJ_NEW_SMALL_INT(event_id)); // TODO: Swap out with ScanEntry + ubluepy_scan_entry_obj_t * item = m_new_obj(ubluepy_scan_entry_obj_t); + item->base.type = &ubluepy_scan_entry_type; + + mp_obj_list_append(self->adv_reports, item); (void)self; } @@ -61,8 +64,6 @@ STATIC mp_obj_t ubluepy_scanner_make_new(const mp_obj_type_t *type, size_t n_arg ubluepy_scanner_obj_t * s = m_new_obj(ubluepy_scanner_obj_t); s->base.type = type; - s->adv_reports = mp_obj_new_list(0, NULL); - return MP_OBJ_FROM_PTR(s); } @@ -74,6 +75,8 @@ STATIC mp_obj_t scanner_scan(mp_obj_t self_in, mp_obj_t timeout_in) { ubluepy_scanner_obj_t * self = MP_OBJ_TO_PTR(self_in); mp_int_t timeout = mp_obj_get_int(timeout_in); + self->adv_reports = mp_obj_new_list(0, NULL); + ble_drv_adv_report_handler_set(MP_OBJ_FROM_PTR(self), adv_event_handler); // start