Skip to content

Commit

Permalink
Merge pull request #44 from adafruit/pylint-update
Browse files Browse the repository at this point in the history
Ran black, updated to pylint 2.x
  • Loading branch information
kattni committed Mar 17, 2020
2 parents 7d7ad89 + efcff1b commit 54d42f1
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ spelling-store-unknown-words=no
[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO
# notes=FIXME,XXX,TODO
notes=FIXME,XXX


[TYPECHECK]
Expand Down
70 changes: 34 additions & 36 deletions adafruit_bno055.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BNO055.git"

_CHIP_ID = const(0xa0)
_CHIP_ID = const(0xA0)

CONFIG_MODE = const(0x00)
ACCONLY_MODE = const(0x01)
Expand All @@ -51,31 +51,30 @@
AMG_MODE = const(0x07)
IMUPLUS_MODE = const(0x08)
COMPASS_MODE = const(0x09)
M4G_MODE = const(0x0a)
NDOF_FMC_OFF_MODE = const(0x0b)
NDOF_MODE = const(0x0c)
M4G_MODE = const(0x0A)
NDOF_FMC_OFF_MODE = const(0x0B)
NDOF_MODE = const(0x0C)

_POWER_NORMAL = const(0x00)
_POWER_LOW = const(0x01)
_POWER_SUSPEND = const(0x02)

_MODE_REGISTER = const(0x3d)
_MODE_REGISTER = const(0x3D)
_PAGE_REGISTER = const(0x07)
_CALIBRATION_REGISTER = const(0x35)
_OFFSET_ACCEL_REGISTER = const(0x55)
_OFFSET_MAGNET_REGISTER = const(0x5b)
_OFFSET_MAGNET_REGISTER = const(0x5B)
_OFFSET_GYRO_REGISTER = const(0x61)
_RADIUS_ACCEL_REGISTER = const(0x67)
_RADIUS_MAGNET_REGISTER = const(0x69)
_TRIGGER_REGISTER = const(0x3f)
_POWER_REGISTER = const(0x3e)
_TRIGGER_REGISTER = const(0x3F)
_POWER_REGISTER = const(0x3E)
_ID_REGISTER = const(0x00)


class _ScaledReadOnlyStruct(Struct): # pylint: disable=too-few-public-methods
class _ScaledReadOnlyStruct(Struct): # pylint: disable=too-few-public-methods
def __init__(self, register_address, struct_format, scale):
super(_ScaledReadOnlyStruct, self).__init__(
register_address, struct_format)
super(_ScaledReadOnlyStruct, self).__init__(register_address, struct_format)
self.scale = scale

def __get__(self, obj, objtype=None):
Expand All @@ -86,11 +85,12 @@ def __set__(self, obj, value):
raise NotImplementedError()


class _ReadOnlyUnaryStruct(UnaryStruct): # pylint: disable=too-few-public-methods
class _ReadOnlyUnaryStruct(UnaryStruct): # pylint: disable=too-few-public-methods
def __set__(self, obj, value):
raise NotImplementedError()

class _ModeStruct(Struct): # pylint: disable=too-few-public-methods

class _ModeStruct(Struct): # pylint: disable=too-few-public-methods
def __init__(self, register_address, struct_format, mode):
super().__init__(register_address, struct_format)
self.mode = mode
Expand All @@ -111,31 +111,31 @@ def __set__(self, obj, value):
super().__set__(obj, set_val)
obj.mode = last_mode


class BNO055:
"""
Driver for the BNO055 9DOF IMU sensor.
"""

_temperature = _ReadOnlyUnaryStruct(0x34, 'b')
_acceleration = _ScaledReadOnlyStruct(0x08, '<hhh', 1/100)
_magnetic = _ScaledReadOnlyStruct(0x0e, '<hhh', 1/16)
_gyro = _ScaledReadOnlyStruct(0x14, '<hhh', 0.001090830782496456)
_euler = _ScaledReadOnlyStruct(0x1a, '<hhh', 1/16)
_quaternion = _ScaledReadOnlyStruct(0x20, '<hhhh', 1/(1<<14))
_linear_acceleration = _ScaledReadOnlyStruct(0x28, '<hhh', 1/100)
_gravity = _ScaledReadOnlyStruct(0x2e, '<hhh', 1/100)
_temperature = _ReadOnlyUnaryStruct(0x34, "b")
_acceleration = _ScaledReadOnlyStruct(0x08, "<hhh", 1 / 100)
_magnetic = _ScaledReadOnlyStruct(0x0E, "<hhh", 1 / 16)
_gyro = _ScaledReadOnlyStruct(0x14, "<hhh", 0.001090830782496456)
_euler = _ScaledReadOnlyStruct(0x1A, "<hhh", 1 / 16)
_quaternion = _ScaledReadOnlyStruct(0x20, "<hhhh", 1 / (1 << 14))
_linear_acceleration = _ScaledReadOnlyStruct(0x28, "<hhh", 1 / 100)
_gravity = _ScaledReadOnlyStruct(0x2E, "<hhh", 1 / 100)


offsets_accelerometer = _ModeStruct(_OFFSET_ACCEL_REGISTER, '<hhh', CONFIG_MODE)
offsets_accelerometer = _ModeStruct(_OFFSET_ACCEL_REGISTER, "<hhh", CONFIG_MODE)
"""Calibration offsets for the accelerometer"""
offsets_magnetometer = _ModeStruct(_OFFSET_MAGNET_REGISTER, '<hhh', CONFIG_MODE)
offsets_magnetometer = _ModeStruct(_OFFSET_MAGNET_REGISTER, "<hhh", CONFIG_MODE)
"""Calibration offsets for the magnetometer"""
offsets_gyroscope = _ModeStruct(_OFFSET_GYRO_REGISTER, '<hhh', CONFIG_MODE)
offsets_gyroscope = _ModeStruct(_OFFSET_GYRO_REGISTER, "<hhh", CONFIG_MODE)
"""Calibration offsets for the gyroscope"""

radius_accelerometer = _ModeStruct(_RADIUS_ACCEL_REGISTER, '<h', CONFIG_MODE)
radius_accelerometer = _ModeStruct(_RADIUS_ACCEL_REGISTER, "<h", CONFIG_MODE)
"""Radius for accelerometer (cm?)"""
radius_magnetometer = _ModeStruct(_RADIUS_MAGNET_REGISTER, '<h', CONFIG_MODE)
radius_magnetometer = _ModeStruct(_RADIUS_MAGNET_REGISTER, "<h", CONFIG_MODE)
"""Radius for magnetometer (cm?)"""

def __init__(self, i2c, address=0x28):
Expand All @@ -161,16 +161,15 @@ def _write_register(self, register, value):
def _read_register(self, register):
self.buffer[0] = register
with self.i2c_device as i2c:
i2c.write_then_readinto(self.buffer, self.buffer,
out_end=1, in_start=1)
i2c.write_then_readinto(self.buffer, self.buffer, out_end=1, in_start=1)
return self.buffer[1]

def _reset(self):
"""Resets the sensor to default settings."""
self.mode = CONFIG_MODE
try:
self._write_register(_TRIGGER_REGISTER, 0x20)
except OSError: # error due to the chip resetting
except OSError: # error due to the chip resetting
pass
# wait for the chip to reset (650 ms typ.)
time.sleep(0.7)
Expand Down Expand Up @@ -262,7 +261,6 @@ def use_external_crystal(self, value):
self.mode = last_mode
time.sleep(0.01)


@property
def temperature(self):
"""Measures the temperature of the chip in degrees Celsius."""
Expand Down Expand Up @@ -291,7 +289,7 @@ def gyro(self):
"""Gives the raw gyroscope reading in radians per second.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode not in [0x00, 0x01, 0x02, 0x04, 0x09, 0x0a]:
if self.mode not in [0x00, 0x01, 0x02, 0x04, 0x09, 0x0A]:
return self._gyro
return (None, None, None)

Expand All @@ -300,7 +298,7 @@ def euler(self):
"""Gives the calculated orientation angles, in degrees.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode in [0x09, 0x0b, 0x0c]:
if self.mode in [0x09, 0x0B, 0x0C]:
return self._euler
return (None, None, None)

Expand All @@ -309,7 +307,7 @@ def quaternion(self):
"""Gives the calculated orientation as a quaternion.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode in [0x09, 0x0b, 0x0c]:
if self.mode in [0x09, 0x0B, 0x0C]:
return self._quaternion
return (None, None, None, None)

Expand All @@ -318,7 +316,7 @@ def linear_acceleration(self):
"""Returns the linear acceleration, without gravity, in m/s.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode in [0x09, 0x0b, 0x0c]:
if self.mode in [0x09, 0x0B, 0x0C]:
return self._linear_acceleration
return (None, None, None)

Expand All @@ -327,6 +325,6 @@ def gravity(self):
"""Returns the gravity vector, without acceleration in m/s.
Returns an empty tuple of length 3 when this property has been disabled by the current mode.
"""
if self.mode in [0x09, 0x0b, 0x0c]:
if self.mode in [0x09, 0x0B, 0x0C]:
return self._gravity
return (None, None, None)

0 comments on commit 54d42f1

Please sign in to comment.