Skip to content

Commit 650517d

Browse files
authored
Update adafruit_debouncer.py
Testing if time.monotonic_ns() is really implemented. Supposed to solve #22 Works for me on PyPortal.
1 parent 5e5e302 commit 650517d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

adafruit_debouncer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@
6262
_UNSTABLE_STATE = const(0x02)
6363
_CHANGED_STATE = const(0x04)
6464

65-
# Find out whether the current CircuitPython supports time.monotonic_ns(),
65+
# Find out whether the current CircuitPython really supports time.monotonic_ns(),
6666
# which doesn't have the accuracy limitation.
67-
if hasattr(time, "monotonic_ns"):
67+
try:
68+
time.monotonic_ns()
6869
TICKS_PER_SEC = 1_000_000_000
6970
MONOTONIC_TICKS = time.monotonic_ns
70-
else:
71+
except (ImportError, NotImplementedError):
7172
TICKS_PER_SEC = 1
7273
MONOTONIC_TICKS = time.monotonic
7374

0 commit comments

Comments
 (0)