Skip to content

Commit 3de8835

Browse files
authored
Merge branch 'master' into use-monotonic-ns
2 parents f060e9a + 793f545 commit 3de8835

File tree

9 files changed

+105
-77
lines changed

9 files changed

+105
-77
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,22 @@ jobs:
3434
with:
3535
repository: adafruit/actions-ci-circuitpython-libs
3636
path: actions-ci
37-
- name: Install deps
37+
- name: Install dependencies
38+
# (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.)
3839
run: |
3940
source actions-ci/install.sh
41+
- name: Pip install pylint, black, & Sphinx
42+
run: |
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4044
- name: Library version
4145
run: git describe --dirty --always --tags
46+
- name: Check formatting
47+
run: |
48+
black --check --target-version=py35 .
4249
- name: PyLint
4350
run: |
4451
pylint $( find . -path './adafruit*.py' )
45-
([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py)
52+
([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" ))
4653
- name: Build assets
4754
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
4855
- name: Build docs

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ confidence=
5252
# no Warning level messages displayed, use"--disable=all --enable=classes
5353
# --disable=W"
5454
# 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
55-
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
55+
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
5656

5757
# Enable the message, report, category or checker with the given id(s). You can
5858
# either give multiple identifier separated by comma (,) or put this option

CODE_OF_CONDUCT.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Examples of unacceptable behavior by participants include:
3434
* Excessive or unwelcome helping; answering outside the scope of the question
3535
asked
3636
* Trolling, insulting/derogatory comments, and personal or political attacks
37+
* Promoting or spreading disinformation, lies, or conspiracy theories against
38+
a person, group, organisation, project, or community
3739
* Public or private harassment
3840
* Publishing others' private information, such as a physical or electronic
3941
address, without explicit permission
@@ -72,10 +74,10 @@ You may report in the following ways:
7274
In any situation, you may send an email to <support@adafruit.com>.
7375

7476
On the Adafruit Discord, you may send an open message from any channel
75-
to all Community Helpers by tagging @community helpers. You may also send an
76-
open message from any channel, or a direct message to @kattni#1507,
77-
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
78-
@Andon#8175.
77+
to all Community Moderators by tagging @community moderators. You may
78+
also send an open message from any channel, or a direct message to
79+
@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442,
80+
@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175.
7981

8082
Email and direct message reports will be kept confidential.
8183

adafruit_debouncer.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,12 @@
5656
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Debouncer.git"
5757

5858
import time
59-
import digitalio
6059
from micropython import const
6160

6261
_DEBOUNCED_STATE = const(0x01)
6362
_UNSTABLE_STATE = const(0x02)
6463
_CHANGED_STATE = const(0x04)
6564

66-
6765
# Find out whether the current CircuitPython supports time.monotonic_ns(),
6866
# which doesn't have the accuracy limitation.
6967
if hasattr(time, 'monotonic_ns'):
@@ -74,7 +72,7 @@
7472
MONOTONIC_TICKS = time.monotonic
7573

7674

77-
class Debouncer(object):
75+
class Debouncer:
7876
"""Debounce an input pin or an arbitrary predicate"""
7977

8078
def __init__(self, io_or_predicate, interval=0.010):
@@ -83,7 +81,7 @@ def __init__(self, io_or_predicate, interval=0.010):
8381
:param int interval: bounce threshold in seconds (default is 0.010, i.e. 10 milliseconds)
8482
"""
8583
self.state = 0x00
86-
if isinstance(io_or_predicate, digitalio.DigitalInOut):
84+
if hasattr(io_or_predicate, "value"):
8785
self.function = lambda: io_or_predicate.value
8886
else:
8987
self.function = io_or_predicate
@@ -97,23 +95,18 @@ def __init__(self, io_or_predicate, interval=0.010):
9795
# set the real underlying attribute:
9896
self._interval_ticks = interval * TICKS_PER_SEC
9997

100-
10198
def _set_state(self, bits):
10299
self.state |= bits
103100

104-
105101
def _unset_state(self, bits):
106102
self.state &= ~bits
107103

108-
109104
def _toggle_state(self, bits):
110105
self.state ^= bits
111106

112-
113107
def _get_state(self, bits):
114108
return (self.state & bits) != 0
115109

116-
117110
def update(self):
118111
"""Update the debouncer state. MUST be called frequently"""
119112
now_ticks = MONOTONIC_TICKS()
@@ -141,23 +134,22 @@ def interval(self):
141134
def interval(self, new_interval_s):
142135
self._interval_ticks = new_interval_s * TICKS_PER_SEC
143136

144-
145137
@property
146138
def value(self):
147139
"""Return the current debounced value."""
148140
return self._get_state(_DEBOUNCED_STATE)
149141

150-
151142
@property
152143
def rose(self):
153144
"""Return whether the debounced value went from low to high at the most recent update."""
154145
return self._get_state(_DEBOUNCED_STATE) and self._get_state(_CHANGED_STATE)
155146

156-
157147
@property
158148
def fell(self):
159149
"""Return whether the debounced value went from high to low at the most recent update."""
160-
return (not self._get_state(_DEBOUNCED_STATE)) and self._get_state(_CHANGED_STATE)
150+
return (not self._get_state(_DEBOUNCED_STATE)) and self._get_state(
151+
_CHANGED_STATE
152+
)
161153

162154
@property
163155
def last_duration(self):

docs/conf.py

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# TODO: Please Read!
@@ -23,29 +24,32 @@
2324
autodoc_mock_imports = ["digitalio"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
30+
}
2731

2832
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3034

31-
source_suffix = '.rst'
35+
source_suffix = ".rst"
3236

3337
# The master toctree document.
34-
master_doc = 'index'
38+
master_doc = "index"
3539

3640
# General information about the project.
37-
project = u'Adafruit Debouncer Library'
38-
copyright = u'2019 Dave Astels'
39-
author = u'Dave Astels'
41+
project = "Adafruit Debouncer Library"
42+
copyright = "2019 Dave Astels"
43+
author = "Dave Astels"
4044

4145
# The version info for the project you're documenting, acts as replacement for
4246
# |version| and |release|, also used in various other places throughout the
4347
# built documents.
4448
#
4549
# The short X.Y version.
46-
version = u'1.0'
50+
version = "1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = "1.0"
4953

5054
# The language for content autogenerated by Sphinx. Refer to documentation
5155
# for a list of supported languages.
@@ -57,7 +61,7 @@
5761
# List of patterns, relative to source directory, that match files and
5862
# directories to ignore when looking for source files.
5963
# This patterns also effect to html_static_path and html_extra_path
60-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
64+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6165

6266
# The reST default role (used for this markup: `text`) to use for all
6367
# documents.
@@ -69,7 +73,7 @@
6973
add_function_parentheses = True
7074

7175
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7377

7478
# If true, `todo` and `todoList` produce output, else they produce nothing.
7579
todo_include_todos = False
@@ -84,68 +88,76 @@
8488
# The theme to use for HTML and HTML Help pages. See the documentation for
8589
# a list of builtin themes.
8690
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
91+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8892

8993
if not on_rtd: # only import and set the theme if we're building docs locally
9094
try:
9195
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9499
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
97102
else:
98-
html_theme_path = ['.']
103+
html_theme_path = ["."]
99104

100105
# Add any paths that contain custom static files (such as style sheets) here,
101106
# relative to this directory. They are copied after the builtin static files,
102107
# so a file named "default.css" will overwrite the builtin "default.css".
103-
html_static_path = ['_static']
108+
html_static_path = ["_static"]
104109

105110
# The name of an image file (relative to this directory) to use as a favicon of
106111
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107112
# pixels large.
108113
#
109-
html_favicon = '_static/favicon.ico'
114+
html_favicon = "_static/favicon.ico"
110115

111116
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitDebouncerLibrarydoc'
117+
htmlhelp_basename = "AdafruitDebouncerLibrarydoc"
113118

114119
# -- Options for LaTeX output ---------------------------------------------
115120

116121
latex_elements = {
117-
# The paper size ('letterpaper' or 'a4paper').
118-
#
119-
# 'papersize': 'letterpaper',
120-
121-
# The font size ('10pt', '11pt' or '12pt').
122-
#
123-
# 'pointsize': '10pt',
124-
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
122+
# The paper size ('letterpaper' or 'a4paper').
123+
#
124+
# 'papersize': 'letterpaper',
125+
# The font size ('10pt', '11pt' or '12pt').
126+
#
127+
# 'pointsize': '10pt',
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
132134
}
133135

134136
# Grouping the document tree into LaTeX files. List of tuples
135137
# (source start file, target name, title,
136138
# author, documentclass [howto, manual, or own class]).
137139
latex_documents = [
138-
(master_doc, 'AdafruitdebouncerLibrary.tex', u'Adafruitdebouncer Library Documentation',
139-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitdebouncerLibrary.tex",
143+
"Adafruitdebouncer Library Documentation",
144+
author,
145+
"manual",
146+
),
140147
]
141148

142149
# -- Options for manual page output ---------------------------------------
143150

144151
# One entry per manual page. List of tuples
145152
# (source start file, name, description, authors, manual section).
146153
man_pages = [
147-
(master_doc, 'Adafruitdebouncerlibrary', u'Adafruit debouncer Library Documentation',
148-
[author], 1)
154+
(
155+
master_doc,
156+
"Adafruitdebouncerlibrary",
157+
"Adafruit debouncer Library Documentation",
158+
[author],
159+
1,
160+
)
149161
]
150162

151163
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +166,13 @@
154166
# (source start file, target name, title, author,
155167
# dir menu entry, description, category)
156168
texinfo_documents = [
157-
(master_doc, 'AdafruitdebouncerLibrary', u'Adafruit debouncer Library Documentation',
158-
author, 'AdafruitdebouncerLibrary', 'One line description of project.',
159-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitdebouncerLibrary",
172+
"Adafruit debouncer Library Documentation",
173+
author,
174+
"AdafruitdebouncerLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
160178
]

examples/debouncer_crickit_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434

3535
ss = crickit.seesaw
3636

37+
3738
def make_crikit_signal_debouncer(pin):
3839
"""Return a lambda to read the specified pin"""
3940
ss.pin_mode(pin, ss.INPUT_PULLUP)
4041
return Debouncer(lambda: ss.digital_read(pin))
4142

43+
4244
# Two buttons are pullups, connect to ground to activate
4345
clock = make_crikit_signal_debouncer(crickit.SIGNAL1)
4446
signal_2 = make_crikit_signal_debouncer(crickit.SIGNAL2)
@@ -54,6 +56,9 @@ def make_crikit_signal_debouncer(pin):
5456
signal_5.update()
5557

5658
if clock.fell:
57-
print('%u %u %u %u' % (signal_2.value, signal_3.value, signal_4.value, signal_5.value))
59+
print(
60+
"%u %u %u %u"
61+
% (signal_2.value, signal_3.value, signal_4.value, signal_5.value)
62+
)
5863

5964
time.sleep(0.1)

examples/debouncer_simpletest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
while True:
3737
switch.update()
3838
if switch.fell:
39-
print('Just pressed')
39+
print("Just pressed")
4040
if switch.rose:
41-
print('Just released')
41+
print("Just released")
4242
if switch.value:
43-
print('not pressed')
43+
print("not pressed")
4444
else:
45-
print('pressed')
45+
print("pressed")

0 commit comments

Comments
 (0)