27
27
28
28
29
29
* Author(s): Scott Shawcroft
30
-
31
- Implementation Notes
32
- --------------------
33
-
34
- **Hardware:**
35
-
36
- .. todo:: Add links to any specific hardware product page(s), or category page(s). Use unordered list & hyperlink rST
37
- inline format: "* `Link Text <url>`_"
38
-
39
- **Software and Dependencies:**
40
-
41
- * Adafruit CircuitPython firmware for the supported boards:
42
- https://github.com/adafruit/circuitpython/releases
43
- * Adafruit's BLE library: https://github.com/adafruit/Adafruit_CircuitPython_BLE
44
30
"""
45
31
32
+ import struct
33
+ import time
46
34
import adafruit_ble
47
35
from adafruit_ble .advertising import Advertisement , LazyObjectField
48
36
from adafruit_ble .advertising .standard import ManufacturerData , ManufacturerDataField
49
37
from micropython import const
50
- import struct
51
- import time
52
38
53
39
__version__ = "0.0.0-auto.0"
54
40
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_BroadcastNet.git"
55
41
56
- _ble = adafruit_ble .BLERadio ()
57
- _sequence_number = 0
42
+ _ble = adafruit_ble .BLERadio () # pylint: disable=invalid-name
43
+ _sequence_number = 0 # pylint: disable=invalid-name
58
44
59
45
60
46
def broadcast (measurement , * , broadcast_time = 0.1 , extended = False ):
61
47
"""Broadcasts the given measurement for the given broadcast time. If extended is False and the
62
- measurement would be too long, it will be split into multiple measurements for transmission."""
63
- global _sequence_number
48
+ measurement would be too long, it will be split into multiple measurements for transmission.
49
+ """
50
+ global _sequence_number # pylint: disable=global-statement,invalid-name
64
51
for submeasurement in measurement .split (252 if extended else 31 ):
65
52
submeasurement .sequence_number = _sequence_number
66
53
_ble .start_advertising (submeasurement , scan_response = None )
@@ -69,9 +56,12 @@ def broadcast(measurement, *, broadcast_time=0.1, extended=False):
69
56
_sequence_number = (_sequence_number + 1 ) % 256
70
57
71
58
72
- device_address = "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}" .format (
73
- * _ble ._adapter .address .address_bytes
59
+ device_address = "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}" .format ( # pylint: disable=invalid-name
60
+ * reversed (
61
+ list (_ble ._adapter .address .address_bytes )
62
+ ) # pylint: disable=protected-access
74
63
)
64
+ """Device address as a string."""
75
65
76
66
_MANUFACTURING_DATA_ADT = const (0xFF )
77
67
_ADAFRUIT_COMPANY_ID = const (0x0822 )
@@ -140,10 +130,10 @@ class AdafruitSensorMeasurement(Advertisement):
140
130
"""Color as RGB integer."""
141
131
142
132
# alarm = ManufacturerDataField(0x0a0f, "<f")
143
- """Alarm as a start date and time and recurrence period. Not supported."""
133
+ # """Alarm as a start date and time and recurrence period. Not supported."""
144
134
145
135
# datetime = ManufacturerDataField(0x0a10, "<f")
146
- """Date and time as a struct. Not supported."""
136
+ # """Date and time as a struct. Not supported."""
147
137
148
138
duty_cycle = ManufacturerDataField (0x0A11 , "<f" )
149
139
"""16-bit PWM duty cycle. Independent of frequency."""
@@ -177,6 +167,8 @@ def __str__(self):
177
167
return "<{} {} >" .format (self .__class__ .__name__ , " " .join (parts ))
178
168
179
169
def split (self , max_packet_size = 31 ):
170
+ """Split the measurement into multiple measurements with the given max_packet_size. Yields
171
+ each submeasurement."""
180
172
current_size = 8 # baseline for mfg data and sequence number
181
173
if current_size + len (self .manufacturer_data ) < max_packet_size :
182
174
yield self
0 commit comments