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_cap1188/cap1188.py b/adafruit_cap1188/cap1188.py index d8608fe..e05fae8 100644 --- a/adafruit_cap1188/cap1188.py +++ b/adafruit_cap1188/cap1188.py @@ -48,38 +48,42 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CAP1188.git" # pylint: disable=bad-whitespace -_CAP1188_MID = const(0x5D) -_CAP1188_PID = const(0x50) -_CAP1188_MAIN_CONTROL = const(0x00) -_CAP1188_GENERAL_STATUS = const(0x02) -_CAP1188_INPUT_STATUS = const(0x03) -_CAP1188_LED_STATUS = const(0x04) -_CAP1188_NOISE_FLAGS = const(0x0A) -_CAP1188_DELTA_COUNT =(const(0x10), - const(0x11), - const(0x12), - const(0x13), - const(0x14), - const(0x15), - const(0x16), - const(0x17)) -_CAP1188_SENSITIVTY = const(0x1F) -_CAP1188_CAL_ACTIVATE = const(0x26) -_CAP1188_MULTI_TOUCH_CFG = const(0x2A) -_CAP1188_THESHOLD_1 = const(0x30) -_CAP1188_STANDBY_CFG = const(0x41) -_CAP1188_LED_LINKING = const(0x72) -_CAP1188_PRODUCT_ID = const(0xFD) -_CAP1188_MANU_ID = const(0xFE) -_CAP1188_REVISION = const(0xFF) +_CAP1188_MID = const(0x5D) +_CAP1188_PID = const(0x50) +_CAP1188_MAIN_CONTROL = const(0x00) +_CAP1188_GENERAL_STATUS = const(0x02) +_CAP1188_INPUT_STATUS = const(0x03) +_CAP1188_LED_STATUS = const(0x04) +_CAP1188_NOISE_FLAGS = const(0x0A) +_CAP1188_DELTA_COUNT = ( + const(0x10), + const(0x11), + const(0x12), + const(0x13), + const(0x14), + const(0x15), + const(0x16), + const(0x17), +) +_CAP1188_SENSITIVTY = const(0x1F) +_CAP1188_CAL_ACTIVATE = const(0x26) +_CAP1188_MULTI_TOUCH_CFG = const(0x2A) +_CAP1188_THESHOLD_1 = const(0x30) +_CAP1188_STANDBY_CFG = const(0x41) +_CAP1188_LED_LINKING = const(0x72) +_CAP1188_PRODUCT_ID = const(0xFD) +_CAP1188_MANU_ID = const(0xFE) +_CAP1188_REVISION = const(0xFF) # pylint: enable=bad-whitespace _SENSITIVITY = (128, 64, 32, 16, 8, 4, 2, 1) + class CAP1188_Channel: # pylint: disable=protected-access """Helper class to represent a touch channel on the CAP1188. Not meant to be used directly.""" + def __init__(self, cap1188, pin): self._cap1188 = cap1188 self._pin = pin @@ -113,24 +117,29 @@ def recalibrate(self): class CAP1188: """CAP1188 driver base, must be extended for I2C/SPI interfacing.""" + def __init__(self): mid = self._read_register(_CAP1188_MANU_ID) if mid != _CAP1188_MID: - raise RuntimeError('Failed to find CAP1188! Manufacturer ID: 0x{:02x}'.format(mid)) + raise RuntimeError( + "Failed to find CAP1188! Manufacturer ID: 0x{:02x}".format(mid) + ) pid = self._read_register(_CAP1188_PRODUCT_ID) if pid != _CAP1188_PID: - raise RuntimeError('Failed to find CAP1188! Product ID: 0x{:02x}'.format(pid)) - self._channels = [None]*8 - self._write_register(_CAP1188_LED_LINKING, 0xFF) # turn on LED linking - self._write_register(_CAP1188_MULTI_TOUCH_CFG, 0x00) # allow multi touch - self._write_register(0x2F, 0x10) # turn off input-1-sets-all-inputs feature + raise RuntimeError( + "Failed to find CAP1188! Product ID: 0x{:02x}".format(pid) + ) + self._channels = [None] * 8 + self._write_register(_CAP1188_LED_LINKING, 0xFF) # turn on LED linking + self._write_register(_CAP1188_MULTI_TOUCH_CFG, 0x00) # allow multi touch + self._write_register(0x2F, 0x10) # turn off input-1-sets-all-inputs feature self.recalibrate() def __getitem__(self, key): pin = key index = key - 1 if pin < 1 or pin > 8: - raise IndexError('Pin must be a value 1-8.') + raise IndexError("Pin must be a value 1-8.") if self._channels[index] is None: self._channels[index] = CAP1188_Channel(self, pin) return self._channels[index] @@ -172,7 +181,7 @@ def thresholds(self, value): value = int(value) if not 0 <= value <= 127: raise ValueError("Threshold value must be in range 0 to 127.") - self._write_block(_CAP1188_THESHOLD_1, bytearray((value,)*8)) + self._write_block(_CAP1188_THESHOLD_1, bytearray((value,) * 8)) def threshold_values(self): """Return tuple of touch threshold values for all channels.""" @@ -185,9 +194,9 @@ def recalibrate(self): def delta_count(self, pin): """Return the 8 bit delta count value for the channel.""" if pin < 1 or pin > 8: - raise IndexError('Pin must be a value 1-8.') + raise IndexError("Pin must be a value 1-8.") # 8 bit 2's complement - raw_value = self._read_register(_CAP1188_DELTA_COUNT[pin-1]) + raw_value = self._read_register(_CAP1188_DELTA_COUNT[pin - 1]) raw_value = raw_value - 256 if raw_value & 128 else raw_value return raw_value diff --git a/adafruit_cap1188/i2c.py b/adafruit_cap1188/i2c.py index cca5bc7..1da5b4d 100644 --- a/adafruit_cap1188/i2c.py +++ b/adafruit_cap1188/i2c.py @@ -50,11 +50,13 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CAP1188.git" # pylint: disable=bad-whitespace -_CAP1188_DEFAULT_ADDRESS = const(0x29) +_CAP1188_DEFAULT_ADDRESS = const(0x29) # pylint: enable=bad-whitespace + class CAP1188_I2C(CAP1188): """Driver for the CAP1188 connected over I2C.""" + def __init__(self, i2c, address=_CAP1188_DEFAULT_ADDRESS): self._i2c = i2c_device.I2CDevice(i2c, address) self._buf = bytearray(2) diff --git a/adafruit_cap1188/spi.py b/adafruit_cap1188/spi.py index 28bea27..9a2fc1d 100644 --- a/adafruit_cap1188/spi.py +++ b/adafruit_cap1188/spi.py @@ -50,13 +50,15 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CAP1188.git" # pylint: disable=bad-whitespace -_CAP1188_SPI_SET_ADDR = const(0x7D) -_CAP1188_SPI_WRITE_DATA = const(0x7E) -_CAP1188_SPI_READ_DATA = const(0x7F) +_CAP1188_SPI_SET_ADDR = const(0x7D) +_CAP1188_SPI_WRITE_DATA = const(0x7E) +_CAP1188_SPI_READ_DATA = const(0x7F) # pylint: enable=bad-whitespace + class CAP1188_SPI(CAP1188): """Driver for the CAP1188 connected over SPI.""" + def __init__(self, spi, cs): self._spi = spi_device.SPIDevice(spi, cs) self._buf = bytearray(4) @@ -88,7 +90,7 @@ def _read_block(self, start, length): self._buf[0] = _CAP1188_SPI_SET_ADDR self._buf[1] = start self._buf[2] = _CAP1188_SPI_READ_DATA - result = bytearray((_CAP1188_SPI_READ_DATA,)*length) + result = bytearray((_CAP1188_SPI_READ_DATA,) * length) with self._spi as spi: spi.write(self._buf, end=3) spi.write_readinto(result, result) diff --git a/docs/conf.py b/docs/conf.py index 7ed8b77..ff1483a 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,41 +11,52 @@ # 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", ] # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -#autodoc_mock_imports = ["digitalio", "busio", "micropython"] - - -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)} +# autodoc_mock_imports = ["digitalio", "busio", "micropython"] + + +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 CAP1188 Library' -copyright = u'2018 Carter Nelson' -author = u'Carter Nelson' +project = u"Adafruit CAP1188 Library" +copyright = u"2018 Carter Nelson" +author = u"Carter Nelson" # 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. @@ -56,7 +68,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. @@ -68,7 +80,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 @@ -83,59 +95,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 = 'AdafruitCap1188Librarydoc' +htmlhelp_basename = "AdafruitCap1188Librarydoc" # -- 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, 'AdafruitCAP1188Library.tex', u'AdafruitCAP1188 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitCAP1188Library.tex", + u"AdafruitCAP1188 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -143,8 +158,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitCAP1188library', u'Adafruit CAP1188 Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitCAP1188library", + u"Adafruit CAP1188 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -153,7 +173,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitCAP1188Library', u'Adafruit CAP1188 Library Documentation', - author, 'AdafruitCAP1188Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitCAP1188Library", + u"Adafruit CAP1188 Library Documentation", + author, + "AdafruitCAP1188Library", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/cap1188_simpletest.py b/examples/cap1188_simpletest.py index 359d787..7ebcdda 100644 --- a/examples/cap1188_simpletest.py +++ b/examples/cap1188_simpletest.py @@ -3,6 +3,7 @@ # I2C setup from adafruit_cap1188.i2c import CAP1188_I2C + i2c = busio.I2C(board.SCL, board.SDA) cap = CAP1188_I2C(i2c) diff --git a/setup.py b/setup.py index e608962..4f26734 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -14,47 +15,38 @@ 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-cap1188', - + name="adafruit-circuitpython-cap1188", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython driver for the CAP1188 8-Key Capacitive Touch Sensor Breakout.', + setup_requires=["setuptools_scm"], + description="CircuitPython driver for the CAP1188 8-Key Capacitive Touch Sensor Breakout.", 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_CAP1188', - + url="https://github.com/adafruit/Adafruit_CircuitPython_CAP1188", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"], # 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 seesaw hardware micropython circuitpython', - + keywords="adafruit seesaw hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - packages=['adafruit_cap1188'], -) \ No newline at end of file + packages=["adafruit_cap1188"], +)