Skip to content

Commit d31a9c2

Browse files
committed
fix doc build; fix advertising; new examples; a few bugs
1 parent 9147c16 commit d31a9c2

12 files changed

+150
-39
lines changed

adafruit_ble_adafruit/adafruit_service.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,16 @@
6464

6565
class AdafruitServerAdvertisement(Advertisement):
6666
"""Advertise the Adafruit company ID and the board USB PID.
67-
68-
:param pid: The USB PID (product id) for this board
6967
"""
7068

71-
prefix = struct.pack("<BBH", 0x3, _MANUFACTURING_DATA_ADT, _ADAFRUIT_COMPANY_ID)
69+
prefix = struct.pack(
70+
"<BBHBH",
71+
0x6,
72+
_MANUFACTURING_DATA_ADT,
73+
_ADAFRUIT_COMPANY_ID,
74+
struct.calcsize("<HH"),
75+
_PID_DATA_ID,
76+
)
7277
manufacturer_data = LazyObjectField(
7378
ManufacturerData,
7479
"manufacturer_data",
@@ -77,13 +82,17 @@ class AdafruitServerAdvertisement(Advertisement):
7782
key_encoding="<H",
7883
)
7984
pid = ManufacturerDataField(_PID_DATA_ID, "<H")
85+
"""The USB PID (product id) for this board."""
8086

81-
def __init__(self, pid):
87+
def __init__(self):
8288
super().__init__()
8389
self.connectable = True
8490
self.flags.general_discovery = True
8591
self.flags.le_only = True
86-
self.pid = pid
92+
93+
@classmethod
94+
def matches(cls, entry):
95+
return entry.matches(cls.prefix, all=False)
8796

8897

8998
class AdafruitService(Service):

adafruit_ble_adafruit/humidity_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222
"""
23-
`adafruit_ble_adafruit.humdity_service`
23+
`adafruit_ble_adafruit.humidity_service`
2424
================================================================================
2525
2626
BLE access to humidity data.

adafruit_ble_adafruit/quaternion_service.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class QuaternionService(AdafruitService): # pylint: disable=too-few-public-meth
5656
properties=(Characteristic.READ | Characteristic.NOTIFY),
5757
write_perm=Attribute.NO_ACCESS,
5858
)
59-
"""9-tuple of floats sent to client for calibration calculation:
60-
(acceleration x, y, z, # in m/s^2
61-
gyro x, y, z, # in rad/s
62-
magnetic x, y, z, # in microteslas
63-
)
59+
"""
60+
9-tuple of floats sent to client for calibration calculation:
61+
acceleration x, y, z, # in m/s^2
62+
gyro x, y, z, # in rad/s
63+
magnetic x, y, z, # in microteslas
6464
"""
6565

