Skip to content

Commit 3917670

Browse files
authored
Merge pull request #4 from dhalbert/up-to-date-data
Use only latest data when reading value. Prevent sync errors.
2 parents 9e5afba + fdc0e81 commit 3917670

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

README.rst

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ This is easily achieved by downloading
3232

3333
Installing from PyPI
3434
=====================
35-
.. note:: This library is not available on PyPI yet. Install documentation is included
36-
as a standard element. Stay tuned for PyPI availability!
37-
3835
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
3936
PyPI <https://pypi.org/project/adafruit-circuitpython-ble-berrymed_pulse_oximeter/>`_. To install for current user:
4037

adafruit_ble_berrymed_pulse_oximeter/__init__.py

+28-12
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@
3333
3434
**Hardware:**
3535
36-
* BM1000C, made by Shanghai Berry Electronic Tech Co.,Ltd
36+
* BM1000, made by Shanghai Berry Electronic Tech Co.,Ltd.
37+
Device labeling is not consistent.
38+
May be identified on device label, box, or in BLE advertisement as
39+
BM1000, BM1000B, BM1000C, or BM1000E.
40+
41+
Protocol defined here:
42+
43+
* https://github.com/zh2x/BCI_Protocol.
3744
38-
Protocol defined here: https://github.com/zh2x/BCI_Protocol
3945
Thanks as well to:
40-
* https://github.com/ehborisov/BerryMed-Pulse-Oximeter-tool
41-
* https://github.com/ScheindorfHyenetics/berrymedBluetoothOxymeter
46+
47+
* https://github.com/ehborisov/BerryMed-Pulse-Oximeter-tool
48+
* https://github.com/ScheindorfHyenetics/berrymedBluetoothOxymeter
4249
4350
**Software and Dependencies:**
4451
@@ -100,14 +107,23 @@ def values(self):
100107
101108
Return ``None`` if no data available.
102109
"""
103-
first_byte = self.read(1)
104-
# Wait for a byte with the high bit set, which indicates the beginning
105-
# a data packet.
106-
if not first_byte:
107-
return None
108-
header = first_byte[0]
109-
if header & 0x80 == 0:
110-
# Not synchronized.
110+
# Discard stale data.
111+
self.reset_input_buffer()
112+
# Data packets are five bytes long. The first byte has its high bit set;
113+
# the rest do not. Read up to five bytes to get back in sync.
114+
have_header = False
115+
for _ in range(5):
116+
first_byte = self.read(1)
117+
if not first_byte:
118+
# Nothing read, even after stream timeout.
119+
return None
120+
header = first_byte[0]
121+
if header & 0x80:
122+
have_header = True
123+
break
124+
125+
if not have_header:
126+
# Failed to synchronize.
111127
return None
112128

113129
data = self.read(4)

docs/conf.py

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
3030
}
3131

32+
# Show the docstring from both the class and its __init__() method.
33+
autoclass_content = "both"
34+
3235
# Add any paths that contain templates here, relative to this directory.
3336
templates_path = ["_templates"]
3437

0 commit comments

Comments
 (0)