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 all commits
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 @@ -196,6 +197,22 @@ def mode(self):
"""
return self._read_register(_MODE_REGISTER)

@property
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

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