From 16d24302dd9cc8b160c68e795dc245ac37ceb368 Mon Sep 17 00:00:00 2001 From: Evan Flynn <6157095+flynneva@users.noreply.github.com> Date: Sat, 14 Jan 2023 20:42:51 -0800 Subject: [PATCH] Fix i2c issues found (param and division by zero) (#56) --- bno055/bno055.py | 3 +++ bno055/params/NodeParameters.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bno055/bno055.py b/bno055/bno055.py index 743a21c..950a863 100755 --- a/bno055/bno055.py +++ b/bno055/bno055.py @@ -112,6 +112,9 @@ def read_data(): except BusOverRunException: # data not available yet, wait for next cycle | see #5 return + except ZeroDivisionError: + # division by zero in get_sensor_data, return + return except Exception as e: # noqa: B902 node.get_logger().warn('Receiving sensor data failed with %s:"%s"' % (type(e).__name__, e)) diff --git a/bno055/params/NodeParameters.py b/bno055/params/NodeParameters.py index 770d64d..ab88dc4 100644 --- a/bno055/params/NodeParameters.py +++ b/bno055/params/NodeParameters.py @@ -109,7 +109,7 @@ def __init__(self, node: Node): self.connection_type = node.get_parameter('connection_type') node.get_logger().info('\tconnection_type:\t"%s"' % self.connection_type.value) - if self.connection_type == I2C.CONNECTIONTYPE_I2C: + if self.connection_type.value == I2C.CONNECTIONTYPE_I2C: self.i2c_bus = node.get_parameter('i2c_bus') node.get_logger().info('\ti2c_bus:\t\t"%s"' % self.i2c_bus.value) @@ -117,7 +117,7 @@ def __init__(self, node: Node): self.i2c_addr = node.get_parameter('i2c_addr') node.get_logger().info('\ti2c_addr:\t\t"%s"' % self.i2c_addr.value) - elif self.connection_type == UART.CONNECTIONTYPE_UART: + elif self.connection_type.value == UART.CONNECTIONTYPE_UART: self.uart_port = node.get_parameter('uart_port') node.get_logger().info('\tuart_port:\t\t"%s"' % self.uart_port.value)