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_neotrellis/multitrellis.py b/adafruit_neotrellis/multitrellis.py index 70babe7..8898adf 100644 --- a/adafruit_neotrellis/multitrellis.py +++ b/adafruit_neotrellis/multitrellis.py @@ -30,19 +30,23 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_neotrellis.git" from time import sleep -from adafruit_seesaw.keypad import KeyEvent from micropython import const +from adafruit_seesaw.keypad import KeyEvent _NEO_TRELLIS_NUM_KEYS = const(16) + def _key(xval): - return int(int(xval/4)*8 + (xval%4)) + return int(int(xval / 4) * 8 + (xval % 4)) + def _seesaw_key(xval): - return int(int(xval/8)*4 + (xval%8)) + return int(int(xval / 8) * 4 + (xval % 8)) + -class MultiTrellis(object): +class MultiTrellis: """Driver for multiple connected Adafruit NeoTrellis boards.""" + def __init__(self, neotrellis_array): self._trelli = neotrellis_array self._rows = len(neotrellis_array) @@ -54,23 +58,23 @@ def activate_key(self, x, y, edge, enable=True): edge to register an event on and can be NeoTrellis.EDGE_FALLING or NeoTrellis.EDGE_RISING. enable should be set to True if the event is to be enabled, or False if the event is to be disabled.""" - xkey = x%4 - ykey = int(int(y%4)*4/4) - self._trelli[int(y/4)][int(x/4)].activate_key(ykey*4 + xkey, edge, enable) + xkey = x % 4 + ykey = int(int(y % 4) * 4 / 4) + self._trelli[int(y / 4)][int(x / 4)].activate_key(ykey * 4 + xkey, edge, enable) def set_callback(self, x, y, function): """Set a callback function for when an event for the key at index x, y (measured from the top lefthand corner) is detected.""" - xkey = x%4 - ykey = int(int(y%4)*4/4) - self._trelli[int(y/4)][int(x/4)].callbacks[ykey*4 + xkey] = function + xkey = x % 4 + ykey = int(int(y % 4) * 4 / 4) + self._trelli[int(y / 4)][int(x / 4)].callbacks[ykey * 4 + xkey] = function def color(self, x, y, color): """Set the color of the pixel at index x, y measured from the top lefthand corner of the matrix""" - xkey = x%4 - ykey = int(int(y%4)*4/4) - self._trelli[int(y/4)][int(x/4)].pixels[ykey*4 + xkey] = color + xkey = x % 4 + ykey = int(int(y % 4) * 4 / 4) + self._trelli[int(y / 4)][int(x / 4)].pixels[ykey * 4 + xkey] = color def sync(self): """Read all trellis boards in the matrix and call any callbacks""" @@ -79,14 +83,16 @@ def sync(self): _t = self._trelli[_n][_m] available = _t.count - sleep(.0005) + sleep(0.0005) if available > 0: available = available + 2 buf = _t.read_keypad(available) for raw in buf: evt = KeyEvent(_seesaw_key((raw >> 2) & 0x3F), raw & 0x3) - if evt.number < _NEO_TRELLIS_NUM_KEYS \ - and _t.callbacks[evt.number] is not None: - y = int(evt.number/4)+_n*4 - x = int(evt.number%4)+_m*4 + if ( + evt.number < _NEO_TRELLIS_NUM_KEYS + and _t.callbacks[evt.number] is not None + ): + y = int(evt.number / 4) + _n * 4 + x = int(evt.number % 4) + _m * 4 _t.callbacks[evt.number](x, y, evt.edge) diff --git a/adafruit_neotrellis/neotrellis.py b/adafruit_neotrellis/neotrellis.py index 28c18c5..104a08b 100644 --- a/adafruit_neotrellis/neotrellis.py +++ b/adafruit_neotrellis/neotrellis.py @@ -61,14 +61,18 @@ _NEO_TRELLIS_MAX_CALLBACKS = const(32) + def _key(xval): - return int(int(xval/4)*8 + (xval%4)) + return int(int(xval / 4) * 8 + (xval % 4)) + def _seesaw_key(xval): - return int(int(xval/8)*4 + (xval%8)) + return int(int(xval / 8) * 4 + (xval % 8)) + class NeoTrellis(Keypad): """Driver for the Adafruit NeoTrellis.""" + def __init__(self, i2c_bus, interrupt=False, addr=_NEO_TRELLIS_ADDR, drdy=None): super().__init__(i2c_bus, addr, drdy) self.interrupt_enabled = interrupt @@ -87,11 +91,14 @@ def sync(self): """read any events from the Trellis hardware and call associated callbacks""" available = self.count - sleep(.0005) + sleep(0.0005) if available > 0: available = available + 2 buf = self.read_keypad(available) for raw in buf: evt = KeyEvent(_seesaw_key((raw >> 2) & 0x3F), raw & 0x3) - if evt.number < _NEO_TRELLIS_NUM_KEYS and self.callbacks[evt.number] is not None: + if ( + evt.number < _NEO_TRELLIS_NUM_KEYS + and self.callbacks[evt.number] is not None + ): self.callbacks[evt.number](evt) diff --git a/docs/conf.py b/docs/conf.py index 1f9c07a..2027453 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 = ["digitalio", "busio", "micropython", "adafruit_seesaw"] -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 NeoTrellis Library' -copyright = u'2018 Dean Miller' -author = u'Dean Miller' +project = u"Adafruit NeoTrellis Library" +copyright = u"2018 Dean Miller" +author = u"Dean Miller" # 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 = 'AdafruitNeoTrellisLibrarydoc' +htmlhelp_basename = "AdafruitNeoTrellisLibrarydoc" # -- 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, 'AdafruitNeoTrellisLibrary.tex', u'AdafruitNeoTrellis Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitNeoTrellisLibrary.tex", + u"AdafruitNeoTrellis 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, 'AdafruitNeoTrellisLibrary', u'Adafruit NeoTrellis Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitNeoTrellisLibrary", + u"Adafruit NeoTrellis 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, 'AdafruitNeoTrellisLibrary', u'Adafruit NeoTrellis Library Documentation', - author, 'AdafruitNeoTrellisLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitNeoTrellisLibrary", + u"Adafruit NeoTrellis Library Documentation", + author, + "AdafruitNeoTrellisLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/neotrellis_multitrellis_simpletest.py b/examples/neotrellis_multitrellis_simpletest.py index 8c9cf71..0b32a44 100644 --- a/examples/neotrellis_multitrellis_simpletest.py +++ b/examples/neotrellis_multitrellis_simpletest.py @@ -5,7 +5,7 @@ from adafruit_neotrellis.neotrellis import NeoTrellis from adafruit_neotrellis.multitrellis import MultiTrellis -#create the i2c object for the trellis +# create the i2c object for the trellis i2c_bus = busio.I2C(SCL, SDA) """create the trellis. This is for a 2x2 array of NeoTrellis boards @@ -18,12 +18,12 @@ """ trelli = [ [NeoTrellis(i2c_bus, False, addr=0x2E), NeoTrellis(i2c_bus, False, addr=0x2F)], - [NeoTrellis(i2c_bus, False, addr=0x30), NeoTrellis(i2c_bus, False, addr=0x31)] - ] + [NeoTrellis(i2c_bus, False, addr=0x30), NeoTrellis(i2c_bus, False, addr=0x31)], +] trellis = MultiTrellis(trelli) -#some color definitions +# some color definitions OFF = (0, 0, 0) RED = (255, 0, 0) YELLOW = (255, 150, 0) @@ -32,31 +32,32 @@ BLUE = (0, 0, 255) PURPLE = (180, 0, 255) -#this will be called when button events are received +# this will be called when button events are received def blink(xcoord, ycoord, edge): - #turn the LED on when a rising edge is detected + # turn the LED on when a rising edge is detected if edge == NeoTrellis.EDGE_RISING: trellis.color(xcoord, ycoord, BLUE) - #turn the LED off when a rising edge is detected + # turn the LED off when a rising edge is detected elif edge == NeoTrellis.EDGE_FALLING: trellis.color(xcoord, ycoord, OFF) + for y in range(8): for x in range(8): - #activate rising edge events on all keys + # activate rising edge events on all keys trellis.activate_key(x, y, NeoTrellis.EDGE_RISING) - #activate falling edge events on all keys + # activate falling edge events on all keys trellis.activate_key(x, y, NeoTrellis.EDGE_FALLING) trellis.set_callback(x, y, blink) trellis.color(x, y, PURPLE) - time.sleep(.05) + time.sleep(0.05) for y in range(8): for x in range(8): trellis.color(x, y, OFF) - time.sleep(.05) + time.sleep(0.05) while True: - #the trellis can only be read every 17 millisecons or so + # the trellis can only be read every 17 millisecons or so trellis.sync() - time.sleep(.02) + time.sleep(0.02) diff --git a/examples/neotrellis_simpletest.py b/examples/neotrellis_simpletest.py index 42a7572..cd1a82f 100644 --- a/examples/neotrellis_simpletest.py +++ b/examples/neotrellis_simpletest.py @@ -4,13 +4,13 @@ import busio from adafruit_neotrellis.neotrellis import NeoTrellis -#create the i2c object for the trellis +# create the i2c object for the trellis i2c_bus = busio.I2C(SCL, SDA) -#create the trellis +# create the trellis trellis = NeoTrellis(i2c_bus) -#some color definitions +# some color definitions OFF = (0, 0, 0) RED = (255, 0, 0) YELLOW = (255, 150, 0) @@ -19,33 +19,34 @@ BLUE = (0, 0, 255) PURPLE = (180, 0, 255) -#this will be called when button events are received +# this will be called when button events are received def blink(event): - #turn the LED on when a rising edge is detected + # turn the LED on when a rising edge is detected if event.edge == NeoTrellis.EDGE_RISING: trellis.pixels[event.number] = CYAN - #turn the LED off when a rising edge is detected + # turn the LED off when a rising edge is detected elif event.edge == NeoTrellis.EDGE_FALLING: trellis.pixels[event.number] = OFF + for i in range(16): - #activate rising edge events on all keys + # activate rising edge events on all keys trellis.activate_key(i, NeoTrellis.EDGE_RISING) - #activate falling edge events on all keys + # activate falling edge events on all keys trellis.activate_key(i, NeoTrellis.EDGE_FALLING) - #set all keys to trigger the blink callback + # set all keys to trigger the blink callback trellis.callbacks[i] = blink - #cycle the LEDs on startup + # cycle the LEDs on startup trellis.pixels[i] = PURPLE - time.sleep(.05) + time.sleep(0.05) for i in range(16): trellis.pixels[i] = OFF - time.sleep(.05) + time.sleep(0.05) while True: - #call the sync function call any triggered callbacks + # call the sync function call any triggered callbacks trellis.sync() - #the trellis can only be read every 17 millisecons or so - time.sleep(.02) + # the trellis can only be read every 17 millisecons or so + time.sleep(0.02) diff --git a/setup.py b/setup.py index cf81bc0..ade99b2 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,48 +15,39 @@ 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-neotrellis', - + name="adafruit-circuitpython-neotrellis", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for using Adafruit NeoTrellis.', + setup_requires=["setuptools_scm"], + description="CircuitPython library for using Adafruit NeoTrellis.", 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_NeoTrellis', - + url="https://github.com/adafruit/Adafruit_CircuitPython_NeoTrellis", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-seesaw'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka", "adafruit-circuitpython-seesaw"], # 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 neotrellis neopixel trellis led rgb' - 'sensor hardware micropython circuitpython', - + keywords="adafruit neotrellis neopixel trellis led rgb" + "sensor hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - packages=['adafruit_neotrellis'], + packages=["adafruit_neotrellis"], )