Skip to content

Commit

Permalink
Merge pull request #24 from adafruit/pylint-update
Browse files Browse the repository at this point in the history
Ran black, updated to pylint 2.x
  • Loading branch information
kattni authored Mar 17, 2020
2 parents 3c1be30 + 2a0e60c commit a8527a5
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 143 deletions.
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
55 changes: 32 additions & 23 deletions adafruit_is31fl3731.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
_AUDIOSYNC_REGISTER = const(0x06)
_BREATH1_REGISTER = const(0x08)
_BREATH2_REGISTER = const(0x09)
_SHUTDOWN_REGISTER = const(0x0a)
_GAIN_REGISTER = const(0x0b)
_ADC_REGISTER = const(0x0c)
_SHUTDOWN_REGISTER = const(0x0A)
_GAIN_REGISTER = const(0x0B)
_ADC_REGISTER = const(0x0C)

_CONFIG_BANK = const(0x0b)
_BANK_ADDRESS = const(0xfd)
_CONFIG_BANK = const(0x0B)
_BANK_ADDRESS = const(0xFD)

_PICTURE_MODE = const(0x00)
_AUTOPLAY_MODE = const(0x08)
Expand All @@ -77,13 +77,15 @@
_BLINK_OFFSET = const(0x12)
_COLOR_OFFSET = const(0x24)


class Matrix:
"""
The Matrix class support the main function for driving the 16x9 matrix Display
:param ~adafruit_bus_device.i2c_device i2c_device: the connected i2c bus i2c_device
:param address: the device address; defaults to 0x74
"""

width = 16
height = 9

Expand Down Expand Up @@ -127,7 +129,6 @@ def _bank(self, bank=None):
self._i2c_write_reg(_BANK_ADDRESS, bytearray([bank]))
return None


def _register(self, bank, register, value=None):
self._bank(bank)
if value is None:
Expand All @@ -145,7 +146,7 @@ def _init(self):
for frame in range(8):
self.fill(0, False, frame=frame)
for col in range(18):
self._register(frame, _ENABLE_OFFSET + col, 0xff)
self._register(frame, _ENABLE_OFFSET + col, 0xFF)
self.audio_sync(False)

def reset(self):
Expand Down Expand Up @@ -184,7 +185,6 @@ def autoplay(self, delay=0, loops=0, frames=0):
self._register(_CONFIG_BANK, _AUTOPLAY2_REGISTER, delay % 64)
self._mode(_AUTOPLAY_MODE | self._frame)


def fade(self, fade_in=None, fade_out=None, pause=0):
"""
Start and stop the fade feature. If both fade_in and fade_out are None (the
Expand Down Expand Up @@ -234,8 +234,7 @@ def audio_sync(self, value=None):
"""
return self._register(_CONFIG_BANK, _AUDIOSYNC_REGISTER, value)

