Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger: pass loop to new Trigger in composition functions #58

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gittrack
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[git-source-track]
upstream_root = ../allwpilib/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command
upstream_branch = main
upstream_commit = 4b94a64b06057c723d6fcafeb1a45f55a70d179a
upstream_commit = 25ad6eafd5eeaf57ed25db2414a20838bf098399
validation_root = commands2

10 changes: 5 additions & 5 deletions commands2/button/trigger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2024-01-23 DS 70b60e3a7465 button/Trigger.java
# validated: 2024-04-02 DS 0b1345946950 button/Trigger.java
from types import SimpleNamespace
from typing import Callable, overload

Expand Down Expand Up @@ -227,7 +227,7 @@ def __bool__(self) -> bool:

def __and__(self, other: Callable[[], bool]) -> "Trigger":
assert callable(other)
return Trigger(lambda: self() and other())
return Trigger(self._loop, lambda: self() and other())

def and_(self, other: Callable[[], bool]) -> "Trigger":
"""
Expand All @@ -240,7 +240,7 @@ def and_(self, other: Callable[[], bool]) -> "Trigger":

def __or__(self, other: Callable[[], bool]) -> "Trigger":
assert callable(other)
return Trigger(lambda: self() or other())
return Trigger(self._loop, lambda: self() or other())

def or_(self, other: Callable[[], bool]) -> "Trigger":
"""
Expand All @@ -252,7 +252,7 @@ def or_(self, other: Callable[[], bool]) -> "Trigger":
return self | other

def __invert__(self) -> "Trigger":
return Trigger(lambda: not self())
return Trigger(self._loop, lambda: not self())

def negate(self) -> "Trigger":
"""
Expand Down Expand Up @@ -280,4 +280,4 @@ def debounce(
:returns: The debounced trigger.
"""
debouncer = Debouncer(seconds, debounce_type)
return Trigger(lambda: debouncer.calculate(self()))
return Trigger(self._loop, lambda: debouncer.calculate(self()))
Loading