|
61 | 61 |
|
62 | 62 | _MODE_REGISTER = const(0x3d)
|
63 | 63 | _PAGE_REGISTER = const(0x07)
|
| 64 | +_CALIBRATION_REGISTER = const(0x35) |
64 | 65 | _TRIGGER_REGISTER = const(0x3f)
|
65 | 66 | _POWER_REGISTER = const(0x3e)
|
66 | 67 | _ID_REGISTER = const(0x00)
|
@@ -144,6 +145,14 @@ def _read_register(self, register):
|
144 | 145 | i2c.readinto(self.buffer, start=1)
|
145 | 146 | return self.buffer[1]
|
146 | 147 |
|
| 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 | + |
147 | 156 | def reset(self):
|
148 | 157 | """Resets the sensor to default settings."""
|
149 | 158 | self.mode = CONFIG_MODE
|
@@ -196,6 +205,14 @@ def mode(self):
|
196 | 205 | """
|
197 | 206 | return self._read_register(_MODE_REGISTER)
|
198 | 207 |
|
| 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 | + |
199 | 216 | @mode.setter
|
200 | 217 | def mode(self, new_mode):
|
201 | 218 | self._write_register(_MODE_REGISTER, new_mode)
|
|
0 commit comments