def audio_play(self, sample_rate, audio_gain=0,
agc_enable=False, agc_fast=False):
def audio_play(self, sample_rate, audio_gain=0, agc_enable=False, agc_fast=False):
"""Controls the audio play feature
"""
if sample_rate == 0:
Expand All @@ -248,8 +247,11 @@ def audio_play(self, sample_rate, audio_gain=0,
audio_gain //= 3
if not 0 <= audio_gain <= 7:
raise ValueError("Audio gain out of range")
self._register(_CONFIG_BANK, _GAIN_REGISTER,
bool(agc_enable) << 3 | bool(agc_fast) << 4 | audio_gain)
self._register(
_CONFIG_BANK,
_GAIN_REGISTER,
bool(agc_enable) << 3 | bool(agc_fast) << 4 | audio_gain,
)
self._mode(_AUDIOPLAY_MODE)

def blink(self, rate=None):
Expand Down Expand Up @@ -280,7 +282,7 @@ def fill(self, color=None, blink=None, frame=None):
if color is not None:
if not 0 <= color <= 255:
raise ValueError("Color out of range")
data = bytearray([color] * 25) # Extra byte at front for address.
data = bytearray([color] * 25) # Extra byte at front for address.
while not self.i2c.try_lock():
pass
try:
Expand All @@ -290,7 +292,7 @@ def fill(self, color=None, blink=None, frame=None):
finally:
self.i2c.unlock()
if blink is not None:
data = bool(blink) * 0xff
data = bool(blink) * 0xFF
for col in range(18):
self._register(frame, _BLINK_OFFSET + col, data)

Expand All @@ -300,7 +302,7 @@ def pixel_addr(x, y):
"""
return x + y * 16

#pylint: disable-msg=too-many-arguments
# pylint: disable-msg=too-many-arguments
def pixel(self, x, y, color=None, blink=None, frame=None):
"""
Blink or brightness for x-, y-pixel
Expand Down Expand Up @@ -333,7 +335,8 @@ def pixel(self, x, y, color=None, blink=None, frame=None):
bits &= ~(1 << bit)
self._register(frame, _BLINK_OFFSET + addr, bits)
return None
#pylint: enable-msg=too-many-arguments

# pylint: enable-msg=too-many-arguments

def image(self, img, blink=None, frame=None):
"""Set buffer to value of Python Imaging Library image. The image should
Expand All @@ -343,24 +346,28 @@ def image(self, img, blink=None, frame=None):
:param blink: True to blink
:param frame: the frame to set the image
"""
if img.mode != 'L':
raise ValueError('Image must be in mode L.')
if img.mode != "L":
raise ValueError("Image must be in mode L.")
imwidth, imheight = img.size
if imwidth != self.width or imheight != self.height:
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
.format(self.width, self.height))
raise ValueError(
"Image must be same dimensions as display ({0}x{1}).".format(
self.width, self.height
)
)
# Grab all the pixels from the image, faster than getpixel.
pixels = img.load()

# Iterate through the pixels
for x in range(self.width): # yes this double loop is slow,
for x in range(self.width): # yes this double loop is slow,
for y in range(self.height): # but these displays are small!
self.pixel(x, y, pixels[(x, y)], blink=blink, frame=frame)


class CharlieWing(Matrix):
"""Supports the Charlieplexed feather wing
"""

width = 15
height = 7

Expand All @@ -378,19 +385,21 @@ def pixel_addr(x, y):

class CharlieBonnet(Matrix):
"""Supports the Charlieplexed bonnet"""

width = 16
height = 8

@staticmethod
def pixel_addr(x, y):
"""Calulate the offset into the device array for x,y pixel"""
if x >= 8:
return (x-6) * 16 - (y + 1)
return (x+1) * 16 + (7 - y)
return (x - 6) * 16 - (y + 1)
return (x + 1) * 16 + (7 - y)


class ScrollPhatHD(Matrix):
"""Supports the Scroll pHAT HD by Pimoroni"""

width = 17
height = 7

Expand Down
114 changes: 68 additions & 46 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,55 @@

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.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
]

# 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"]

intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/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,
),
"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 IS31FL3731 Library'
copyright = u'2017 Radomir Dopieralski'
author = u'Radomir Dopieralski'
project = u"Adafruit IS31FL3731 Library"
copyright = u"2017 Radomir Dopieralski"
author = u"Radomir Dopieralski"

# 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 +62,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 +74,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 +88,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 = 'AdafruitIS31FL3731Librarydoc'
htmlhelp_basename = "AdafruitIS31FL3731Librarydoc"

# -- 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, 'AdafruitIS31FL3731Library.tex', u'Adafruit IS31FL3731 Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitIS31FL3731Library.tex",
u"Adafruit IS31FL3731 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, 'adafruitIS31FL3731library', u'Adafruit IS31FL3731 Library Documentation',
[author], 1)
(
master_doc,
"adafruitIS31FL3731library",
u"Adafruit IS31FL3731 Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -150,7 +166,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitIS31FL3731Library', u'Adafruit IS31FL3731 Library Documentation',
author, 'AdafruitIS31FL3731Library', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitIS31FL3731Library",
u"Adafruit IS31FL3731 Library Documentation",
author,
"AdafruitIS31FL3731Library",
"One line description of project.",
"Miscellaneous",
),
]
Loading

0 comments on commit a8527a5

Please sign in to comment.