Skip to content

Commit 72b7319

Browse files
authored
Merge pull request #37 from adafruit/manual_valueset
allow manually pushing state, back compatible
2 parents 49bc7fe + 3be36e4 commit 72b7319

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

adafruit_debouncer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ def _toggle_state(self, bits):
7373
def _get_state(self, bits):
7474
return (self.state & bits) != 0
7575

76-
def update(self):
76+
def update(self, new_state=None):
7777
"""Update the debouncer state. MUST be called frequently"""
7878
now_ticks = ticks_ms()
7979
self._unset_state(_CHANGED_STATE)
80-
current_state = self.function()
80+
if new_state is None:
81+
current_state = self.function()
82+
else:
83+
current_state = bool(new_state)
8184
if current_state != self._get_state(_UNSTABLE_STATE):
8285
self._last_bounce_ticks = now_ticks
8386
self._toggle_state(_UNSTABLE_STATE)
@@ -160,8 +163,8 @@ def _released(self):
160163
not self.active_down and super().fell
161164
)
162165

163-
def update(self):
164-
super().update()
166+
def update(self, new_state=None):
167+
super().update(new_state)
165168
if self._pushed():
166169
self.last_change_ms = ticks_ms()
167170
self.short_counter = self.short_counter + 1

0 commit comments

Comments
 (0)