62
62
_MODE_REGISTER = const (0x3d )
63
63
_PAGE_REGISTER = const (0x07 )
64
64
_CALIBRATION_REGISTER = const (0x35 )
65
+ _OFFSET_ACCEL_REGISTER = const (0x55 )
66
+ _OFFSET_MAGNET_REGISTER = const (0x5b )
67
+ _OFFSET_GYRO_REGISTER = const (0x61 )
68
+ _RADIUS_ACCEL_REGISTER = const (0x67 )
69
+ _RADIUS_MAGNET_REGISTER = const (0x69 )
65
70
_TRIGGER_REGISTER = const (0x3f )
66
71
_POWER_REGISTER = const (0x3e )
67
72
_ID_REGISTER = const (0x00 )
@@ -85,6 +90,26 @@ class _ReadOnlyUnaryStruct(UnaryStruct): # pylint: disable=too-few-public-method
85
90
def __set__ (self , obj , value ):
86
91
raise NotImplementedError ()
87
92
93
+ class _ModeStruct (Struct ): # pylint: disable=too-few-public-methods
94
+ def __init__ (self , register_address , struct_format , mode ):
95
+ super ().__init__ (register_address , struct_format )
96
+ self .mode = mode
97
+
98
+ def __get__ (self , obj , objtype = None ):
99
+ last_mode = obj .mode
100
+ obj .mode = self .mode
101
+ result = super ().__get__ (obj , objtype )
102
+ obj .mode = last_mode
103
+ # single value comes back as a one-element tuple
104
+ return result [0 ] if isinstance (result , tuple ) and len (result ) == 1 else result
105
+
106
+ def __set__ (self , obj , value ):
107
+ last_mode = obj .mode
108
+ obj .mode = self .mode
109
+ # underlying __set__() expects a tuple
110
+ set_val = value if isinstance (value , tuple ) else (value ,)
111
+ super ().__set__ (obj , set_val )
112
+ obj .mode = last_mode
88
113
89
114
class BNO055 :
90
115
"""
@@ -101,6 +126,18 @@ class BNO055:
101
126
_gravity = _ScaledReadOnlyStruct (0x2e , '<hhh' , 1 / 100 )
102
127
103
128
129
+ offsets_accelerometer = _ModeStruct (_OFFSET_ACCEL_REGISTER , '<hhh' , CONFIG_MODE )
130
+ """Calibration offsets for the accelerometer"""
131
+ offsets_magnetometer = _ModeStruct (_OFFSET_MAGNET_REGISTER , '<hhh' , CONFIG_MODE )
132
+ """Calibration offsets for the magnetometer"""
133
+ offsets_gyroscope = _ModeStruct (_OFFSET_GYRO_REGISTER , '<hhh' , CONFIG_MODE )
134
+ """Calibration offsets for the gyroscope"""
135
+
136
+ radius_accelerometer = _ModeStruct (_RADIUS_ACCEL_REGISTER , '<h' , CONFIG_MODE )
137
+ """Radius for accelerometer (cm?)"""
138
+ radius_magnetometer = _ModeStruct (_RADIUS_MAGNET_REGISTER , '<h' , CONFIG_MODE )
139
+ """Radius for magnetometer (cm?)"""
140
+
104
141
def __init__ (self , i2c , address = 0x28 ):
105
142
self .i2c_device = I2CDevice (i2c , address )
106
143
self .buffer = bytearray (2 )
0 commit comments