Skip to content

Commit

Permalink
Merge pull request #10 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 13, 2020
2 parents cdb3cb2 + d0e416d commit 66f2b5b
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 95 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
16 changes: 9 additions & 7 deletions adafruit_rgbled.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGBLED.git"


class RGBLED:
"""
Creates a RGBLED object given three physical pins or PWMOut objects.
Expand Down Expand Up @@ -111,16 +112,17 @@ class RGBLED:
rgb_led.color = (0, 255, 0)
"""

def __init__(self, red_pin, green_pin, blue_pin, invert_pwm=False):
self._rgb_led_pins = [red_pin, green_pin, blue_pin]
for i in range(len(self._rgb_led_pins)):
if hasattr(self._rgb_led_pins[i], 'frequency'):
if hasattr(self._rgb_led_pins[i], "frequency"):
self._rgb_led_pins[i].duty_cycle = 0
elif str(type(self._rgb_led_pins[i])) == "<class 'Pin'>":
self._rgb_led_pins[i] = PWMOut(self._rgb_led_pins[i])
self._rgb_led_pins[i].duty_cycle = 0
else:
raise TypeError('Must provide a pin, PWMOut, or PWMChannel.')
raise TypeError("Must provide a pin, PWMOut, or PWMChannel.")
self._invert_pwm = invert_pwm
self._current_color = (0, 0, 0)
self.color = self._current_color
Expand All @@ -134,7 +136,7 @@ def __exit__(self, exception_type, exception_value, traceback):
def deinit(self):
"""Turn the LEDs off, deinit pwmout and release hardware resources."""
for pin in self._rgb_led_pins:
pin.deinit() #pylint: no-member
pin.deinit() # pylint: no-member
self._current_color = (0, 0, 0)

@property
Expand All @@ -155,16 +157,16 @@ def color(self, value):
color -= 65535
self._rgb_led_pins[i].duty_cycle = abs(color)
elif isinstance(value, int):
if value>>24:
if value >> 24:
raise ValueError("Only bits 0->23 valid for integer input")
r = value >> 16
g = (value >> 8) & 0xff
b = value & 0xff
g = (value >> 8) & 0xFF
b = value & 0xFF
rgb = [r, g, b]
for color in range(0, 3):
rgb[color] = int(map_range(rgb[color], 0, 255, 0, 65535))
if self._invert_pwm:
rgb[color] -= 65535
self._rgb_led_pins[color].duty_cycle = abs(rgb[color])
else:
raise ValueError('Color must be a tuple or 24-bit integer value.')
raise ValueError("Color must be a tuple or 24-bit integer value.")
112 changes: 65 additions & 47 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

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

# TODO: Please Read!
Expand All @@ -23,29 +24,32 @@
autodoc_mock_imports = ["pulseio"]


intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", 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 RGBLED Library'
copyright = u'2019 Brent Rubell'
author = u'Brent Rubell'
project = "Adafruit RGBLED Library"
copyright = "2019 Brent Rubell"
author = "Brent Rubell"

# 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 = "1.0"
# The full version, including alpha/beta/rc tags.
release = u'1.0'
release = "1.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -57,7 +61,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 @@ -69,7 +73,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 @@ -84,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 = 'AdafruitRgbledLibrarydoc'
htmlhelp_basename = "AdafruitRgbledLibrarydoc"

# -- 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, 'AdafruitRGBLEDLibrary.tex', u'AdafruitRGBLED Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitRGBLEDLibrary.tex",
"AdafruitRGBLED 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, 'AdafruitRGBLEDlibrary', u'Adafruit RGBLED Library Documentation',
[author], 1)
(
master_doc,
"AdafruitRGBLEDlibrary",
"Adafruit RGBLED Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -154,7 +166,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitRGBLEDLibrary', u'Adafruit RGBLED Library Documentation',
author, 'AdafruitRGBLEDLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitRGBLEDLibrary",
"Adafruit RGBLED Library Documentation",
author,
"AdafruitRGBLEDLibrary",
"One line description of project.",
"Miscellaneous",
),
]
10 changes: 5 additions & 5 deletions examples/rgbled_blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import adafruit_rgbled

# Configure the setup
RED_LED = board.D5 # Pin the Red LED is connected to
GREEN_LED = board.D6 # Pin the Green LED is connected to
BLUE_LED = board.D7 # Pin the Blue LED is connected to
RED_LED = board.D5 # Pin the Red LED is connected to
GREEN_LED = board.D6 # Pin the Green LED is connected to
BLUE_LED = board.D7 # Pin the Blue LED is connected to
COLOR = (100, 50, 150) # color to blink
CLEAR = (0, 0, 0) # clear (or second color)
DELAY = 0.25 # blink rate in seconds
CLEAR = (0, 0, 0) # clear (or second color)
DELAY = 0.25 # blink rate in seconds

# Create the RGB LED object
led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED)
Expand Down
11 changes: 7 additions & 4 deletions examples/rgbled_pca9685.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# PCA9685 Initialization
i2c = busio.I2C(board.SCL, board.SDA)
pca = adafruit_pca9685.PCA9685(i2c)
pca.frequency=60
pca.frequency = 60

# PCA9685 LED Channels
RED_LED = pca.channels[0]
Expand All @@ -20,6 +20,7 @@
# Optionally, you can also create the RGB LED object with inverted PWM
# led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True)


def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
Expand All @@ -33,23 +34,25 @@ def wheel(pos):
pos -= 170
return int(pos * 3), 0, int(255 - (pos * 3))


def rainbow_cycle(wait):
for i in range(255):
i = (i + 1) % 256
led.color = wheel(i)
time.sleep(wait)


while True:
# setting RGB LED color to RGB Tuples (R, G, B)
print('setting color 1')
print("setting color 1")
led.color = (255, 0, 0)
time.sleep(1)

print('setting color 2')
print("setting color 2")
led.color = (0, 255, 0)
time.sleep(1)

print('setting color 3')
print("setting color 3")
led.color = (0, 0, 255)
time.sleep(1)

Expand Down
3 changes: 3 additions & 0 deletions examples/rgbled_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# Optionally, you can also create the RGB LED object with inverted PWM
# led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True)


def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
Expand All @@ -30,12 +31,14 @@ def wheel(pos):
pos -= 170
return int(pos * 3), 0, int(255 - (pos * 3))


def rainbow_cycle(wait):
for i in range(255):
i = (i + 1) % 256
led.color = wheel(i)
time.sleep(wait)


while True:
# setting RGB LED color to RGB Tuples (R, G, B)
led.color = (255, 0, 0)
Expand Down

0 comments on commit 66f2b5b

Please sign in to comment.