Skip to content

Commit

Permalink
Merge pull request #37 from adafruit/manual_valueset
Browse files Browse the repository at this point in the history
allow manually pushing state, back compatible
  • Loading branch information
ladyada authored Mar 6, 2022
2 parents 49bc7fe + 3be36e4 commit 72b7319
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions adafruit_debouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ def _toggle_state(self, bits):
def _get_state(self, bits):
return (self.state & bits) != 0

def update(self):
def update(self, new_state=None):
"""Update the debouncer state. MUST be called frequently"""
now_ticks = ticks_ms()
self._unset_state(_CHANGED_STATE)
current_state = self.function()
if new_state is None:
current_state = self.function()
else:
current_state = bool(new_state)
if current_state != self._get_state(_UNSTABLE_STATE):
self._last_bounce_ticks = now_ticks
self._toggle_state(_UNSTABLE_STATE)
Expand Down Expand Up @@ -160,8 +163,8 @@ def _released(self):
not self.active_down and super().fell
)

def update(self):
super().update()
def update(self, new_state=None):
super().update(new_state)
if self._pushed():
self.last_change_ms = ticks_ms()
self.short_counter = self.short_counter + 1
Expand Down

0 comments on commit 72b7319

Please sign in to comment.