Skip to content

Commit

Permalink
Merge pull request #3 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 authored Mar 13, 2020
2 parents a6e224c + 134aebf commit f2a1da3
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 130 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
91 changes: 50 additions & 41 deletions adafruit_icm20649.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@
from adafruit_register.i2c_bit import RWBit
from adafruit_register.i2c_bits import RWBits

#pylint: disable=bad-whitespace
_ICM20649_DEFAULT_ADDRESS = 0x68 #icm20649 default i2c address
_ICM20649_DEVICE_ID = 0xE1 # Correct context of WHO_AM_I register
# pylint: disable=bad-whitespace
_ICM20649_DEFAULT_ADDRESS = 0x68 # icm20649 default i2c address
_ICM20649_DEVICE_ID = 0xE1 # Correct context of WHO_AM_I register

# Bank 0
_ICM20649_WHO_AM_I = 0x00 # device_id register
_ICM20649_REG_BANK_SEL = 0x7F # register bank selection register
_ICM20649_PWR_MGMT_1 = 0x06 #primary power management register
_ICM20649_ACCEL_XOUT_H = 0x2D # first byte of accel data
_ICM20649_GYRO_XOUT_H = 0x33 # first byte of accel data
_ICM20649_REG_BANK_SEL = 0x7F # register bank selection register
_ICM20649_PWR_MGMT_1 = 0x06 # primary power management register
_ICM20649_ACCEL_XOUT_H = 0x2D # first byte of accel data
_ICM20649_GYRO_XOUT_H = 0x33 # first byte of accel data

# Bank 2
_ICM20649_GYRO_SMPLRT_DIV = 0x00
_ICM20649_GYRO_CONFIG_1 = 0x01
_ICM20649_GYRO_CONFIG_1 = 0x01
_ICM20649_ACCEL_SMPLRT_DIV_1 = 0x10
_ICM20649_ACCEL_SMPLRT_DIV_2 = 0x11
_ICM20649_ACCEL_CONFIG_1 = 0x14
_ICM20649_ACCEL_CONFIG_1 = 0x14


G_TO_ACCEL = 9.80665
#pylint: enable=bad-whitespace
G_TO_ACCEL = 9.80665
# pylint: enable=bad-whitespace
class CV:
"""struct helper"""

Expand All @@ -96,31 +96,39 @@ def is_valid(cls, value):
return value in cls.string



class AccelRange(CV):
"""Options for ``accelerometer_range``"""
pass #pylint: disable=unnecessary-pass

AccelRange.add_values((
('RANGE_4G', 0, 4, 8192),
('RANGE_8G', 1, 8, 4096.0),
('RANGE_16G', 2, 16, 2048),
('RANGE_30G', 3, 30, 1024),
))
pass # pylint: disable=unnecessary-pass


AccelRange.add_values(
(
("RANGE_4G", 0, 4, 8192),
("RANGE_8G", 1, 8, 4096.0),
("RANGE_16G", 2, 16, 2048),
("RANGE_30G", 3, 30, 1024),
)
)


class GyroRange(CV):
"""Options for ``gyro_data_range``"""
pass #pylint: disable=unnecessary-pass

GyroRange.add_values((
('RANGE_500_DPS', 0, 500, 65.5),
('RANGE_1000_DPS', 1, 1000, 32.8),
('RANGE_2000_DPS', 2, 2000, 16.4),
('RANGE_4000_DPS', 3, 4000, 8.2)
))
pass # pylint: disable=unnecessary-pass


class ICM20649: #pylint:disable=too-many-instance-attributes
GyroRange.add_values(
(
("RANGE_500_DPS", 0, 500, 65.5),
("RANGE_1000_DPS", 1, 1000, 32.8),
("RANGE_2000_DPS", 2, 2000, 16.4),
("RANGE_4000_DPS", 3, 4000, 8.2),
)
)


