summaryrefslogtreecommitdiff
path: root/shared-module/bleio
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-06-18 23:46:20 -0400
committerDan Halbert <halbert@halwitz.org>2019-06-18 23:46:20 -0400
commit35b919185747c42e183ccfc41f99fd370acca450 (patch)
tree5c1a383a99c53592c16daed8c61f84a4176d99f0 /shared-module/bleio
parent1356819de195810da09b5fc051ef5cc9dc21b2f4 (diff)
Don't operate directly on bleio objects in shared-bindings: use common_hal
routines instead. Changes made but not yet tested.
Diffstat (limited to 'shared-module/bleio')
-rw-r--r--shared-module/bleio/Address.c (renamed from shared-module/bleio/Scanner.h)26
-rw-r--r--shared-module/bleio/Address.h2
-rw-r--r--shared-module/bleio/Characteristic.h1
-rw-r--r--shared-module/bleio/ScanEntry.c (renamed from shared-module/bleio/Service.h)35
-rw-r--r--shared-module/bleio/ScanEntry.h3
5 files changed, 41 insertions, 26 deletions
diff --git a/shared-module/bleio/Scanner.h b/shared-module/bleio/Address.c
index 76f5e5866..e26bbe2ac 100644
--- a/shared-module/bleio/Scanner.h
+++ b/shared-module/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
@@ -24,16 +25,21 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H
-#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H
+#include <string.h>
-#include "py/obj.h"
+#include "py/objproperty.h"
+#include "shared-bindings/bleio/Address.h"
+#include "shared-module/bleio/Address.h"
-typedef struct {
- mp_obj_base_t base;
- mp_obj_t adv_reports;
- uint16_t interval;
- uint16_t window;
-} bleio_scanner_obj_t;
+void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type) {
+ memcpy(self->bytes, bytes, bytes_length);
+ self->type = address_type;
+}
-#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H
+mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self) {
+ return mp_obj_new_bytes(self->bytes, NUM_BLEIO_ADDRESS_BYTES);
+}
+
+uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self) {
+ return self->type;
+}
diff --git a/shared-module/bleio/Address.h b/shared-module/bleio/Address.h
index 65f493c16..f66e97d64 100644
--- a/shared-module/bleio/Address.h
+++ b/shared-module/bleio/Address.h
@@ -27,6 +27,8 @@
#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H
#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H
+#include "py/obj.h"
+
#define NUM_BLEIO_ADDRESS_BYTES 6
typedef struct {
diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h
index 958837e64..3132fd47b 100644
--- a/shared-module/bleio/Characteristic.h
+++ b/shared-module/bleio/Characteristic.h
@@ -37,5 +37,6 @@ typedef struct {
bool indicate : 1;
} bleio_characteristic_properties_t;
+// bleio_characteristic_obj_t is defined in ports/*/common-hal.
#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H
diff --git a/shared-module/bleio/Service.h b/shared-module/bleio/ScanEntry.c
index 828d4cdc8..44b50a4ce 100644
--- a/shared-module/bleio/Service.h
+++ b/shared-module/bleio/ScanEntry.c
@@ -3,7 +3,9 @@
*
* The MIT License (MIT)
*
+ * Copyright (c) 2019 Dan Halbert for Adafruit Industries
* Copyright (c) 2018 Artur Pacholec
+ * 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
@@ -24,21 +26,24 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H
-#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H
+#include <string.h>
-#include "common-hal/bleio/UUID.h"
+#include "shared-bindings/bleio/Address.h"
+#include "shared-module/bleio/Address.h"
+#include "shared-module/bleio/ScanEntry.h"
-typedef struct {
- mp_obj_base_t base;
- uint16_t handle;
- bool is_secondary;
- bleio_uuid_obj_t *uuid;
- // May be a Peripheral, Central, etc.
- mp_obj_t *device;
- mp_obj_t char_list;
- uint16_t start_handle;
- uint16_t end_handle;
-} bleio_service_obj_t;
+mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self) {
+ 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);
+}
-#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H
+mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self) {
+ return self->data;
+}
+
+mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self) {
+ return self->rssi;
+}
diff --git a/shared-module/bleio/ScanEntry.h b/shared-module/bleio/ScanEntry.h
index 6ae7334a8..40e02f9fa 100644
--- a/shared-module/bleio/ScanEntry.h
+++ b/shared-module/bleio/ScanEntry.h
@@ -27,7 +27,8 @@
#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H
#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H
-#include "shared-module/bleio/Address.h"
+#include "py/obj.h"
+#include "shared-bindings/bleio/Address.h"
typedef struct {
mp_obj_base_t base;