Skip to content

Use only latest data when reading value. Prevent sync errors. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ This is easily achieved by downloading

Installing from PyPI
=====================
.. note:: This library is not available on PyPI yet. Install documentation is included
as a standard element. Stay tuned for PyPI availability!

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
PyPI <https://pypi.org/project/adafruit-circuitpython-ble-berrymed_pulse_oximeter/>`_. To install for current user:

Expand Down
40 changes: 28 additions & 12 deletions adafruit_ble_berrymed_pulse_oximeter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@

**Hardware:**

* BM1000C, made by Shanghai Berry Electronic Tech Co.,Ltd
* BM1000, made by Shanghai Berry Electronic Tech Co.,Ltd.
Device labeling is not consistent.
May be identified on device label, box, or in BLE advertisement as
BM1000, BM1000B, BM1000C, or BM1000E.

Protocol defined here:

* https://github.com/zh2x/BCI_Protocol.

Protocol defined here: https://github.com/zh2x/BCI_Protocol
Thanks as well to:
* https://github.com/ehborisov/BerryMed-Pulse-Oximeter-tool
* https://github.com/ScheindorfHyenetics/berrymedBluetoothOxymeter

* https://github.com/ehborisov/BerryMed-Pulse-Oximeter-tool
* https://github.com/ScheindorfHyenetics/berrymedBluetoothOxymeter

**Software and Dependencies:**

Expand Down Expand Up @@ -100,14 +107,23 @@ def values(self):

Return ``None`` if no data available.
"""
first_byte = self.read(1)
# Wait for a byte with the high bit set, which indicates the beginning
# a data packet.
if not first_byte:
return None
header = first_byte[0]
if header & 0x80 == 0:
# Not synchronized.
# Discard stale data.
self.reset_input_buffer()
# Data packets are five bytes long. The first byte has its high bit set;
# the rest do not. Read up to five bytes to get back in sync.
have_header = False
for _ in range(5):
first_byte = self.read(1)
if not first_byte:
# Nothing read, even after stream timeout.
return None
header = first_byte[0]
if header & 0x80:
have_header = True
break

if not have_header:
# Failed to synchronize.
return None

data = self.read(4)
Expand Down
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
}

# Show the docstring from both the class and its __init__() method.
autoclass_content = "both"

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand Down