diff --git a/adafruit_bno055.py b/adafruit_bno055.py index 16a290a..615ff08 100644 --- a/adafruit_bno055.py +++ b/adafruit_bno055.py @@ -33,6 +33,7 @@ import time import struct +from os import uname from micropython import const from adafruit_bus_device.i2c_device import I2CDevice from adafruit_register.i2c_struct import Struct, UnaryStruct @@ -146,6 +147,20 @@ def __set__(self, obj, value): class _ReadOnlyUnaryStruct(UnaryStruct): # pylint: disable=too-few-public-methods + def __init__(self, register_address, struct_format): + super().__init__(register_address, struct_format) + self.last_val = 0xFFFF + + def __get__(self, obj, objtype=None): + result = super().__get__(obj, objtype) + if uname().sysname == "Linux": + if abs(result - self.last_val) == 128: + result = super().__get__(obj, objtype) + if abs(result - self.last_val) == 128: + return 0b00111111 & result + self.last_val = result + return result + def __set__(self, obj, value): raise NotImplementedError() @@ -456,7 +471,7 @@ def _gravity(self): @property def accel_range(self): - """ Switch the accelerometer range and return the new range. Default value: +/- 4g + """Switch the accelerometer range and return the new range. Default value: +/- 4g See table 3-8 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -474,7 +489,7 @@ def accel_range(self, rng=ACCEL_4G): @property def accel_bandwidth(self): - """ Switch the accelerometer bandwidth and return the new bandwidth. Default value: 62.5 Hz + """Switch the accelerometer bandwidth and return the new bandwidth. Default value: 62.5 Hz See table 3-8 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -494,7 +509,7 @@ def accel_bandwidth(self, bandwidth=ACCEL_62_5HZ): @property def accel_mode(self): - """ Switch the accelerometer mode and return the new mode. Default value: Normal + """Switch the accelerometer mode and return the new mode. Default value: Normal See table 3-8 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -514,7 +529,7 @@ def accel_mode(self, mode=ACCEL_NORMAL_MODE): @property def gyro_range(self): - """ Switch the gyroscope range and return the new range. Default value: 2000 dps + """Switch the gyroscope range and return the new range. Default value: 2000 dps See table 3-9 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -534,7 +549,7 @@ def gyro_range(self, rng=GYRO_2000_DPS): @property def gyro_bandwidth(self): - """ Switch the gyroscope bandwidth and return the new bandwidth. Default value: 32 Hz + """Switch the gyroscope bandwidth and return the new bandwidth. Default value: 32 Hz See table 3-9 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -554,7 +569,7 @@ def gyro_bandwidth(self, bandwidth=GYRO_32HZ): @property def gyro_mode(self): - """ Switch the gyroscope mode and return the new mode. Default value: Normal + """Switch the gyroscope mode and return the new mode. Default value: Normal See table 3-9 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -574,7 +589,7 @@ def gyro_mode(self, mode=GYRO_NORMAL_MODE): @property def magnet_rate(self): - """ Switch the magnetometer data output rate and return the new rate. Default value: 20Hz + """Switch the magnetometer data output rate and return the new rate. Default value: 20Hz See table 3-10 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -594,7 +609,7 @@ def magnet_rate(self, rate=MAGNET_20HZ): @property def magnet_operation_mode(self): - """ Switch the magnetometer operation mode and return the new mode. Default value: Regular + """Switch the magnetometer operation mode and return the new mode. Default value: Regular See table 3-10 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01) @@ -614,7 +629,7 @@ def magnet_operation_mode(self, mode=MAGNET_REGULAR_MODE): @property def magnet_mode(self): - """ Switch the magnetometer power mode and return the new mode. Default value: Forced + """Switch the magnetometer power mode and return the new mode. Default value: Forced See table 3-10 in the datasheet. """ self._write_register(_PAGE_REGISTER, 0x01)