summaryrefslogtreecommitdiff
path: root/shared-bindings/bleio
diff options
context:
space:
mode:
Diffstat (limited to 'shared-bindings/bleio')
-rw-r--r--shared-bindings/bleio/Address.c10
-rw-r--r--shared-bindings/bleio/Address.h5
-rw-r--r--shared-bindings/bleio/Characteristic.c22
-rw-r--r--shared-bindings/bleio/Characteristic.h5
-rw-r--r--shared-bindings/bleio/CharacteristicBuffer.c3
-rw-r--r--shared-bindings/bleio/Device.h2
-rw-r--r--shared-bindings/bleio/Peripheral.c25
-rw-r--r--shared-bindings/bleio/Peripheral.h4
-rw-r--r--shared-bindings/bleio/ScanEntry.c24
-rw-r--r--shared-bindings/bleio/ScanEntry.h5
-rw-r--r--shared-bindings/bleio/Scanner.c6
-rw-r--r--shared-bindings/bleio/Scanner.h6
-rw-r--r--shared-bindings/bleio/Service.c24
-rw-r--r--shared-bindings/bleio/Service.h8
14 files changed, 80 insertions, 69 deletions
diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c
index 7367da535..5875cf9bd 100644
--- a/shared-bindings/bleio/Address.c
+++ b/shared-bindings/bleio/Address.c
@@ -3,6 +3,7 @@
*
* The MIT License (MIT)
*
+ * Copyright (c) 2019 Dan Halbert for Adafruit Industries
* Copyright (c) 2018 Artur Pacholec
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -74,13 +75,12 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args,
mp_raise_ValueError_varg(translate("Address must be %d bytes long"), NUM_BLEIO_ADDRESS_BYTES);
}
- memcpy(self->bytes, buf_info.buf, buf_info.len);
-
const mp_int_t address_type = args[ARG_address_type].u_int;
if (address_type < BLEIO_ADDRESS_TYPE_MIN || address_type > BLEIO_ADDRESS_TYPE_MAX) {
mp_raise_ValueError(translate("Address type out of range"));
}
- self->type = address_type;
+
+ common_hal_bleio_address_construct(self, buf_info.buf, buf_info.len, address_type);
return MP_OBJ_FROM_PTR(self);
}
@@ -97,7 +97,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args,
STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) {
bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bytes(self->bytes, NUM_BLEIO_ADDRESS_BYTES);
+ return common_hal_bleio_address_get_address_bytes(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_address_bytes_obj, bleio_address_get_address_bytes);
@@ -113,7 +113,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_address_bytes_obj, bleio_address_get
STATIC mp_obj_t bleio_address_get_type(mp_obj_t self_in) {
bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return MP_OBJ_NEW_SMALL_INT(self->type);
+ return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_address_get_type(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_type_obj, bleio_address_get_type);
diff --git a/shared-bindings/bleio/Address.h b/shared-bindings/bleio/Address.h
index ef84d7432..9652a9841 100644
--- a/shared-bindings/bleio/Address.h
+++ b/shared-bindings/bleio/Address.h
@@ -28,6 +28,7 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADDRESS_H
#include "py/objtype.h"
+#include "shared-module/bleio/Address.h"
#define BLEIO_ADDRESS_TYPE_PUBLIC (0)
#define BLEIO_ADDRESS_TYPE_RANDOM_STATIC (1)
@@ -39,4 +40,8 @@
extern const mp_obj_type_t bleio_address_type;
+extern void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type);
+extern mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self);
+extern uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self);
+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADDRESS_H
diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c
index ae83de864..e48cfd433 100644
--- a/shared-bindings/bleio/Characteristic.c
+++ b/shared-bindings/bleio/Characteristic.c
@@ -73,10 +73,10 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t
if (!MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) {
mp_raise_ValueError(translate("Expected a UUID"));
}
+ bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid);
bleio_characteristic_obj_t *self = m_new_obj(bleio_characteristic_obj_t);
self->base.type = &bleio_characteristic_type;
- self->uuid = MP_OBJ_TO_PTR(uuid);
bleio_characteristic_properties_t properties;
@@ -87,7 +87,7 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t
properties.write = args[ARG_write].u_bool;
properties.write_no_response = args[ARG_write_no_response].u_bool;
- common_hal_bleio_characteristic_construct(self, uuid, properties);
+ common_hal_bleio_characteristic_construct(self, uuid_obj, properties);
return MP_OBJ_FROM_PTR(self);
}
@@ -99,7 +99,7 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t
STATIC mp_obj_t bleio_characteristic_get_broadcast(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(self->props.broadcast);
+ return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).broadcast);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_broadcast_obj, bleio_characteristic_get_broadcast);
@@ -117,7 +117,7 @@ const mp_obj_property_t bleio_characteristic_broadcast_obj = {
STATIC mp_obj_t bleio_characteristic_get_indicate(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(self->props.indicate);
+ return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).indicate);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_indicate_obj, bleio_characteristic_get_indicate);
@@ -136,7 +136,7 @@ const mp_obj_property_t bleio_characteristic_indicate_obj = {
STATIC mp_obj_t bleio_characteristic_get_notify(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(self->props.notify);
+ return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).notify);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_notify_obj, bleio_characteristic_get_notify);
@@ -154,7 +154,7 @@ const mp_obj_property_t bleio_characteristic_notify_obj = {
STATIC mp_obj_t bleio_characteristic_get_read(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(self->props.read);
+ return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).read);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_read_obj, bleio_characteristic_get_read);
@@ -172,7 +172,7 @@ const mp_obj_property_t bleio_characteristic_read_obj = {
STATIC mp_obj_t bleio_characteristic_get_write(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(self->props.write);
+ return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).write);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_write_obj, bleio_characteristic_get_write);
@@ -190,7 +190,7 @@ const mp_obj_property_t bleio_characteristic_write_obj = {
STATIC mp_obj_t bleio_characteristic_get_write_no_response(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(self->props.write_no_response);
+ return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).write_no_response);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_write_no_response_obj, bleio_characteristic_get_write_no_response);
@@ -208,7 +208,7 @@ const mp_obj_property_t bleio_characteristic_write_no_response_obj = {
STATIC mp_obj_t bleio_characteristic_get_uuid(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return MP_OBJ_FROM_PTR(self->uuid);
+ return MP_OBJ_FROM_PTR(common_hal_bleio_characteristic_get_uuid(self));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_uuid_obj, bleio_characteristic_get_uuid);
@@ -228,9 +228,7 @@ const mp_obj_property_t bleio_characteristic_uuid_obj = {
STATIC mp_obj_t bleio_characteristic_get_value(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
- common_hal_bleio_characteristic_get_value(self);
-
- return self->value_data;
+ return common_hal_bleio_characteristic_get_value(self);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_value_obj, bleio_characteristic_get_value);
diff --git a/shared-bindings/bleio/Characteristic.h b/shared-bindings/bleio/Characteristic.h
index 206cbcd40..ffee6bdbc 100644
--- a/shared-bindings/bleio/Characteristic.h
+++ b/shared-bindings/bleio/Characteristic.h
@@ -32,7 +32,10 @@
extern const mp_obj_type_t bleio_characteristic_type;
extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props);
-extern void common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self);
+extern void common_hal_bleio_characteristic_set_service(bleio_characteristic_obj_t *self, bleio_service_obj_t *service);
+extern mp_obj_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self);
extern void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo);
+extern bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self);
+extern bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H
diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c
index a1dc663fd..da79c5d7a 100644
--- a/shared-bindings/bleio/CharacteristicBuffer.c
+++ b/shared-bindings/bleio/CharacteristicBuffer.c
@@ -85,9 +85,8 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type,
bleio_characteristic_buffer_obj_t *self = m_new_obj(bleio_characteristic_buffer_obj_t);
self->base.type = &bleio_characteristic_buffer_type;
- self->characteristic = MP_OBJ_TO_PTR(characteristic);
- common_hal_bleio_characteristic_buffer_construct(self, self->characteristic, timeout, buffer_size);
+ common_hal_bleio_characteristic_buffer_construct(self, characteristic, timeout, buffer_size);
return MP_OBJ_FROM_PTR(self);
}
diff --git a/shared-bindings/bleio/Device.h b/shared-bindings/bleio/Device.h
index 1f85abe9a..e452a8ad6 100644
--- a/shared-bindings/bleio/Device.h
+++ b/shared-bindings/bleio/Device.h
@@ -28,7 +28,7 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H
#include "shared-module/bleio/Device.h"
-#include "shared-module/bleio/Service.h"
+#include "common-hal/bleio/Service.h"
extern const mp_obj_type_t bleio_device_type;
diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c
index 4492a8e26..5397f4c3a 100644
--- a/shared-bindings/bleio/Peripheral.c
+++ b/shared-bindings/bleio/Peripheral.c
@@ -101,32 +101,33 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar
// If services is not an iterable, an exception will be thrown.
mp_obj_iter_buf_t iter_buf;
mp_obj_t iterable = mp_getiter(args[ARG_services].u_obj, &iter_buf);
- mp_obj_t service;
bleio_peripheral_obj_t *self = m_new_obj(bleio_peripheral_obj_t);
self->base.type = &bleio_peripheral_type;
- self->service_list = mp_obj_new_list(0, NULL);
- self->notif_handler = mp_const_none;
+
+ // Copy the services list and validate its items.
+ mp_obj_t service_list = mp_obj_new_list(0, NULL);
+ mp_obj_list_t *service_list_obj = MP_OBJ_FROM_PTR(service_list);
+
+ mp_obj_t service;
while ((service = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
if (!MP_OBJ_IS_TYPE(service, &bleio_service_type)) {
mp_raise_ValueError(translate("services includes an object that is not a Service"));
}
- bleio_service_obj_t *service_ptr = MP_OBJ_TO_PTR(service);
- service_ptr->device = MP_OBJ_FROM_PTR(self);
- mp_obj_list_append(self->service_list, service);
+ mp_obj_list_append(service_list, service);
}
const mp_obj_t name = args[ARG_name].u_obj;
+ mp_obj_t name_str;
if (name == MP_OBJ_NULL || name == mp_const_none) {
- self->name = mp_obj_new_str(default_name, strlen(default_name));
+ name_str = mp_obj_new_str(default_name, strlen(default_name));
} else if (MP_OBJ_IS_STR(name)) {
- self->name = name;
+ name_str = name;
} else {
mp_raise_ValueError(translate("name must be a string"));
}
- // Do port-specific initialization.
- common_hal_bleio_peripheral_construct(self);
+ common_hal_bleio_peripheral_construct(self, service_list_obj, name_str);
return MP_OBJ_FROM_PTR(self);
}
@@ -157,7 +158,7 @@ const mp_obj_property_t bleio_peripheral_connected_obj = {
STATIC mp_obj_t bleio_peripheral_get_services(mp_obj_t self_in) {
bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
// Return list as a tuple so user won't be able to change it.
- mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list);
+ mp_obj_list_t *service_list = common_hal_bleio_peripheral_get_service_list(self);
return mp_obj_new_tuple(service_list->len, service_list->items);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_get_services_obj, bleio_peripheral_get_services);
@@ -176,7 +177,7 @@ const mp_obj_property_t bleio_peripheral_services_obj = {
STATIC mp_obj_t bleio_peripheral_get_name(mp_obj_t self_in) {
bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return self->name;
+ return common_hal_bleio_peripheral_get_name(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_get_name_obj, bleio_peripheral_get_name);
diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h
index 7ef45edcd..6468325c2 100644
--- a/shared-bindings/bleio/Peripheral.h
+++ b/shared-bindings/bleio/Peripheral.h
@@ -32,8 +32,10 @@
extern const mp_obj_type_t bleio_peripheral_type;
-extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self);
+extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self, mp_obj_list_t *service_list, mp_obj_t name);
+extern mp_obj_list_t *common_hal_bleio_peripheral_get_service_list(bleio_peripheral_obj_t *self);
extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self);
+extern mp_obj_t common_hal_bleio_peripheral_get_name(bleio_peripheral_obj_t *self);
extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, float interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo);
extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device);
diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c
index f66b3df4b..145d2b023 100644
--- a/shared-bindings/bleio/ScanEntry.c
+++ b/shared-bindings/bleio/ScanEntry.c
@@ -3,6 +3,7 @@
*
* The MIT License (MIT)
*
+ * Copyright (c) 2019 Dan Halbert for Adafruit Industries
* Copyright (c) 2018 Artur Pacholec
* Copyright (c) 2017 Glenn Ruben Bakke
*
@@ -27,10 +28,7 @@
#include <string.h>
-#include "py/objarray.h"
#include "py/objproperty.h"
-#include "py/objstr.h"
-#include "py/objtuple.h"
#include "shared-bindings/bleio/Address.h"
#include "shared-bindings/bleio/ScanEntry.h"
#include "shared-bindings/bleio/UUID.h"
@@ -53,18 +51,13 @@
//|
STATIC mp_obj_t bleio_scanentry_get_address(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
-
- bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t);
- address->base.type = &bleio_address_type;
- memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES);
- address->type = self->address.type;
- return MP_OBJ_TO_PTR(address);
+ return common_hal_bleio_scanentry_get_address(self);
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scanentry_get_address_obj, bleio_scanentry_get_address);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_address_obj, bleio_scanentry_get_address);
const mp_obj_property_t bleio_scanentry_address_obj = {
.base.type = &mp_type_property,
- .proxy = { (mp_obj_t)&bluepy_scanentry_get_address_obj,
+ .proxy = { (mp_obj_t)&bleio_scanentry_get_address_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
@@ -75,7 +68,7 @@ const mp_obj_property_t bleio_scanentry_address_obj = {
//|
STATIC mp_obj_t scanentry_get_raw_data(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return self->data;
+ return common_hal_bleio_scanentry_get_raw_data(self);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_raw_data_obj, scanentry_get_raw_data);
@@ -92,14 +85,13 @@ const mp_obj_property_t bleio_scanentry_raw_data_obj = {
//|
STATIC mp_obj_t scanentry_get_rssi(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
-
- return mp_obj_new_int(self->rssi);
+ return mp_obj_new_int(common_hal_bleio_scanentry_get_rssi(self));
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scanentry_get_rssi_obj, scanentry_get_rssi);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_rssi_obj, scanentry_get_rssi);
const mp_obj_property_t bleio_scanentry_rssi_obj = {
.base.type = &mp_type_property,
- .proxy = { (mp_obj_t)&bluepy_scanentry_get_rssi_obj,
+ .proxy = { (mp_obj_t)&bleio_scanentry_get_rssi_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
diff --git a/shared-bindings/bleio/ScanEntry.h b/shared-bindings/bleio/ScanEntry.h
index 2b44ba3f4..c1b52e6b4 100644
--- a/shared-bindings/bleio/ScanEntry.h
+++ b/shared-bindings/bleio/ScanEntry.h
@@ -29,7 +29,12 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H
#include "py/obj.h"
+#include "shared-module/bleio/ScanEntry.h"
extern const mp_obj_type_t bleio_scanentry_type;
+mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self);
+mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self);
+mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self);
+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H
diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c
index a249d5343..92f6a2a18 100644
--- a/shared-bindings/bleio/Scanner.c
+++ b/shared-bindings/bleio/Scanner.c
@@ -61,6 +61,8 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args,
bleio_scanner_obj_t *self = m_new_obj(bleio_scanner_obj_t);
self->base.type = type;
+ common_hal_bleio_scanner_construct(self);
+
return MP_OBJ_FROM_PTR(self);
}
@@ -108,11 +110,9 @@ STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_m
mp_raise_ValueError(translate("window must be <= interval"));
}
- self->adv_reports = mp_obj_new_list(0, NULL);
-
common_hal_bleio_scanner_scan(self, timeout, interval, window);
- return self->adv_reports;
+ return common_hal_bleio_scanner_get_adv_reports(self);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan);
diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h
index 54c09675b..b9e3ecdee 100644
--- a/shared-bindings/bleio/Scanner.h
+++ b/shared-bindings/bleio/Scanner.h
@@ -29,11 +29,13 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H
#include "py/objtype.h"
-#include "shared-module/bleio/Scanner.h"
+#include "common-hal/bleio/Scanner.h"
extern const mp_obj_type_t bleio_scanner_type;
-void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window);
+extern void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self);
+extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window);
extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self);
+extern mp_obj_t common_hal_bleio_scanner_get_adv_reports(bleio_scanner_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H
diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c
index d9bc4021f..352ef8d6a 100644
--- a/shared-bindings/bleio/Service.c
+++ b/shared-bindings/bleio/Service.c
@@ -67,18 +67,20 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args,
}
bleio_service_obj_t *self = m_new_obj(bleio_service_obj_t);
- self->char_list = mp_obj_new_list(0, NULL);
self->base.type = &bleio_service_type;
- self->device = mp_const_none;
- self->handle = 0xFFFF;
- self->is_secondary = args[ARG_secondary].u_bool;
- self->uuid = MP_OBJ_TO_PTR(uuid);
+
+ const bool is_secondary = args[ARG_secondary].u_bool;
+ bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid);
// If characteristics is not an iterable, an exception will be thrown.
mp_obj_iter_buf_t iter_buf;
mp_obj_t iterable = mp_getiter(args[ARG_characteristics].u_obj, &iter_buf);
mp_obj_t characteristic;
+ // Copy the characteristics list and validate its items.
+ mp_obj_t char_list = mp_obj_new_list(0, NULL);
+ mp_obj_list_t *char_list_obj = MP_OBJ_FROM_PTR(char_list);
+
while ((characteristic = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
if (!MP_OBJ_IS_TYPE(characteristic, &bleio_characteristic_type)) {
mp_raise_ValueError(translate("characteristics includes an object that is not a Characteristic"));
@@ -89,12 +91,10 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args,
// The descriptor base UUID doesn't match the characteristic base UUID.
mp_raise_ValueError(translate("Characteristic UUID doesn't match Service UUID"));
}
- characteristic_ptr->service = self;
- mp_obj_list_append(self->char_list, characteristic);
+ mp_obj_list_append(char_list, characteristic);
}
- // Do port-specific initialization.
- common_hal_bleio_service_construct(self);
+ common_hal_bleio_service_construct(self, uuid_obj, char_list_obj, is_secondary);
return MP_OBJ_FROM_PTR(self);
}
@@ -106,7 +106,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args,
STATIC mp_obj_t bleio_service_get_characteristics(mp_obj_t self_in) {
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);
// Return list as a tuple so user won't be able to change it.
- mp_obj_list_t *char_list = MP_OBJ_TO_PTR(self->char_list);
+ mp_obj_list_t *char_list = common_hal_bleio_service_get_characteristic_list(self);
return mp_obj_new_tuple(char_list->len, char_list->items);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_characteristics_obj, bleio_service_get_characteristics);
@@ -125,7 +125,7 @@ const mp_obj_property_t bleio_service_characteristics_obj = {
STATIC mp_obj_t bleio_service_get_secondary(mp_obj_t self_in) {
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(self->is_secondary);
+ return mp_obj_new_bool(common_hal_bleio_service_get_is_secondary(self));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_secondary_obj, bleio_service_get_secondary);
@@ -143,7 +143,7 @@ const mp_obj_property_t bleio_service_secondary_obj = {
STATIC mp_obj_t bleio_service_get_uuid(mp_obj_t self_in) {
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return MP_OBJ_FROM_PTR(self->uuid);
+ return MP_OBJ_FROM_PTR(common_hal_bleio_service_get_uuid(self));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_uuid_obj, bleio_service_get_uuid);
diff --git a/shared-bindings/bleio/Service.h b/shared-bindings/bleio/Service.h
index 389db3b2e..27d79f953 100644
--- a/shared-bindings/bleio/Service.h
+++ b/shared-bindings/bleio/Service.h
@@ -28,11 +28,15 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H
#include "shared-module/bleio/Characteristic.h"
-#include "shared-module/bleio/Service.h"
+#include "common-hal/bleio/Service.h"
const mp_obj_type_t bleio_service_type;
-extern void common_hal_bleio_service_construct(bleio_service_obj_t *self);
+extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, mp_obj_list_t *char_list, bool is_secondary);
+extern bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self);
+extern mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self);
+extern bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self);
+extern void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t device);
extern void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H