Skip to content

Ran black, updated to pylint 2.x #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
102 changes: 73 additions & 29 deletions adafruit_trellis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -128,6 +172,7 @@ class Trellis():
:linenos:

"""

def __init__(self, i2c, addresses=None):
if addresses is None:
addresses = [0x70]
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
118 changes: 72 additions & 46 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,59 @@

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))

# -- General configuration ------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# 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
# 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 = ["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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -80,68 +92,76 @@
# 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 ---------------------------------------

# 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 -------------------------------------------
Expand All @@ -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",
),
]
Loading