diff --git a/adafruit_bno055.py b/adafruit_bno055.py index a32e9fe..38e701c 100644 --- a/adafruit_bno055.py +++ b/adafruit_bno055.py @@ -62,6 +62,11 @@ _MODE_REGISTER = const(0x3d) _PAGE_REGISTER = const(0x07) _CALIBRATION_REGISTER = const(0x35) +_OFFSET_ACCEL_REGISTER = const(0x55) +_OFFSET_MAGNET_REGISTER = const(0x5b) +_OFFSET_GYRO_REGISTER = const(0x61) +_RADIUS_ACCEL_REGISTER = const(0x67) +_RADIUS_MAGNET_REGISTER = const(0x69) _TRIGGER_REGISTER = const(0x3f) _POWER_REGISTER = const(0x3e) _ID_REGISTER = const(0x00) @@ -85,6 +90,26 @@ class _ReadOnlyUnaryStruct(UnaryStruct): # pylint: disable=too-few-public-method def __set__(self, obj, value): raise NotImplementedError() +class _ModeStruct(Struct): # pylint: disable=too-few-public-methods + def __init__(self, register_address, struct_format, mode): + super().__init__(register_address, struct_format) + self.mode = mode + + def __get__(self, obj, objtype=None): + last_mode = obj.mode + obj.mode = self.mode + result = super().__get__(obj, objtype) + obj.mode = last_mode + # single value comes back as a one-element tuple + return result[0] if isinstance(result, tuple) and len(result) == 1 else result + + def __set__(self, obj, value): + last_mode = obj.mode + obj.mode = self.mode + # underlying __set__() expects a tuple + set_val = value if isinstance(value, tuple) else (value,) + super().__set__(obj, set_val) + obj.mode = last_mode class BNO055: """ @@ -118,6 +143,18 @@ class BNO055: gravity = _ScaledReadOnlyStruct(0x2e, '