Skip to content

Commit 42517d7

Browse files
authored
Possible fix for #11
Would like someone to review, didn't setup hardware tests yet. Will do so when I have more time. Thanks for the Hacktoberfest tag!
1 parent 7a84ff7 commit 42517d7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

adafruit_bno055.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
_MODE_REGISTER = const(0x3d)
6363
_PAGE_REGISTER = const(0x07)
64+
_CALIBRATION_REGISTER = const(0x35)
6465
_TRIGGER_REGISTER = const(0x3f)
6566
_POWER_REGISTER = const(0x3e)
6667
_ID_REGISTER = const(0x00)
@@ -144,6 +145,14 @@ def _read_register(self, register):
144145
i2c.readinto(self.buffer, start=1)
145146
return self.buffer[1]
146147

148+
def _get_calibration_data(self):
149+
calibration_data = self._read_register(_CALIBRATION_REGISTER)
150+
sys = (calibration_data >> 6) & 0x03
151+
gyro = (calibration_data >> 4) & 0x03
152+
accel = (calibration_data >> 2) & 0x03
153+
mag = calibration_data & 0x03
154+
return sys, gyro, accel, mag
155+
147156
def reset(self):
148157
"""Resets the sensor to default settings."""
149158
self.mode = CONFIG_MODE
@@ -196,6 +205,14 @@ def mode(self):
196205
"""
197206
return self._read_register(_MODE_REGISTER)
198207

208+
@property
209+
def is_fully_calibrated(self):
210+
"""Returns the status of the sensor calibration."""
211+
sys, gyro, accel, mag = self._get_calibration_data()
212+
if sys < 3 or gyro < 3 or accel < 3 or mag < 3:
213+
return False
214+
return True
215+
199216
@mode.setter
200217
def mode(self, new_mode):
201218
self._write_register(_MODE_REGISTER, new_mode)

0 commit comments

Comments
 (0)