_read_register now uses loop in uart mode to increase stability and speed
This commit is contained in:
parent
0879db5326
commit
843480682b
3 changed files with 19 additions and 35 deletions
|
|
@ -402,28 +402,20 @@ class BNO055_UART(BNO055):
|
|||
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]))
|
||||
now = time.monotonic()
|
||||
while self._uart.in_waiting < length + 2 and time.monotonic() - now < 0.25:
|
||||
pass
|
||||
resp = self._uart.read(self._uart.in_waiting)
|
||||
|
||||
if resp[0] != 0xBB: # Recursion
|
||||
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.25:
|
||||
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:
|
||||
raise OSError("UART access error.")
|
||||
if resp[0] != 0xBB:
|
||||
raise RuntimeError("UART read error: {}".format(resp[1]))
|
||||
if length > 1:
|
||||
return resp[2:]
|
||||
return int(resp[2])
|
||||
|
||||
if len(resp) >= 2 and resp[0] == 0xBB:
|
||||
i = 3
|
||||
i += 1
|
||||
if len(resp) < 2:
|
||||
raise OSError("UART access error.")
|
||||
if resp[0] != 0xBB:
|
||||
raise RuntimeError("UART read error: {}".format(resp[1]))
|
||||
if length > 1:
|
||||
return resp[2:]
|
||||
return int(resp[2])
|
||||
|
|
|
|||
10
docs/conf.py
10
docs/conf.py
|
|
@ -10,11 +10,7 @@ sys.path.insert(0, os.path.abspath(".."))
|
|||
# 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 @@ latex_documents = [
|
|||
"Adafruit BNO055 Library Documentation",
|
||||
"Radomir Dopieralski",
|
||||
"manual",
|
||||
),
|
||||
)
|
||||
]
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
|
@ -175,5 +171,5 @@ texinfo_documents = [
|
|||
"AdafruitBNO055Library",
|
||||
"One line description of project.",
|
||||
"Miscellaneous",
|
||||
),
|
||||
)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -12,17 +12,13 @@ sensor = adafruit_bno055.BNO055_I2C(i2c)
|
|||
# sensor = adafruit_bno055.BNO055_UART(uart)
|
||||
|
||||
while True:
|
||||
# Try/except only necessary when usuing UART mode
|
||||
try:
|
||||
print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
|
||||
print("Magnetometer (microteslas): {}".format(sensor.magnetic))
|
||||
print("Gyroscope (rad/sec): {}".format(sensor.gyro))
|
||||
print("Euler angle: {}".format(sensor.euler))
|
||||
print("Quaternion: {}".format(sensor.quaternion))
|
||||
print("Linear acceleration (m/s^2): {}".format(sensor.linear_acceleration))
|
||||
print("Gravity (m/s^2): {}".format(sensor.gravity))
|
||||
print()
|
||||
except RuntimeError as e:
|
||||
print(e)
|
||||
print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
|
||||
print("Magnetometer (microteslas): {}".format(sensor.magnetic))
|
||||
print("Gyroscope (rad/sec): {}".format(sensor.gyro))
|
||||
print("Euler angle: {}".format(sensor.euler))
|
||||
print("Quaternion: {}".format(sensor.quaternion))
|
||||
print("Linear acceleration (m/s^2): {}".format(sensor.linear_acceleration))
|
||||
print("Gravity (m/s^2): {}".format(sensor.gravity))
|
||||
print()
|
||||
|
||||
time.sleep(1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue