From 170c92d97a4974613f111ad569d695b22e53795d Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 25 Nov 2020 13:24:57 -0500 Subject: [PATCH 1/3] Made temperature more stable on raspberry pi --- adafruit_bno055.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/adafruit_bno055.py b/adafruit_bno055.py index 16a290a..2c76472 100644 --- a/adafruit_bno055.py +++ b/adafruit_bno055.py @@ -35,7 +35,8 @@ from micropython import const from adafruit_bus_device.i2c_device import I2CDevice -from adafruit_register.i2c_struct import Struct, UnaryStruct +from adafruit_register.i2c_struct import Struct, UnaryStruct, ROUnaryStruct +from os import uname __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BNO055.git" @@ -131,7 +132,6 @@ _POWER_REGISTER = const(0x3E) _ID_REGISTER = const(0x00) - class _ScaledReadOnlyStruct(Struct): # pylint: disable=too-few-public-methods def __init__(self, register_address, struct_format, scale): super().__init__(register_address, struct_format) @@ -145,7 +145,21 @@ def __set__(self, obj, value): raise NotImplementedError() -class _ReadOnlyUnaryStruct(UnaryStruct): # pylint: disable=too-few-public-methods +class _ReadOnlyUnaryStruct(ROUnaryStruct): # 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 0b01111111 & result + self.last_val = result + return result + def __set__(self, obj, value): raise NotImplementedError() From 9f503ae923e783969cd939fa899e684da7bb692b Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 25 Nov 2020 13:33:44 -0500 Subject: [PATCH 2/3] Fixed black and pylint issues --- adafruit_bno055.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/adafruit_bno055.py b/adafruit_bno055.py index 2c76472..add7372 100644 --- a/adafruit_bno055.py +++ b/adafruit_bno055.py @@ -33,10 +33,10 @@ 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, ROUnaryStruct -from os import uname +from adafruit_register.i2c_struct import Struct, UnaryStruct __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BNO055.git" @@ -132,6 +132,7 @@ _POWER_REGISTER = const(0x3E) _ID_REGISTER = const(0x00) + class _ScaledReadOnlyStruct(Struct): # pylint: disable=too-few-public-methods def __init__(self, register_address, struct_format, scale): super().__init__(register_address, struct_format) @@ -145,21 +146,21 @@ def __set__(self, obj, value): raise NotImplementedError() -class _ReadOnlyUnaryStruct(ROUnaryStruct): # pylint: disable=too-few-public-methods +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 uname().sysname == "Linux": if abs(result - self.last_val) == 128: result = super().__get__(obj, objtype) if abs(result - self.last_val) == 128: return 0b01111111 & result self.last_val = result return result - + def __set__(self, obj, value): raise NotImplementedError() @@ -470,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) @@ -488,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) @@ -508,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) @@ -528,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) @@ -548,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) @@ -568,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) @@ -588,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) @@ -608,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) @@ -628,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) From f21b520f26e6565de7a6b064efea09c381286f7d Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 25 Nov 2020 13:58:57 -0500 Subject: [PATCH 3/3] Made bitmask do what it was supposed to do --- adafruit_bno055.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bno055.py b/adafruit_bno055.py index add7372..615ff08 100644 --- a/adafruit_bno055.py +++ b/adafruit_bno055.py @@ -157,7 +157,7 @@ def __get__(self, obj, objtype=None): if abs(result - self.last_val) == 128: result = super().__get__(obj, objtype) if abs(result - self.last_val) == 128: - return 0b01111111 & result + return 0b00111111 & result self.last_val = result return result