Skip to content

Commit d8ad1e6

Browse files
authored
Merge pull request #50 from adafruit/uart_speed
Allow uart to go ~100Hz versus 10Hz
2 parents 3700bb5 + d73e432 commit d8ad1e6

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

adafruit_bno055.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,26 @@ def _write_register(self, register, data): # pylint: disable=arguments-differ
392392
if not isinstance(data, bytes):
393393
data = bytes([data])
394394
self._uart.write(bytes([0xAA, 0x00, register, len(data)]) + data)
395-
time.sleep(0.1)
395+
now = time.monotonic()
396+
while self._uart.in_waiting < 2 and time.monotonic() - now < 0.25:
397+
pass
396398
resp = self._uart.read(self._uart.in_waiting)
397399
if len(resp) < 2:
398400
raise OSError("UART access error.")
399401
if resp[0] != 0xEE or resp[1] != 0x01:
400402
raise RuntimeError("UART write error: {}".format(resp[1]))
401403

402404
def _read_register(self, register, length=1): # pylint: disable=arguments-differ
403-
self._uart.write(bytes([0xAA, 0x01, register, length]))
404-
time.sleep(0.1)
405-
resp = self._uart.read(self._uart.in_waiting)
405+
i = 0
406+
while i < 3:
407+
self._uart.write(bytes([0xAA, 0x01, register, length]))
408+
now = time.monotonic()
409+
while self._uart.in_waiting < length + 2 and time.monotonic() - now < 0.1:
410+
pass
411+
resp = self._uart.read(self._uart.in_waiting)
412+
if len(resp) >= 2 and resp[0] == 0xBB:
413+
break
414+
i += 1
406415
if len(resp) < 2:
407416
raise OSError("UART access error.")
408417
if resp[0] != 0xBB:

docs/conf.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
# Add any Sphinx extension module names here, as strings. They can be
1111
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1212
# ones.
13-
extensions = [
14-
"sphinx.ext.autodoc",
15-
"sphinx.ext.intersphinx",
16-
"sphinx.ext.viewcode",
17-
]
13+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx.ext.viewcode"]
1814

1915
# Uncomment the below if you use native CircuitPython modules such as
2016
# digitalio, micropython and busio. List the modules you use. Without it, the
@@ -144,7 +140,7 @@
144140
"Adafruit BNO055 Library Documentation",
145141
"Radomir Dopieralski",
146142
"manual",
147-
),
143+
)
148144
]
149145

150146
# -- Options for manual page output ---------------------------------------
@@ -175,5 +171,5 @@
175171
"AdafruitBNO055Library",
176172
"One line description of project.",
177173
"Miscellaneous",
178-
),
174+
)
179175
]

0 commit comments

Comments
 (0)