Skip to content

Add calibration offsets and radii as properties on BNO055 library #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
34 changes: 34 additions & 0 deletions adafruit_bno055.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -85,6 +90,23 @@ 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
return result

def __set__(self, obj, value):
last_mode = obj.mode
obj.mode = self.mode
super().__set__(obj, value)
obj.mode = last_mode

class BNO055:
"""
Expand Down Expand Up @@ -118,6 +140,18 @@ class BNO055:
gravity = _ScaledReadOnlyStruct(0x2e, '<hhh', 1/100)
"""Returns the gravity vector, without acceleration in m/s."""

offsets_accelerometer = _ModeStruct(_OFFSET_ACCEL_REGISTER, '<hhh', CONFIG_MODE)
"""Calibration offsets for the accelerometer"""
offsets_magnetometer = _ModeStruct(_OFFSET_MAGNET_REGISTER, '<hhh', CONFIG_MODE)
"""Calibration offsets for the magnetometer"""
offsets_gyroscope = _ModeStruct(_OFFSET_GYRO_REGISTER, '<hhh', CONFIG_MODE)
"""Calibration offsets for the gyroscope"""

radius_accelerometer = _ModeStruct(_RADIUS_ACCEL_REGISTER, '<h', CONFIG_MODE)
"""Radius for accelerometer (cm?)"""
radius_magnetometer = _ModeStruct(_RADIUS_MAGNET_REGISTER, '<h', CONFIG_MODE)
"""Radius for magnetometer (cm?)"""

def __init__(self, i2c, address=0x28):
self.i2c_device = I2CDevice(i2c, address)
self.buffer = bytearray(2)
Expand Down