Skip to content

Commit

Permalink
Merge pull request #14 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 committed Mar 17, 2020
2 parents bc7fcfd + 5a99c06 commit e0d2dc5
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 120 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
77 changes: 43 additions & 34 deletions adafruit_cap1188/cap1188.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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."""
Expand All @@ -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

Expand Down
4 changes: 3 additions & 1 deletion adafruit_cap1188/i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions adafruit_cap1188/spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
126 changes: 76 additions & 50 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,61 @@

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.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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -83,68 +95,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 = '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 ---------------------------------------

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

0 comments on commit e0d2dc5

Please sign in to comment.