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_trellis.py b/adafruit_trellis.py index 185f849..4b03f41 100644 --- a/adafruit_trellis.py +++ b/adafruit_trellis.py @@ -54,44 +54,84 @@ # HT16K33 Command Contstants # pylint: disable=bad-whitespace, invalid-name -_HT16K33_OSCILATOR_ON = const(0x21) -_HT16K33_BLINK_CMD = const(0x80) -_HT16K33_BLINK_DISPLAYON = const(0x01) -_HT16K33_CMD_BRIGHTNESS = const(0xE0) -_HT16K33_KEY_READ_CMD = const(0x40) +_HT16K33_OSCILATOR_ON = const(0x21) +_HT16K33_BLINK_CMD = const(0x80) +_HT16K33_BLINK_DISPLAYON = const(0x01) +_HT16K33_CMD_BRIGHTNESS = const(0xE0) +_HT16K33_KEY_READ_CMD = const(0x40) # LED Lookup Table -ledLUT = (0x3A, 0x37, 0x35, 0x34, - 0x28, 0x29, 0x23, 0x24, - 0x16, 0x1B, 0x11, 0x10, - 0x0E, 0x0D, 0x0C, 0x02) +ledLUT = ( + 0x3A, + 0x37, + 0x35, + 0x34, + 0x28, + 0x29, + 0x23, + 0x24, + 0x16, + 0x1B, + 0x11, + 0x10, + 0x0E, + 0x0D, + 0x0C, + 0x02, +) # Button Loookup Table -buttonLUT = (0x07, 0x04, 0x02, 0x22, - 0x05, 0x06, 0x00, 0x01, - 0x03, 0x10, 0x30, 0x21, - 0x13, 0x12, 0x11, 0x31) +buttonLUT = ( + 0x07, + 0x04, + 0x02, + 0x22, + 0x05, + 0x06, + 0x00, + 0x01, + 0x03, + 0x10, + 0x30, + 0x21, + 0x13, + 0x12, + 0x11, + 0x31, +) # pylint: enable=bad-whitespace, invalid-name # pylint: disable=missing-docstring, protected-access -class TrellisLEDs(): +class TrellisLEDs: def __init__(self, trellis_obj): self._parent = trellis_obj def __getitem__(self, x): if 0 < x >= self._parent._num_leds: - raise ValueError(('LED number must be between 0 -', self._parent._num_leds - 1)) + raise ValueError( + ("LED number must be between 0 -", self._parent._num_leds - 1) + ) led = ledLUT[x % 16] >> 4 - mask = 1 << (ledLUT[x % 16] & 0x0f) - return bool(((self._parent._led_buffer[x // 16][(led * 2) + 1] | \ - self._parent._led_buffer[x // 16][(led * 2) + 2] << 8) & mask) > 0) + mask = 1 << (ledLUT[x % 16] & 0x0F) + return bool( + ( + ( + self._parent._led_buffer[x // 16][(led * 2) + 1] + | self._parent._led_buffer[x // 16][(led * 2) + 2] << 8 + ) + & mask + ) + > 0 + ) def __setitem__(self, x, value): if 0 < x >= self._parent._num_leds: - raise ValueError(('LED number must be between 0 -', self._parent._num_leds - 1)) + raise ValueError( + ("LED number must be between 0 -", self._parent._num_leds - 1) + ) led = ledLUT[x % 16] >> 4 - mask = 1 << (ledLUT[x % 16] & 0x0f) + mask = 1 << (ledLUT[x % 16] & 0x0F) if value: - self._parent._led_buffer[x // 16][(led * 2) + 1] |= (mask & 0xff) + self._parent._led_buffer[x // 16][(led * 2) + 1] |= mask & 0xFF self._parent._led_buffer[x // 16][(led * 2) + 2] |= mask >> 8 elif not value: self._parent._led_buffer[x // 16][(led * 2) + 1] &= ~mask @@ -101,17 +141,21 @@ def __setitem__(self, x, value): if self._parent._auto_show: self._parent.show() + # pylint: disable=invalid-name def fill(self, on): - fill = 0xff if on else 0x00 + fill = 0xFF if on else 0x00 for buff in range(len(self._parent._i2c_devices)): for i in range(1, 17): self._parent._led_buffer[buff][i] = fill if self._parent._auto_show: self._parent.show() + + # pylint: enable=missing-docstring, protected-access -class Trellis(): + +class Trellis: """ Driver base for a single Trellis Board @@ -128,6 +172,7 @@ class Trellis(): :linenos: """ + def __init__(self, i2c, addresses=None): if addresses is None: addresses = [0x70] @@ -173,11 +218,10 @@ def blink_rate(self): @blink_rate.setter def blink_rate(self, rate): if not 0 <= rate <= 3: - raise ValueError('Blink rate must be an integer in the range: 0-3') + raise ValueError("Blink rate must be an integer in the range: 0-3") rate = rate & 0x03 self._blink_rate = rate - self._write_cmd(_HT16K33_BLINK_CMD | - _HT16K33_BLINK_DISPLAYON | rate << 1) + self._write_cmd(_HT16K33_BLINK_CMD | _HT16K33_BLINK_DISPLAYON | rate << 1) @property def brightness(self): @@ -189,7 +233,7 @@ def brightness(self): @brightness.setter def brightness(self, brightness): if not 0 <= brightness <= 15: - raise ValueError('Brightness must be an integer in the range: 0-15') + raise ValueError("Brightness must be an integer in the range: 0-15") brightness = brightness & 0x0F self._brightness = brightness self._write_cmd(_HT16K33_CMD_BRIGHTNESS | brightness) @@ -241,11 +285,11 @@ def read_buttons(self): return pressed, released def _is_pressed(self, button): - mask = 1 << (buttonLUT[button % 16] & 0x0f) + mask = 1 << (buttonLUT[button % 16] & 0x0F) return self._buttons[button // 16][1][(buttonLUT[button % 16] >> 4)] & mask def _was_pressed(self, button): - mask = 1 << (buttonLUT[button % 16] & 0x0f) + mask = 1 << (buttonLUT[button % 16] & 0x0F) return self._buttons[button // 16][0][(buttonLUT[button % 16] >> 4)] & mask def _just_pressed(self, button): diff --git a/docs/conf.py b/docs/conf.py index c56811a..3c4dbf2 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,9 +11,9 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.todo", ] # Uncomment the below if you use native CircuitPython modules such as @@ -20,29 +21,40 @@ # autodoc module docs will fail to generate with a warning. # autodoc_mock_imports = ["micropython", "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 Trellis Library' -copyright = u'2017 Michael Schroeder' -author = u'Michael Schroeder' +project = u"Adafruit Trellis Library" +copyright = u"2017 Michael Schroeder" +author = u"Michael Schroeder" # 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. @@ -54,7 +66,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. @@ -66,7 +78,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 @@ -80,59 +92,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 = 'AdafruitTrellisLibrarydoc' +htmlhelp_basename = "AdafruitTrellisLibrarydoc" # -- 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, 'AdafruitTrellisLibrary.tex', u'AdafruitTrellis Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitTrellisLibrary.tex", + u"AdafruitTrellis Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -140,8 +155,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitTrellislibrary', u'Adafruit Trellis Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitTrellislibrary", + u"Adafruit Trellis Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -150,7 +170,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitTrellisLibrary', u'Adafruit Trellis Library Documentation', - author, 'AdafruitTrellisLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitTrellisLibrary", + u"Adafruit Trellis Library Documentation", + author, + "AdafruitTrellisLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/trellis_simpletest.py b/examples/trellis_simpletest.py index b1f8414..bf7c919 100644 --- a/examples/trellis_simpletest.py +++ b/examples/trellis_simpletest.py @@ -22,26 +22,26 @@ # method afterwards to send updates to the Trellis board. # Turn on every LED -print('Turning all LEDs on...') +print("Turning all LEDs on...") trellis.led.fill(True) time.sleep(2) # Turn off every LED -print('Turning all LEDs off...') +print("Turning all LEDs off...") trellis.led.fill(False) time.sleep(2) # Turn on every LED, one at a time -print('Turning on each LED, one at a time...') +print("Turning on each LED, one at a time...") for i in range(16): trellis.led[i] = True - time.sleep(.1) + time.sleep(0.1) # Turn off every LED, one at a time -print('Turning off each LED, one at a time...') +print("Turning off each LED, one at a time...") for i in range(15, 0, -1): trellis.led[i] = False - time.sleep(.1) + time.sleep(0.1) # Now start reading button activity # - When a button is depressed (just_pressed), @@ -50,22 +50,22 @@ # the LED will turn off. # - Any button that is still depressed (pressed_buttons), # the LED will remain on. -print('Starting button sensory loop...') +print("Starting button sensory loop...") pressed_buttons = set() while True: # Make sure to take a break during each trellis.read_buttons # cycle. - time.sleep(.1) + time.sleep(0.1) just_pressed, released = trellis.read_buttons() for b in just_pressed: - print('pressed:', b) + print("pressed:", b) trellis.led[b] = True pressed_buttons.update(just_pressed) for b in released: - print('released:', b) + print("released:", b) trellis.led[b] = False pressed_buttons.difference_update(released) for b in pressed_buttons: - print('still pressed:', b) + print("still pressed:", b) trellis.led[b] = True diff --git a/setup.py b/setup.py index 1afca37..51015ce 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-trellis', - + name="adafruit-circuitpython-trellis", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for Adafruit Trellis boards.', + setup_requires=["setuptools_scm"], + description="CircuitPython library for Adafruit Trellis boards.", 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_trellis', - + url="https://github.com/adafruit/Adafruit_CircuitPython_trellis", # 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 trellis button led board hardware micropython circuitpython', - + keywords="adafruit trellis button led board hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['adafruit_trellis'], + py_modules=["adafruit_trellis"], )