diff --git a/adafruit_bno055.py b/adafruit_bno055.py index 10fd1be..2ad5a28 100644 --- a/adafruit_bno055.py +++ b/adafruit_bno055.py @@ -392,7 +392,9 @@ def _write_register(self, register, data): # pylint: disable=arguments-differ if not isinstance(data, bytes): data = bytes([data]) self._uart.write(bytes([0xAA, 0x00, register, len(data)]) + data) - time.sleep(0.1) + now = time.monotonic() + while self._uart.in_waiting < 2 and time.monotonic() - now < 0.25: + pass resp = self._uart.read(self._uart.in_waiting) if len(resp) < 2: raise OSError("UART access error.") @@ -400,9 +402,16 @@ def _write_register(self, register, data): # pylint: disable=arguments-differ raise RuntimeError("UART write error: {}".format(resp[1])) def _read_register(self, register, length=1): # pylint: disable=arguments-differ - self._uart.write(bytes([0xAA, 0x01, register, length])) - time.sleep(0.1) - resp = self._uart.read(self._uart.in_waiting) + i = 0 + while i < 3: + self._uart.write(bytes([0xAA, 0x01, register, length])) + now = time.monotonic() + while self._uart.in_waiting < length + 2 and time.monotonic() - now < 0.1: + pass + resp = self._uart.read(self._uart.in_waiting) + if len(resp) >= 2 and resp[0] == 0xBB: + break + i += 1 if len(resp) < 2: raise OSError("UART access error.") if resp[0] != 0xBB: diff --git a/docs/conf.py b/docs/conf.py index c5429f0..543cbaa 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,11 +10,7 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.intersphinx", - "sphinx.ext.viewcode", -] +extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx.ext.viewcode"] # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the @@ -144,7 +140,7 @@ "Adafruit BNO055 Library Documentation", "Radomir Dopieralski", "manual", - ), + ) ] # -- Options for manual page output --------------------------------------- @@ -175,5 +171,5 @@ "AdafruitBNO055Library", "One line description of project.", "Miscellaneous", - ), + ) ]