From 42517d70d443288e30a9b19599e9bf5a59b5e8ed Mon Sep 17 00:00:00 2001 From: David Keck Date: Mon, 8 Oct 2018 21:01:19 -0400 Subject: [PATCH 1/2] 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! --- adafruit_bno055.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/adafruit_bno055.py b/adafruit_bno055.py index dff4500..97d2485 100644 --- a/adafruit_bno055.py +++ b/adafruit_bno055.py @@ -61,6 +61,7 @@ _MODE_REGISTER = const(0x3d) _PAGE_REGISTER = const(0x07) +_CALIBRATION_REGISTER = const(0x35) _TRIGGER_REGISTER = const(0x3f) _POWER_REGISTER = const(0x3e) _ID_REGISTER = const(0x00) @@ -144,6 +145,14 @@ def _read_register(self, register): i2c.readinto(self.buffer, start=1) return self.buffer[1] + def _get_calibration_data(self): + calibration_data = self._read_register(_CALIBRATION_REGISTER) + sys = (calibration_data >> 6) & 0x03 + gyro = (calibration_data >> 4) & 0x03 + accel = (calibration_data >> 2) & 0x03 + mag = calibration_data & 0x03 + return sys, gyro, accel, mag + def reset(self): """Resets the sensor to default settings.""" self.mode = CONFIG_MODE @@ -196,6 +205,14 @@ def mode(self): """ return self._read_register(_MODE_REGISTER) + @property + def is_fully_calibrated(self): + """Returns the status of the sensor calibration.""" + sys, gyro, accel, mag = self._get_calibration_data() + if sys < 3 or gyro < 3 or accel < 3 or mag < 3: + return False + return True + @mode.setter def mode(self, new_mode): self._write_register(_MODE_REGISTER, new_mode) From cf551a6399551e06a41dd3e92fb7c9ee466a09b3 Mon Sep 17 00:00:00 2001 From: David Keck Date: Tue, 9 Oct 2018 07:52:06 -0400 Subject: [PATCH 2/2] Updated calibration functionality after review. --- adafruit_bno055.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/adafruit_bno055.py b/adafruit_bno055.py index 97d2485..a32e9fe 100644 --- a/adafruit_bno055.py +++ b/adafruit_bno055.py @@ -145,14 +145,6 @@ def _read_register(self, register): i2c.readinto(self.buffer, start=1) return self.buffer[1] - def _get_calibration_data(self): - calibration_data = self._read_register(_CALIBRATION_REGISTER) - sys = (calibration_data >> 6) & 0x03 - gyro = (calibration_data >> 4) & 0x03 - accel = (calibration_data >> 2) & 0x03 - mag = calibration_data & 0x03 - return sys, gyro, accel, mag - def reset(self): """Resets the sensor to default settings.""" self.mode = CONFIG_MODE @@ -206,12 +198,20 @@ def mode(self): return self._read_register(_MODE_REGISTER) @property - def is_fully_calibrated(self): - """Returns the status of the sensor calibration.""" - sys, gyro, accel, mag = self._get_calibration_data() - if sys < 3 or gyro < 3 or accel < 3 or mag < 3: - return False - return True + def calibration_status(self): + """Tuple containing sys, gyro, accel, and mag calibration data.""" + calibration_data = self._read_register(_CALIBRATION_REGISTER) + sys = (calibration_data >> 6) & 0x03 + gyro = (calibration_data >> 4) & 0x03 + accel = (calibration_data >> 2) & 0x03 + mag = calibration_data & 0x03 + return sys, gyro, accel, mag + + @property + def calibrated(self): + """Boolean indicating calibration status.""" + sys, gyro, accel, mag = self.calibration_status + return sys == gyro == accel == mag == 0x03 @mode.setter def mode(self, new_mode):