class ICM20649: # pylint:disable=too-many-instance-attributes
"""Library for the ST ICM-20649 Wide-Range 6-DoF Accelerometer and Gyro.
:param ~busio.I2C i2c_bus: The I2C bus the ICM20649 is connected to.
Expand Down Expand Up @@ -159,19 +167,18 @@ def __init__(self, i2c_bus, address=_ICM20649_DEFAULT_ADDRESS):
self._sleep = False

self._bank = 2
self._accel_range = AccelRange.RANGE_8G #pylint: disable=no-member
self._accel_range = AccelRange.RANGE_8G # pylint: disable=no-member
self._cached_accel_range = self._accel_range

#TODO: CV-ify
# TODO: CV-ify
self._accel_dlpf_config = 3


# 1.125 kHz/(1+ACCEL_SMPLRT_DIV[11:0]),
# 1125Hz/(1+20) = 53.57Hz
self._accel_rate_divisor = 20

# writeByte(ICM20649_ADDR,GYRO_CONFIG_1, gyroConfig);
self._gyro_range = GyroRange.RANGE_500_DPS #pylint: disable=no-member
self._gyro_range = GyroRange.RANGE_500_DPS # pylint: disable=no-member
sleep(0.100)
self._cached_gyro_range = self._gyro_range

Expand All @@ -196,7 +203,7 @@ def acceleration(self):
y = self._scale_xl_data(raw_accel_data[1])
z = self._scale_xl_data(raw_accel_data[2])

return(x, y, z)
return (x, y, z)

@property
def gyro(self):
Expand All @@ -221,7 +228,7 @@ def accelerometer_range(self):
return self._cached_accel_range

@accelerometer_range.setter
def accelerometer_range(self, value): #pylint: disable=no-member
def accelerometer_range(self, value): # pylint: disable=no-member
if not AccelRange.is_valid(value):
raise AttributeError("range must be an `AccelRange`")
self._bank = 2
Expand All @@ -244,7 +251,7 @@ def gyro_range(self, value):
self._gyro_range = value
self._cached_gyro_range = value
self._bank = 0
sleep(.100) # needed to let new range settle
sleep(0.100) # needed to let new range settle

@property
def accelerometer_data_rate_divisor(self):
Expand All @@ -258,7 +265,7 @@ def accelerometer_data_rate_divisor(self):
self._bank = 2
raw_rate_divisor = self._accel_rate_divisor
self._bank = 0
#rate_hz = 1125/(1+raw_rate_divisor)
# rate_hz = 1125/(1+raw_rate_divisor)
return raw_rate_divisor

@accelerometer_data_rate_divisor.setter
Expand Down Expand Up @@ -291,11 +298,11 @@ def gyro_data_rate_divisor(self, value):
self._gyro_rate_divisor = value
self._bank = 0

def _accel_rate_calc(self, divisor):#pylint:disable=no-self-use
return 1125/(1+divisor)
def _accel_rate_calc(self, divisor): # pylint:disable=no-self-use
return 1125 / (1 + divisor)

def _gyro_rate_calc(self, divisor):#pylint:disable=no-self-use
return 1100/(1+divisor)
def _gyro_rate_calc(self, divisor): # pylint:disable=no-self-use
return 1100 / (1 + divisor)

@property
def accelerometer_data_rate(self):
Expand All @@ -312,7 +319,9 @@ def accelerometer_data_rate(self):
@accelerometer_data_rate.setter
def accelerometer_data_rate(self, value):
if value < self._accel_rate_calc(4095) or value > self._accel_rate_calc(0):
raise AttributeError("Accelerometer data rate must be between 0.27 and 1125.0")
raise AttributeError(
"Accelerometer data rate must be between 0.27 and 1125.0"
)
self.accelerometer_data_rate_divisor = value

@property
Expand All @@ -332,5 +341,5 @@ def gyro_data_rate(self, value):
if value < self._gyro_rate_calc(4095) or value > self._gyro_rate_calc(0):
raise AttributeError("Gyro data rate must be between 4.30 and 1100.0")

divisor = round(((1125.0-value)/ value))
divisor = round(((1125.0 - value) / value))
self.gyro_data_rate_divisor = divisor
Loading

0 comments on commit f2a1da3

Please sign in to comment.