summaryrefslogtreecommitdiff
path: root/ports/nrf/modules
diff options
context:
space:
mode:
authorarturo182 <arturo182@tlen.pl>2018-07-18 10:22:11 +0200
committerarturo182 <arturo182@tlen.pl>2018-10-21 15:43:29 +0200
commit1c6bf9a15061d64ea097a024d73ad0a6da8f8e2b (patch)
treeac0a919e38d8324d7c7698f90d092e07b7e0536b /ports/nrf/modules
parent7390dc7dab2c5ccd34a1fa5a33e1e5241b8f9bd7 (diff)
bleio: Move the Scanner class to a shared module
Diffstat (limited to 'ports/nrf/modules')
-rw-r--r--ports/nrf/modules/ubluepy/modubluepy.c4
-rw-r--r--ports/nrf/modules/ubluepy/modubluepy.h6
-rw-r--r--ports/nrf/modules/ubluepy/ubluepy_scanner.c118
3 files changed, 0 insertions, 128 deletions
diff --git a/ports/nrf/modules/ubluepy/modubluepy.c b/ports/nrf/modules/ubluepy/modubluepy.c
index 034cc806c..e817983fa 100644
--- a/ports/nrf/modules/ubluepy/modubluepy.c
+++ b/ports/nrf/modules/ubluepy/modubluepy.c
@@ -33,7 +33,6 @@ extern const mp_obj_type_t ubluepy_service_type;
extern const mp_obj_type_t ubluepy_characteristic_type;
extern const mp_obj_type_t ubluepy_delegate_type;
extern const mp_obj_type_t ubluepy_constants_type;
-extern const mp_obj_type_t ubluepy_scanner_type;
STATIC const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubluepy) },
@@ -43,9 +42,6 @@ STATIC const mp_rom_map_elem_t mp_module_ubluepy_globals_table[] = {
#if 0 // MICROPY_PY_UBLUEPY_CENTRAL
{ MP_ROM_QSTR(MP_QSTR_Central), MP_ROM_PTR(&ubluepy_central_type) },
#endif
-#if MICROPY_PY_UBLUEPY_CENTRAL
- { MP_ROM_QSTR(MP_QSTR_Scanner), MP_ROM_PTR(&ubluepy_scanner_type) },
-#endif
{ MP_ROM_QSTR(MP_QSTR_DefaultDelegate), MP_ROM_PTR(&ubluepy_delegate_type) },
{ MP_ROM_QSTR(MP_QSTR_Service), MP_ROM_PTR(&ubluepy_service_type) },
{ MP_ROM_QSTR(MP_QSTR_Characteristic), MP_ROM_PTR(&ubluepy_characteristic_type) },
diff --git a/ports/nrf/modules/ubluepy/modubluepy.h b/ports/nrf/modules/ubluepy/modubluepy.h
index 8fb9fadd0..f51cc9e87 100644
--- a/ports/nrf/modules/ubluepy/modubluepy.h
+++ b/ports/nrf/modules/ubluepy/modubluepy.h
@@ -77,7 +77,6 @@ p.advertise(device_name="micr", services=[s])
extern const mp_obj_type_t ubluepy_service_type;
extern const mp_obj_type_t ubluepy_characteristic_type;
extern const mp_obj_type_t ubluepy_peripheral_type;
-extern const mp_obj_type_t ubluepy_scanner_type;
extern const mp_obj_type_t ubluepy_constants_type;
extern const mp_obj_type_t ubluepy_constants_ad_types_type;
@@ -147,11 +146,6 @@ typedef struct _ubluepy_advertise_data_t {
bool connectable;
} ubluepy_advertise_data_t;
-typedef struct _ubluepy_scanner_obj_t {
- mp_obj_base_t base;
- mp_obj_t adv_reports;
-} ubluepy_scanner_obj_t;
-
typedef enum _ubluepy_prop_t {
UBLUEPY_PROP_BROADCAST = 0x01,
UBLUEPY_PROP_READ = 0x02,
diff --git a/ports/nrf/modules/ubluepy/ubluepy_scanner.c b/ports/nrf/modules/ubluepy/ubluepy_scanner.c
deleted file mode 100644
index 9d15037a5..000000000
--- a/ports/nrf/modules/ubluepy/ubluepy_scanner.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2017 Glenn Ruben Bakke
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include <string.h>
-#include "py/obj.h"
-#include "py/runtime.h"
-#include "py/objstr.h"
-#include "py/objlist.h"
-#include "py/mphal.h"
-
-#if MICROPY_PY_UBLUEPY_CENTRAL
-
-#include "shared-bindings/bleio/ScanEntry.h"
-#include "ble_drv.h"
-
-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);
-
- // TODO: Don't add new entry for each item, group by address and update
- bleio_scanentry_obj_t *item = m_new_obj(bleio_scanentry_obj_t);
- item->base.type = &bleio_scanentry_type;
-
- item->rssi = data->rssi;
- item->data = mp_obj_new_bytearray(data->data_len, data->p_data);
-
- item->address.type = data->addr_type;
- memcpy(item->address.value, data->p_peer_addr, BLEIO_ADDRESS_BYTES);
-
- mp_obj_list_append(self->adv_reports, item);
-
- ble_drv_scan_continue();
-}
-
-STATIC void ubluepy_scanner_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
- ubluepy_scanner_obj_t * self = (ubluepy_scanner_obj_t *)o;
- (void)self;
- mp_printf(print, "Scanner");
-}
-
-STATIC mp_obj_t ubluepy_scanner_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
- static const mp_arg_t allowed_args[] = {
-
- };
-
- // parse args
- mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
- mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
-
- ubluepy_scanner_obj_t * s = m_new_obj(ubluepy_scanner_obj_t);
- s->base.type = type;
-
- return MP_OBJ_FROM_PTR(s);
-}
-
-/// \method scan(timeout)
-/// Scan for devices. Timeout is in milliseconds and will set the duration
-/// of the scanning.
-///
-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
- ble_drv_scan_start();
-
- // sleep
- mp_hal_delay_ms(timeout);
-
- // stop
- ble_drv_scan_stop();
-
- return self->adv_reports;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_scanner_scan_obj, scanner_scan);
-
-STATIC const mp_rom_map_elem_t ubluepy_scanner_locals_dict_table[] = {
- { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&ubluepy_scanner_scan_obj) },
-};
-
-STATIC MP_DEFINE_CONST_DICT(ubluepy_scanner_locals_dict, ubluepy_scanner_locals_dict_table);
-
-
-const mp_obj_type_t ubluepy_scanner_type = {
- { &mp_type_type },
- .name = MP_QSTR_Scanner,
- .print = ubluepy_scanner_print,
- .make_new = ubluepy_scanner_make_new,
- .locals_dict = (mp_obj_dict_t*)&ubluepy_scanner_locals_dict
-};
-
-#endif // MICROPY_PY_UBLUEPY_CENTRAL