diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/adafruit_icm20649.py b/adafruit_icm20649.py index 78d967b..36f6ebd 100644 --- a/adafruit_icm20649.py +++ b/adafruit_icm20649.py @@ -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""" @@ -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. @@ -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 @@ -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): @@ -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 @@ -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): @@ -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 @@ -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): @@ -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 @@ -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 diff --git a/docs/conf.py b/docs/conf.py index 4f6f0e6..a1adf75 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,10 +11,10 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] # TODO: Please Read! @@ -23,29 +24,40 @@ autodoc_mock_imports = ["adafruit_register", "adafruit_bus_device"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice": ( + "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + None, + ), + "Register": ( + "https://circuitpython.readthedocs.io/projects/register/en/latest/", + None, + ), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit ICM20649 Library' -copyright = u'2019 Bryan Siepert' -author = u'Bryan Siepert' +project = u"Adafruit ICM20649 Library" +copyright = u"2019 Bryan Siepert" +author = u"Bryan Siepert" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -57,7 +69,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -69,7 +81,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -84,59 +96,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitIcm20649Librarydoc' +htmlhelp_basename = "AdafruitIcm20649Librarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitICM20649Library.tex', u'AdafruitICM20649 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitICM20649Library.tex", + u"AdafruitICM20649 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -144,8 +159,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitICM20649library', u'Adafruit ICM20649 Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitICM20649library", + u"Adafruit ICM20649 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -154,7 +174,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitICM20649Library', u'Adafruit ICM20649 Library Documentation', - author, 'AdafruitICM20649Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitICM20649Library", + u"Adafruit ICM20649 Library Documentation", + author, + "AdafruitICM20649Library", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/icm20649_full_test.py b/examples/icm20649_full_test.py index bc840f8..ef7ad22 100644 --- a/examples/icm20649_full_test.py +++ b/examples/icm20649_full_test.py @@ -3,22 +3,24 @@ import busio from adafruit_icm20649 import ICM20649, AccelRange, GyroRange + def printNewMax(value, current_max, axis): if value > current_max: current_max = value print(axis, "Max:", current_max) return current_max -#pylint:disable=no-member + +# pylint:disable=no-member i2c = busio.I2C(board.SCL, board.SDA) ism = ICM20649(i2c) ism.accelerometer_range = AccelRange.RANGE_30G -print("Accelerometer range set to: %d G"%AccelRange.string[ism.accelerometer_range]) +print("Accelerometer range set to: %d G" % AccelRange.string[ism.accelerometer_range]) ism.gyro_range = GyroRange.RANGE_500_DPS -print("Gyro range set to: %d DPS"%GyroRange.string[ism.gyro_range]) +print("Gyro range set to: %d DPS" % GyroRange.string[ism.gyro_range]) ax_max = ay_max = az_max = 0 gx_max = gy_max = gz_max = 0 @@ -26,10 +28,12 @@ def printNewMax(value, current_max, axis): ism.gyro_data_rate = 125 ism.accelerometer_data_rate = 4095 st = time.monotonic() -while time.monotonic()-st < 0.250: +while time.monotonic() - st < 0.250: - print("Accel X:%.2f Y:%.2f Z:%.2f ms^2 Gyro X:%.2f Y:%.2f Z:%.2f degrees/s" - %(ism.acceleration+ism.gyro)) + print( + "Accel X:%.2f Y:%.2f Z:%.2f ms^2 Gyro X:%.2f Y:%.2f Z:%.2f degrees/s" + % (ism.acceleration + ism.gyro) + ) # acceleration = ism.acceleration # # ax_max = printNewMax(acceleration[0], ax_max, "AX") diff --git a/examples/icm20649_simpletest.py b/examples/icm20649_simpletest.py index 35e5e08..66e92e5 100644 --- a/examples/icm20649_simpletest.py +++ b/examples/icm20649_simpletest.py @@ -4,10 +4,10 @@ import adafruit_icm20649 i2c = busio.I2C(board.SCL, board.SDA) -icm = adafruit_icm20649.ICM20649(i2c) +icm = adafruit_icm20649.ICM20649(i2c) while True: - print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2"%(icm.acceleration)) - print("Gyro X:%.2f, Y: %.2f, Z: %.2f degrees/s"%(icm.gyro)) + print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (icm.acceleration)) + print("Gyro X:%.2f, Y: %.2f, Z: %.2f degrees/s" % (icm.gyro)) print("") time.sleep(0.5) diff --git a/setup.py b/setup.py index 5de683b..0a294e6 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ """ from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -13,54 +14,45 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-icm20649', - + name="adafruit-circuitpython-icm20649", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='Library for the ST ICM-20649 Wide-Range 6-DoF Accelerometer and Gyro', + setup_requires=["setuptools_scm"], + description="Library for the ST ICM-20649 Wide-Range 6-DoF Accelerometer and Gyro", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_ICM20649', - + url="https://github.com/adafruit/Adafruit_CircuitPython_ICM20649", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", install_requires=[ - 'Adafruit-Blinka', - 'adafruit-circuitpython-busdevice', - 'adafruit-circuitpython-register' + "Adafruit-Blinka", + "adafruit-circuitpython-busdevice", + "adafruit-circuitpython-register", ], - # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit blinka circuitpython micropython icm20649 gyro accelerometer high-G ' - '6-axis wide range', - + keywords="adafruit blinka circuitpython micropython icm20649 gyro accelerometer high-G " + "6-axis wide range", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=['adafruit_icm20649'], + py_modules=["adafruit_icm20649"], )