Skip to content

Possible fix for #11 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions adafruit_bno055.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being able to get the individual status's might be useful. Change this to a property called calibration_status, still returning the same tuple.

def reset(self):
"""Resets the sensor to default settings."""
self.mode = CONFIG_MODE
Expand Down Expand Up @@ -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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change name to simply calibrated. And a python-y way to do the check and return is:

return sys == gyro == accel == mag == 0x03

Also - the doc strings for properties should read like a variable, not a function. So instead of describing what it does ("Returns..."), describe what it is ("The status of...").

@mode.setter
def mode(self, new_mode):
self._write_register(_MODE_REGISTER, new_mode)
Expand Down