Skip to content

add touchio as an optional type of input #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion adafruit_debouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import time
import digitalio
from micropython import const
import touchio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will stop the module from being importable on boards without touchio


_DEBOUNCED_STATE = const(0x01)
_UNSTABLE_STATE = const(0x02)
Expand All @@ -62,7 +63,7 @@ def __init__(self, io_or_predicate, interval=0.010):
:param int interval: bounce threshold in seconds (default is 0.010, i.e. 10 milliseconds)
"""
self.state = 0x00
if isinstance(io_or_predicate, digitalio.DigitalInOut):
if isinstance(io_or_predicate, (digitalio.DigitalInOut, touchio.TouchIn)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be changed to 'if hasattr(io_or_predicate, 'value')` ? This would mean that the import of touchio was not needed, but would also make it work with other io types, such as on a seesaw.

self.function = lambda: io_or_predicate.value
else:
self.function = io_or_predicate
Expand Down