Skip to content

Commit e28bc77

Browse files
committed
Made members that store sensor dataproperties. Removed deprecated members. Now returns None for disabled members
1 parent 84ff6fd commit e28bc77

File tree

1 file changed

+61
-10
lines changed

1 file changed

+61
-10
lines changed

adafruit_bno055.py

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ class BNO055:
9191
Driver for the BNO055 9DOF IMU sensor.
9292
"""
9393

94+
_temperature = _ReadOnlyUnaryStruct(0x34, 'b')
95+
_acceleration = _ScaledReadOnlyStruct(0x08, '<hhh', 1/100)
96+
_magnetic = _ScaledReadOnlyStruct(0x0e, '<hhh', 1/16)
97+
_gyro = _ScaledReadOnlyStruct(0x14, '<hhh', 0.001090830782496456)
98+
_euler = _ScaledReadOnlyStruct(0x1a, '<hhh', 1/16)
99+
_quaternion = _ScaledReadOnlyStruct(0x20, '<hhhh', 1/(1<<14))
100+
_linear_acceleration = _ScaledReadOnlyStruct(0x28, '<hhh', 1/100)
101+
_gravity = _ScaledReadOnlyStruct(0x2e, '<hhh', 1/100)
102+
103+
94104
def __init__(self, i2c, address=0x28):
95105
self.i2c_device = I2CDevice(i2c, address)
96106
self.buffer = bytearray(2)
@@ -217,62 +227,103 @@ def use_external_crystal(self, value):
217227
@property
218228
def temperature(self):
219229
"""Measures the temperature of the chip in degrees Celsius."""
220-
return _ReadOnlyUnaryStruct(0x34, 'b')
230+
return self._temperature
231+
232+
@temperature.setter
233+
def temperature(self):
234+
self._temperature = _ReadOnlyUnaryStruct(0x34, 'b')
221235

222236
@property
223237
def acceleration(self):
224238
"""Gives the raw accelerometer readings, in m/s."""
225239
if self.mode not in [0, 2, 3, 6]:
226-
return _ScaledReadOnlyStruct(0x08, '<hhh', 1/100)
240+
return self._acceleration
227241
else:
228242
return (None, None, None)
243+
244+
@acceleration.setter
245+
def acceleration(self):
246+
self._acceleration = _ScaledReadOnlyStruct(0x08, '<hhh', 1/100)
247+
229248

230249
@property
231250
def magnetic(self):
232251
"""Gives the raw magnetometer readings in microteslas."""
233252
if self.mode not in [0, 3, 5, 8]:
234-
return _ScaledReadOnlyStruct(0x0e, '<hhh', 1/16)
253+
return self._magnetic
254+
235255
else:
236256
return (None, None, None)
237257

258+
@magnetic.setter
259+
def magnetic(self):
260+
self._magnetic = _ScaledReadOnlyStruct(0x0e, '<hhh', 1/16)
261+
262+
238263
@property
239264
def gyro(self):
240265
"""Gives the raw gyroscope reading in radians per second."""
241266
if self.mode not in [0, 1, 2, 4, 9, 10]:
242-
return _ScaledReadOnlyStruct(0x14, '<hhh', 0.001090830782496456)
267+
return self._gyro
243268

244269
else:
245270
return (None, None, None)
246271

272+
@gyro.setter
273+
def gyro(self):
274+
self._gyro = _ScaledReadOnlyStruct(0x14, '<hhh', 0.001090830782496456)
275+
276+
247277
@property
248278
def euler(self):
249279
"""Gives the calculated orientation angles, in degrees."""
250-
if self.mode in [9, 11, 12, 0x0c]:
280+
if self.mode in [9, 11, 12]:
251281

252-
return _ScaledReadOnlyStruct(0x1a, '<hhh', 1/16)
282+
return self._euler
253283
else:
254284
return (None, None, None)
255-
285+
286+
@euler.setter
287+
def euler(self):
288+
self._euler = _ScaledReadOnlyStruct(0x1a, '<hhh', 1/16)
289+
290+
256291
@property
257292
def quaternion(self):
258293
"""Gives the calculated orientation as a quaternion."""
259294
if self.mode in [9, 11, 12]:
260-
return _ScaledReadOnlyStruct(0x20, '<hhhh', 1/(1<<14))
295+
return self._quaternion
261296
else:
262297
return (None, None, None, None)
263298

299+
@quaternion.setter
300+
def quaternion(self):
301+
self._quaternion = _ScaledReadOnlyStruct(0x20, '<hhhh', 1/(1<<14))
302+
303+
264304
@property
265305
def linear_acceleration(self):
266306
"""Returns the linear acceleration, without gravity, in m/s."""
267307
if self.mode in [9, 11, 12]:
268-
return _ScaledReadOnlyStruct(0x28, '<hhh', 1/100)
308+
return self._linear_acceleration
309+
269310
else:
270311
return (None, None, None)
271312

313+
@linear_acceleration.setter
314+
def linear_acceleration(self):
315+
self._linear_acceleration = _ScaledReadOnlyStruct(0x28, '<hhh', 1/100)
316+
317+
272318
@property
273319
def gravity(self):
274320
"""Returns the gravity vector, without acceleration in m/s."""
275321
if self.mode in [9, 11, 12]:
276-
return _ScaledReadOnlyStruct(0x2e, '<hhh', 1/100)
322+
return self._gravity
323+
277324
else:
278325
return (None, None, None)
326+
327+
@gravity.setter
328+
def gravity(self):
329+
self._gravity = _ScaledReadOnlyStruct(0x2e, '<hhh', 1/100)

0 commit comments

Comments
 (0)