Skip to content

Commit 4552414

Browse files
committed
use new protocol. add return nones
1 parent a7e098e commit 4552414

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

adafruit_debouncer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333

3434
try:
3535
from typing import Callable, Optional, Union
36+
from circuitpython_typing.io import ROValueIO
3637
except ImportError:
3738
pass
38-
from digitalio import DigitalInOut
3939

4040
_DEBOUNCED_STATE: int = const(0x01)
4141
_UNSTABLE_STATE: int = const(0x02)
@@ -49,7 +49,7 @@ class Debouncer:
4949

5050
def __init__(
5151
self,
52-
io_or_predicate: Union[DigitalInOut, Callable[[], bool]],
52+
io_or_predicate: Union[ROValueIO, Callable[[], bool]],
5353
interval: float = 0.010,
5454
) -> None:
5555
"""Make an instance.
@@ -58,7 +58,7 @@ def __init__(
5858
:param float interval: bounce threshold in seconds (default is 0.010, i.e. 10 milliseconds)
5959
"""
6060
self.state = 0x00
61-
if isinstance(io_or_predicate, DigitalInOut):
61+
if hasattr(io_or_predicate, "value"):
6262
self.function = lambda: io_or_predicate.value
6363
else:
6464
self.function = io_or_predicate
@@ -113,7 +113,7 @@ def interval(self) -> float:
113113

114114
@interval.setter
115115
def interval(self, new_interval_s: float) -> None:
116-
self._interval_ticks = int(new_interval_s * _TICKS_PER_SEC)
116+
self._interval_ticks = new_interval_s * _TICKS_PER_SEC
117117

118118
@property
119119
def value(self) -> bool:
@@ -159,12 +159,12 @@ class Button(Debouncer):
159159

160160
def __init__(
161161
self,
162-
pin: DigitalInOut,
162+
pin: Union[ROValueIO, Callable[[], bool]],
163163
short_duration_ms: int = 200,
164164
long_duration_ms: int = 500,
165165
value_when_pressed: bool = False,
166166
**kwargs
167-
):
167+
) -> None:
168168
self.short_duration_ms = short_duration_ms
169169
self.long_duration_ms = long_duration_ms
170170
self.value_when_pressed = value_when_pressed
@@ -189,7 +189,7 @@ def released(self) -> bool:
189189
not self.value_when_pressed and self.rose
190190
)
191191

192-
def update(self, new_state: Optional[int] = None):
192+
def update(self, new_state: Optional[int] = None) -> None:
193193
super().update(new_state)
194194
if self.pressed:
195195
self.last_change_ms = ticks_ms()

0 commit comments

Comments
 (0)