Merge pull request #45 from adafruit/pylint-update
Ran black, updated to pylint 2.x
This commit is contained in:
commit
62e645efd9
8 changed files with 179 additions and 135 deletions
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
|
@ -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 pylint black==19.10b0 Sphinx sphinx-rtd-theme
|
||||
- name: Library version
|
||||
run: git describe --dirty --always --tags
|
||||
- name: PyLint
|
||||
|
|
|
|||
16
.pylintrc
16
.pylintrc
|
|
@ -18,6 +18,7 @@ ignore-patterns=
|
|||
#init-hook=
|
||||
|
||||
# Use multiple processes to speed up Pylint.
|
||||
# jobs=1
|
||||
jobs=2
|
||||
|
||||
# List of plugins (as comma separated values of python modules names) to load,
|
||||
|
|
@ -50,7 +51,8 @@ confidence=
|
|||
# --enable=similarities". If you want to run only the classes checker, but have
|
||||
# no Warning level messages displayed, use"--disable=all --enable=classes
|
||||
# --disable=W"
|
||||
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error
|
||||
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
|
||||
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
|
||||
|
||||
# Enable the message, report, category or checker with the given id(s). You can
|
||||
# either give multiple identifier separated by comma (,) or put this option
|
||||
|
|
@ -117,7 +119,8 @@ spelling-store-unknown-words=no
|
|||
[MISCELLANEOUS]
|
||||
|
||||
# List of note tags to take in consideration, separated by a comma.
|
||||
notes=FIXME,XXX,TODO
|
||||
# notes=FIXME,XXX,TODO
|
||||
notes=FIXME,XXX
|
||||
|
||||
|
||||
[TYPECHECK]
|
||||
|
|
@ -200,6 +203,7 @@ redefining-builtins-modules=six.moves,future.builtins
|
|||
[FORMAT]
|
||||
|
||||
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
|
||||
# expected-line-ending-format=
|
||||
expected-line-ending-format=LF
|
||||
|
||||
# Regexp for a line that is allowed to be longer than the limit.
|
||||
|
|
@ -272,9 +276,11 @@ class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
|||
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
||||
|
||||
# Naming hint for class names
|
||||
# class-name-hint=[A-Z_][a-zA-Z0-9]+$
|
||||
class-name-hint=[A-Z_][a-zA-Z0-9_]+$
|
||||
|
||||
# Regular expression matching correct class names
|
||||
# class-rgx=[A-Z_][a-zA-Z0-9]+$
|
||||
class-rgx=[A-Z_][a-zA-Z0-9_]+$
|
||||
|
||||
# Naming hint for constant names
|
||||
|
|
@ -294,7 +300,8 @@ function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|||
function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Good variable names which should always be accepted, separated by a comma
|
||||
good-names=r,g,b,i,j,k,n,ex,Run,_
|
||||
# good-names=i,j,k,ex,Run,_
|
||||
good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_
|
||||
|
||||
# Include a hint for the correct naming format with invalid-name
|
||||
include-naming-hint=no
|
||||
|
|
@ -391,6 +398,7 @@ valid-metaclass-classmethod-first-arg=mcs
|
|||
max-args=5
|
||||
|
||||
# Maximum number of attributes for a class (see R0902).
|
||||
# max-attributes=7
|
||||
max-attributes=11
|
||||
|
||||
# Maximum number of boolean expressions in a if statement
|
||||
|
|
@ -415,7 +423,7 @@ max-returns=6
|
|||
max-statements=50
|
||||
|
||||
# Minimum number of public methods for a class (see R0903).
|
||||
min-public-methods=2
|
||||
min-public-methods=1
|
||||
|
||||
|
||||
[EXCEPTIONS]
|
||||
|
|
|
|||
|
|
@ -81,8 +81,17 @@ class DotStar:
|
|||
time.sleep(2)
|
||||
"""
|
||||
|
||||
def __init__(self, clock, data, n, *, brightness=1.0, auto_write=True,
|
||||
pixel_order=BGR, baudrate=4000000):
|
||||
def __init__(
|
||||
self,
|
||||
clock,
|
||||
data,
|
||||
n,
|
||||
*,
|
||||
brightness=1.0,
|
||||
auto_write=True,
|
||||
pixel_order=BGR,
|
||||
baudrate=4000000
|
||||
):
|
||||
self._spi = None
|
||||
try:
|
||||
self._spi = busio.SPI(clock, MOSI=data)
|
||||
|
|
@ -109,10 +118,10 @@ class DotStar:
|
|||
self._buf[i] = 0x00
|
||||
# Mark the beginnings of each pixel.
|
||||
for i in range(START_HEADER_SIZE, self.end_header_index, 4):
|
||||
self._buf[i] = 0xff
|
||||
self._buf[i] = 0xFF
|
||||
# 0xff bytes at the end.
|
||||
for i in range(self.end_header_index, len(self._buf)):
|
||||
self._buf[i] = 0xff
|
||||
self._buf[i] = 0xFF
|
||||
self._brightness = 1.0
|
||||
# Set auto_write to False temporarily so brightness setter does _not_
|
||||
# call show() while in __init__.
|
||||
|
|
@ -162,7 +171,7 @@ class DotStar:
|
|||
offset = index * 4 + START_HEADER_SIZE
|
||||
rgb = value
|
||||
if isinstance(value, int):
|
||||
rgb = (value >> 16, (value >> 8) & 0xff, value & 0xff)
|
||||
rgb = (value >> 16, (value >> 8) & 0xFF, value & 0xFF)
|
||||
|
||||
if len(rgb) == 4:
|
||||
brightness = value[3]
|
||||
|
|
@ -204,15 +213,18 @@ class DotStar:
|
|||
out = []
|
||||
for in_i in range(*index.indices(self._n)):
|
||||
out.append(
|
||||
tuple(self._buf[in_i * 4 + (3 - i) + START_HEADER_SIZE] for i in range(3)))
|
||||
tuple(
|
||||
self._buf[in_i * 4 + (3 - i) + START_HEADER_SIZE]
|
||||
for i in range(3)
|
||||
)
|
||||
)
|
||||
return out
|
||||
if index < 0:
|
||||
index += len(self)
|
||||
if index >= self._n or index < 0:
|
||||
raise IndexError
|
||||
offset = index * 4
|
||||
return tuple(self._buf[offset + (3 - i) + START_HEADER_SIZE]
|
||||
for i in range(3))
|
||||
return tuple(self._buf[offset + (3 - i) + START_HEADER_SIZE] for i in range(3))
|
||||
|
||||
def __len__(self):
|
||||
return self._n
|
||||
|
|
@ -241,7 +253,7 @@ class DotStar:
|
|||
def _ds_writebytes(self, buf):
|
||||
for b in buf:
|
||||
for _ in range(8):
|
||||
self.dpin.value = (b & 0x80)
|
||||
self.dpin.value = b & 0x80
|
||||
self.cpin.value = True
|
||||
self.cpin.value = False
|
||||
b = b << 1
|
||||
|
|
@ -260,10 +272,12 @@ class DotStar:
|
|||
for i in range(START_HEADER_SIZE):
|
||||
buf[i] = 0x00
|
||||
for i in range(START_HEADER_SIZE, self.end_header_index):
|
||||
buf[i] = self._buf[i] if i % 4 == 0 else int(self._buf[i] * self._brightness)
|
||||
buf[i] = (
|
||||
self._buf[i] if i % 4 == 0 else int(self._buf[i] * self._brightness)
|
||||
)
|
||||
# Four 0xff bytes at the end.
|
||||
for i in range(self.end_header_index, len(buf)):
|
||||
buf[i] = 0xff
|
||||
buf[i] = 0xFF
|
||||
|
||||
if self._spi:
|
||||
self._spi.write(buf)
|
||||
|
|
|
|||
111
docs/conf.py
111
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,37 +11,39 @@ sys.path.insert(0, os.path.abspath('..'))
|
|||
# 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",
|
||||
]
|
||||
|
||||
# autodoc_mock_imports = ["digitalio", "busio"]
|
||||
|
||||
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 CircuitPython DotStar Library'
|
||||
copyright = u'2017 Scott Shawcroft, Limor Fried & Damien P. George'
|
||||
author = u'Scott Shawcroft, Limor Fried & Damien P. George'
|
||||
project = u"Adafruit CircuitPython DotStar Library"
|
||||
copyright = u"2017 Scott Shawcroft, Limor Fried & Damien P. George"
|
||||
author = u"Scott Shawcroft, Limor Fried & Damien P. George"
|
||||
|
||||
# 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.
|
||||
|
|
@ -52,7 +55,7 @@ language = None
|
|||
# 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.
|
||||
|
|
@ -64,7 +67,7 @@ default_role = "any"
|
|||
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
|
||||
|
|
@ -78,59 +81,62 @@ todo_emit_warnings = True
|
|||
# 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 = 'AdafruitDotStarLibrarydoc'
|
||||
htmlhelp_basename = "AdafruitDotStarLibrarydoc"
|
||||
|
||||
# -- 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, 'AdafruitDotStarLibrary.tex', u'Adafruit DotStar Library Documentation',
|
||||
author, 'manual'),
|
||||
(
|
||||
master_doc,
|
||||
"AdafruitDotStarLibrary.tex",
|
||||
u"Adafruit DotStar Library Documentation",
|
||||
author,
|
||||
"manual",
|
||||
),
|
||||
]
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
|
@ -138,8 +144,13 @@ latex_documents = [
|
|||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'adafruitDotStarlibrary', u'Adafruit DotStar Library Documentation',
|
||||
[author], 1)
|
||||
(
|
||||
master_doc,
|
||||
"adafruitDotStarlibrary",
|
||||
u"Adafruit DotStar Library Documentation",
|
||||
[author],
|
||||
1,
|
||||
)
|
||||
]
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
|
@ -148,7 +159,13 @@ man_pages = [
|
|||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'AdafruitDotStarLibrary', u'Adafruit DotStar Library Documentation',
|
||||
author, 'AdafruitDotStarLibrary', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
(
|
||||
master_doc,
|
||||
"AdafruitDotStarLibrary",
|
||||
u"Adafruit DotStar Library Documentation",
|
||||
author,
|
||||
"AdafruitDotStarLibrary",
|
||||
"One line description of project.",
|
||||
"Miscellaneous",
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -11,22 +11,28 @@ import board
|
|||
from PIL import Image
|
||||
import adafruit_dotstar as dotstar
|
||||
|
||||
NUMPIXELS = 30 # Number of LEDs in strip
|
||||
FILENAME = 'hello.png' # Image file to load
|
||||
NUMPIXELS = 30 # Number of LEDs in strip
|
||||
FILENAME = "hello.png" # Image file to load
|
||||
|
||||
# First two arguments in strip declaration identify the clock and data pins
|
||||
# (here we're using the hardware SPI pins). Last argument identifies the
|
||||
# color order -- older DotStar strips use GBR instead of BRG.
|
||||
DOTS = dotstar.DotStar(board.SCK, board.MOSI, NUMPIXELS, brightness=0.25,
|
||||
auto_write=False, pixel_order=dotstar.BGR)
|
||||
DOTS = dotstar.DotStar(
|
||||
board.SCK,
|
||||
board.MOSI,
|
||||
NUMPIXELS,
|
||||
brightness=0.25,
|
||||
auto_write=False,
|
||||
pixel_order=dotstar.BGR,
|
||||
)
|
||||
|
||||
# Load image in RGB format and get dimensions:
|
||||
print('Loading...')
|
||||
print("Loading...")
|
||||
IMG = Image.open(FILENAME).convert("RGB")
|
||||
PIXELS = IMG.load()
|
||||
WIDTH = IMG.size[0]
|
||||
HEIGHT = IMG.size[1]
|
||||
print('%dx%d pixels' % IMG.size)
|
||||
print("%dx%d pixels" % IMG.size)
|
||||
|
||||
if HEIGHT > NUMPIXELS:
|
||||
HEIGHT = NUMPIXELS
|
||||
|
|
@ -36,19 +42,20 @@ GAMMA = bytearray(256)
|
|||
for i in range(256):
|
||||
GAMMA[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5)
|
||||
|
||||
print('Displaying...')
|
||||
while True: # Loop forever
|
||||
print("Displaying...")
|
||||
while True: # Loop forever
|
||||
|
||||
for x in range(WIDTH): # For each column of image...
|
||||
for x in range(WIDTH): # For each column of image...
|
||||
for y in range(HEIGHT): # For each pixel in column...
|
||||
value = PIXELS[x, y] # Read pixel in image
|
||||
DOTS[y] = ( # Set pixel #y in strip
|
||||
GAMMA[value[0]], # Gamma-corrected red
|
||||
GAMMA[value[1]], # Gamma-corrected green
|
||||
GAMMA[value[2]]) # Gamma-corrected blue
|
||||
DOTS.show() # Refresh LED strip
|
||||
time.sleep(0.01) # Pause 1/100 sec.
|
||||
value = PIXELS[x, y] # Read pixel in image
|
||||
DOTS[y] = ( # Set pixel #y in strip
|
||||
GAMMA[value[0]], # Gamma-corrected red
|
||||
GAMMA[value[1]], # Gamma-corrected green
|
||||
GAMMA[value[2]], # Gamma-corrected blue
|
||||
)
|
||||
DOTS.show() # Refresh LED strip
|
||||
time.sleep(0.01) # Pause 1/100 sec.
|
||||
|
||||
DOTS.fill(0) # Clear strip and pause 1/4 sec.
|
||||
DOTS.fill(0) # Clear strip and pause 1/4 sec.
|
||||
DOTS.show()
|
||||
time.sleep(0.25)
|
||||
|
|
|
|||
|
|
@ -14,22 +14,28 @@ import board
|
|||
from PIL import Image
|
||||
import adafruit_dotstar as dotstar
|
||||
|
||||
NUMPIXELS = 30 # Length of DotStar strip
|
||||
FILENAME = 'hello.png' # Image file to load
|
||||
ORDER = dotstar.BGR # Change to GBR for older DotStar strips
|
||||
NUMPIXELS = 30 # Length of DotStar strip
|
||||
FILENAME = "hello.png" # Image file to load
|
||||
ORDER = dotstar.BGR # Change to GBR for older DotStar strips
|
||||
|
||||
# First two arguments in strip declaration identify the clock and data pins
|
||||
# (here we're using the hardware SPI pins).
|
||||
DOTS = dotstar.DotStar(board.SCK, board.MOSI, NUMPIXELS, auto_write=False,
|
||||
brightness=0.25, pixel_order=ORDER)
|
||||
DOTS = dotstar.DotStar(
|
||||
board.SCK,
|
||||
board.MOSI,
|
||||
NUMPIXELS,
|
||||
auto_write=False,
|
||||
brightness=0.25,
|
||||
pixel_order=ORDER,
|
||||
)
|
||||
|
||||
# Load image in RGB format and get dimensions:
|
||||
print('Loading...')
|
||||
IMG = Image.open(FILENAME).convert('RGB')
|
||||
print("Loading...")
|
||||
IMG = Image.open(FILENAME).convert("RGB")
|
||||
PIXELS = IMG.load()
|
||||
WIDTH = IMG.size[0]
|
||||
HEIGHT = IMG.size[1]
|
||||
print('%dx%d pixels' % IMG.size)
|
||||
print("%dx%d pixels" % IMG.size)
|
||||
|
||||
if HEIGHT > NUMPIXELS:
|
||||
HEIGHT = NUMPIXELS
|
||||
|
|
@ -45,7 +51,7 @@ DOTS.brightness = 1.0
|
|||
|
||||
# Allocate list of bytearrays, one for each column of image.
|
||||
# Each pixel REQUIRES 4 bytes (0xFF, B, G, R).
|
||||
print('Allocating...')
|
||||
print("Allocating...")
|
||||
COLUMN = [0 for x in range(WIDTH)]
|
||||
for x in range(WIDTH):
|
||||
COLUMN[x] = bytearray(HEIGHT * 4)
|
||||
|
|
@ -55,22 +61,22 @@ for x in range(WIDTH):
|
|||
# for each pixel to do any R/G/B reordering. Because we're preparing data
|
||||
# directly for the strip, there's a reference to 'ORDER' here to rearrange
|
||||
# the color bytes as needed.
|
||||
print('Converting...')
|
||||
for x in range(WIDTH): # For each column of image
|
||||
for y in range(HEIGHT): # For each pixel in column
|
||||
value = PIXELS[x, y] # Read RGB pixel in image
|
||||
y4 = y * 4 # Position in raw buffer
|
||||
COLUMN[x][y4] = 0xFF # Pixel start marker
|
||||
y4 += 1 # Pixel color data start
|
||||
COLUMN[x][y4 + ORDER[0]] = GAMMA[value[0]] # Gamma-corrected R
|
||||
COLUMN[x][y4 + ORDER[1]] = GAMMA[value[1]] # Gamma-corrected G
|
||||
COLUMN[x][y4 + ORDER[2]] = GAMMA[value[2]] # Gamma-corrected B
|
||||
print("Converting...")
|
||||
for x in range(WIDTH): # For each column of image
|
||||
for y in range(HEIGHT): # For each pixel in column
|
||||
value = PIXELS[x, y] # Read RGB pixel in image
|
||||
y4 = y * 4 # Position in raw buffer
|
||||
COLUMN[x][y4] = 0xFF # Pixel start marker
|
||||
y4 += 1 # Pixel color data start
|
||||
COLUMN[x][y4 + ORDER[0]] = GAMMA[value[0]] # Gamma-corrected R
|
||||
COLUMN[x][y4 + ORDER[1]] = GAMMA[value[1]] # Gamma-corrected G
|
||||
COLUMN[x][y4 + ORDER[2]] = GAMMA[value[2]] # Gamma-corrected B
|
||||
|
||||
print('Displaying...')
|
||||
while True: # Loop forever
|
||||
print("Displaying...")
|
||||
while True: # Loop forever
|
||||
|
||||
# pylint: disable=protected-access
|
||||
# (Really shouldn't access _buf directly, but needed for fastest POV)
|
||||
for x in range(WIDTH): # For each column of image...
|
||||
DOTS._buf[4:4+HEIGHT*4] = COLUMN[x] # Copy column to DotStar buffer
|
||||
DOTS.show() # Send data to strip
|
||||
for x in range(WIDTH): # For each column of image...
|
||||
DOTS._buf[4 : 4 + HEIGHT * 4] = COLUMN[x] # Copy column to DotStar buffer
|
||||
DOTS.show() # Send data to strip
|
||||
|
|
|
|||
|
|
@ -26,4 +26,4 @@ while True:
|
|||
for dot in range(n_dots):
|
||||
dots[dot] = (random_color(), random_color(), random_color())
|
||||
|
||||
time.sleep(.25)
|
||||
time.sleep(0.25)
|
||||
|
|
|
|||
52
setup.py
52
setup.py
|
|
@ -7,6 +7,7 @@ https://github.com/pypa/sampleproject
|
|||
|
||||
# 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,47 +15,38 @@ from os import path
|
|||
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-dotstar',
|
||||
|
||||
name="adafruit-circuitpython-dotstar",
|
||||
use_scm_version=True,
|
||||
setup_requires=['setuptools_scm'],
|
||||
|
||||
description='CircuitPython library for DotStar LEDs.',
|
||||
setup_requires=["setuptools_scm"],
|
||||
description="CircuitPython library for DotStar LEDs.",
|
||||
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_DotStar',
|
||||
|
||||
url="https://github.com/adafruit/Adafruit_CircuitPython_DotStar",
|
||||
# Author details
|
||||
author='Adafruit Industries',
|
||||
author_email='circuitpython@adafruit.com',
|
||||
|
||||
install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice'],
|
||||
|
||||
author="Adafruit Industries",
|
||||
author_email="circuitpython@adafruit.com",
|
||||
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"],
|
||||
# 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 dotstar leds rgb spi addressable hardware micropython circuitpython',
|
||||
|
||||
keywords="adafruit dotstar leds rgb spi addressable hardware micropython circuitpython",
|
||||
# You can just specify the packages manually here if your project is
|
||||
# simple. Or you can use find_packages().
|
||||
py_modules=['adafruit_dotstar'],
|
||||
)
|
||||
py_modules=["adafruit_dotstar"],
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue