Skip to content

Commit

Permalink
Add Trigger.onChange
Browse files Browse the repository at this point in the history
Resolves #65
  • Loading branch information
spacey-sooty committed Jun 23, 2024
1 parent 4ca8a52 commit f1f73d3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions commands2/button/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ def _():

return self

def onChange(self, command: Command) -> Self:
"""
Starts the command when the condition changes.
:param command: the command t start
:returns: this trigger, so calls can be chained
"""
self._last_pressed = self._condition()

@self._loop.bind
def _():
pressed = self._condition()

if this._last_pressed != pressed:
command.schedule()

this._last_pressed = pressed

return self

def whileTrue(self, command: Command) -> Self:
"""
Starts the given command when the condition changes to `True` and cancels it when the condition
Expand Down

0 comments on commit f1f73d3

Please sign in to comment.