6666
calibration_out = StructCharacteristic(
@@ -69,13 +69,13 @@ class QuaternionService(AdafruitService): # pylint: disable=too-few-public-meth
6969
properties=(Characteristic.WRITE),
7070
read_perm=Attribute.NO_ACCESS,
7171
)
72-
"""19-tuple of floats sent back to server after calibration calculation
73-
(acceleration_zerog x, y, z, # in m/s^2
74-
gyro_zerorate x, y, z, # in rad/s
75-
magnetic_hardiron x, y, z, # in microteslas
76-
magnetic_field f, # in microteslas
77-
magnetic_softiron v1, v2, v3, v4, v5, v6, v7, v8, v9, # unitless
78-
)
72+
"""
73+
19-tuple of floats sent back to server after calibration calculation:
74+
acceleration_zerog x, y, z, # in m/s^2
75+
gyro_zerorate x, y, z, # in rad/s
76+
magnetic_hardiron x, y, z, # in microteslas
77+
magnetic_field f, # in microteslas
78+
magnetic_softiron v1, v2, v3, v4, v5, v6, v7, v8, v9, # unitless
7979
"""
8080

8181
# TO DO: Calibration calculations and storage

docs/api.rst

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
1-
.. automodule:: adafruit_ble_adafruit
1+
.. If you created a package, create one automodule per module in the package.
2+
3+
.. automodule:: adafruit_ble_adafruit.accelerometer_service
4+
:members:
5+
6+
.. automodule:: adafruit_ble_adafruit.adafruit_service
7+
:members:
8+
9+
.. automodule:: adafruit_ble_adafruit.addressable_pixel_service
10+
:members:
11+
12+
.. automodule:: adafruit_ble_adafruit.barometric_pressure_service
13+
:members:
14+
15+
.. automodule:: adafruit_ble_adafruit.button_service
16+
:members:
17+
18+
.. automodule:: adafruit_ble_adafruit.color_sensor_service
19+
:members:
20+
21+
.. automodule:: adafruit_ble_adafruit.gesture_service
22+
:members:
23+
24+
.. automodule:: adafruit_ble_adafruit.gyroscope_service
25+
:members:
26+
27+
.. automodule:: adafruit_ble_adafruit.humidity_service
28+
:members:
29+
30+
.. automodule:: adafruit_ble_adafruit.light_sensor_service
31+
:members:
32+
33+
.. automodule:: adafruit_ble_adafruit.magnetometer_service
34+
:members:
35+
36+
.. automodule:: adafruit_ble_adafruit.microphone_service
37+
:members:
38+
39+
.. automodule:: adafruit_ble_adafruit.proximity_service
40+
:members:
41+
42+
.. automodule:: adafruit_ble_adafruit.quaternion_service
43+
:members:
44+
45+
.. automodule:: adafruit_ble_adafruit.temperature_service
46+
:members:
47+
48+
.. automodule:: adafruit_ble_adafruit.tone_service
249
:members:

docs/conf.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,10 @@
1717
"sphinx.ext.todo",
1818
]
1919

20-
# TODO: Please Read!
2120
# Uncomment the below if you use native CircuitPython modules such as
2221
# digitalio, micropython and busio. List the modules you use. Without it, the
2322
# autodoc module docs will fail to generate with a warning.
24-
autodoc_mock_imports = [
25-
"_bleio",
26-
"adafruit_ble_adafruit",
27-
"board",
28-
"digitalio",
29-
"busio",
30-
"ulab",
31-
"micropython",
32-
"adafruit_clue",
33-
"neopixel_write",
34-
"adafruit_circuitplayground",
35-
]
23+
autodoc_mock_imports = ["microcontroller"]
3624

3725

3826
intersphinx_mapping = {

examples/ble_adafruit_circuitplayground_bluefruit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
# in the advertisement. That data uses the USB PID as a unique ID.
5757
# Adafruit Circuit Playground Bluefruit USB PID:
5858
# Arduino: 0x8045, CircuitPython: 0x8046, app supports either
59-
adv = AdafruitServerAdvertisement(0x8046)
59+
adv = AdafruitServerAdvertisement()
60+
adv.pin = 0x8046
6061

6162
while True:
6263
# Advertise when not connected.

examples/ble_adafruit_clue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
# in the advertisement. That data uses the USB PID as a unique ID.
7777
# Adafruit CLUE USB PID:
7878
# Arduino: 0x8071, CircuitPython: 0x8072, app supports either
79-
adv = AdafruitServerAdvertisement(0x8072)
79+
adv = AdafruitServerAdvertisement()
80+
adv.pin = 0x8072
8081

8182
while True:
8283
# Advertise when not connected.

examples/ble_adafruit_feather_bluefruit_sense.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Bluefruit Playground server program, to run on CLUE
1+
# Bluefruit Playground and Web Bluetooth Dashboard server program, to
2+
# run on Feather Bluefruit Sense
23

34
import time
45

@@ -95,7 +96,8 @@
9596
# Feather Bluefruit Sense USB PID:
9697
# This board is not yet support on the app.
9798
# Arduino: 0x8087, CircuitPython: 0x8088
98-
adv = AdafruitServerAdvertisement(0x8088)
99+
adv = AdafruitServerAdvertisement()
100+
adv.pin = 0x8088
99101

100102
while True:
101103
# Advertise when not connected.

examples/ble_adafruit_simpletest.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Use with Web Bluetooth Dashboard, or with ble_adafruit_simpletest_client.py
2+
3+
import time
4+
5+
import microcontroller
6+
7+
from adafruit_ble import BLERadio
8+
9+
from adafruit_ble_adafruit.adafruit_service import AdafruitServerAdvertisement
10+
from adafruit_ble_adafruit.temperature_service import TemperatureService
11+
12+
temp_svc = TemperatureService()
13+
temp_svc.measurement_period = 100
14+
temp_last_update = 0
15+
16+
ble = BLERadio()
17+
18+
# Unknown USB PID, since we don't know what board we're on
19+
adv = AdafruitServerAdvertisement()
20+
adv.pid = 0x0000
21+
22+
while True:
23+
# Advertise when not connected.
24+
print(adv)
25+
print(bytes(adv))
26+
ble.start_advertising(adv)
27+
while not ble.connected:
28+
pass
29+
ble.stop_advertising()
30+
31+
while ble.connected:
32+
now_msecs = time.monotonic_ns() // 1000000 # pylint: disable=no-member
33+
34+
if now_msecs - temp_last_update >= temp_svc.measurement_period:
35+
temp_svc.temperature = (
36+
microcontroller.cpu.temperature # pylint: disable=no-member
37+
)
38+
39+
temp_last_update = now_msecs
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import time
2+
3+
import adafruit_ble
4+
from adafruit_ble_adafruit.adafruit_service import AdafruitServerAdvertisement
5+
from adafruit_ble_adafruit.temperature_service import TemperatureService
6+
7+
# PyLint can't find BLERadio for some reason so special case it here.
8+
ble = adafruit_ble.BLERadio() # pylint: disable=no-member
9+
10+
connection = None
11+
12+
while True:
13+
print("Scanning for an Adafruit Server advertisement...")
14+
for adv in ble.start_scan(AdafruitServerAdvertisement, timeout=5):
15+
connection = ble.connect(adv)
16+
print("Connected")
17+
break
18+
19+
# Stop scanning whether or not we are connected.
20+
ble.stop_scan()
21+
22+
if connection and connection.connected:
23+
temp_service = connection[TemperatureService]
24+
while connection.connected:
25+
print("Temperature:", temp_service.temperature)
26+
time.sleep(1)

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
name="adafruit-circuitpython-ble-adafruit",
2222
use_scm_version=True,
2323
setup_requires=["setuptools_scm"],
24-
description="Description ",
24+
description="Access to sensors and hardware on or connected to BLE-capable boards",
2525
long_description=long_description,
2626
long_description_content_type="text/x-rst",
2727
# The project's main homepage.
@@ -47,7 +47,5 @@
4747
keywords="adafruit blinka circuitpython micropython circuitplayground bluefruit CLUE ble",
4848
# You can just specify the packages manually here if your project is
4949
# simple. Or you can use find_packages().
50-
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
51-
# CHANGE `py_modules=['...']` TO `packages=['...']`
5250
packages=["adafruit_ble_adafruit"],
5351
)

0 commit comments

Comments
 (0)