From 44b87092d3d8ac059aea56c55670d1bcb18c9cb4 Mon Sep 17 00:00:00 2001 From: Spaceman 11 <135277197+Spaceman113138@users.noreply.github.com> Date: Sun, 27 Apr 2025 17:03:22 -0500 Subject: [PATCH 1/3] Update cmd.py --- commands2/cmd.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/commands2/cmd.py b/commands2/cmd.py index 42b9043..60da7dc 100644 --- a/commands2/cmd.py +++ b/commands2/cmd.py @@ -110,6 +110,21 @@ def startRun( start, run, lambda interrupt: None, lambda: False, *requirements ) +def startRunEnd( + start: Callable[[], Any], run: Callable[[], Any], end: Callable[[], Any], +*requirements: Subsystem) -> Command: + """ + Constructs a command that runs an action once, and then runs an action every iteration until interrupted, + and then runs a third action. + + :param start the action to run on start + :param run the action to run every iteration + :param end the action to run on interrupt + :returns: the command + """ + return FunctionalCommand( + start, run, lambda interrupted: end(), lambda: False, *requirements + ) def print_(message: str) -> Command: """ From cd9d1cf5e82c5e025d9bab9106005b99710d9b18 Mon Sep 17 00:00:00 2001 From: Spaceman 11 <135277197+Spaceman113138@users.noreply.github.com> Date: Sun, 27 Apr 2025 17:54:43 -0500 Subject: [PATCH 2/3] add runstartend to subsystem --- commands2/subsystem.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/commands2/subsystem.py b/commands2/subsystem.py index d0b73d0..a14148a 100644 --- a/commands2/subsystem.py +++ b/commands2/subsystem.py @@ -168,6 +168,22 @@ def startRun(self, start: Callable[[], None], run: Callable[[], None]) -> Comman return startRun(start, run, self) + def startRunEnd(self, start: Callable[[], None], run: Callable[[], None], end: Callable[[], None]) -> Command: + """ + Constructs a command that runs an action once, and then runs an action + every iteration until interrupted, and then runs a third action. + every iteration until interrupted, and then runs a third action. Requires + this subsystem. + + :param start the action to run on start + :param run the action to run every iteration + :param end the action to run on interrupt + :returns: the command + """ + from .cmd import startRunEnd + + return startRunEnd(start, run, end, self) + def idle(self) -> Command: """ Constructs a command that does nothing until interrupted. Requires this subsystem. From 447ffe7ed8851ae54243b52eeb35a22cbc203e63 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 28 Apr 2025 21:19:26 -0500 Subject: [PATCH 3/3] fix formating --- commands2/cmd.py | 13 +++++++++---- commands2/subsystem.py | 11 ++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/commands2/cmd.py b/commands2/cmd.py index 60da7dc..0d7d894 100644 --- a/commands2/cmd.py +++ b/commands2/cmd.py @@ -110,13 +110,17 @@ def startRun( start, run, lambda interrupt: None, lambda: False, *requirements ) + def startRunEnd( - start: Callable[[], Any], run: Callable[[], Any], end: Callable[[], Any], -*requirements: Subsystem) -> Command: + start: Callable[[], Any], + run: Callable[[], Any], + end: Callable[[], Any], + *requirements: Subsystem +) -> Command: """ - Constructs a command that runs an action once, and then runs an action every iteration until interrupted, + Constructs a command that runs an action once, and then runs an action every iteration until interrupted, and then runs a third action. - + :param start the action to run on start :param run the action to run every iteration :param end the action to run on interrupt @@ -126,6 +130,7 @@ def startRunEnd( start, run, lambda interrupted: end(), lambda: False, *requirements ) + def print_(message: str) -> Command: """ Constructs a command that prints a message and finishes. diff --git a/commands2/subsystem.py b/commands2/subsystem.py index a14148a..10b86a1 100644 --- a/commands2/subsystem.py +++ b/commands2/subsystem.py @@ -168,13 +168,18 @@ def startRun(self, start: Callable[[], None], run: Callable[[], None]) -> Comman return startRun(start, run, self) - def startRunEnd(self, start: Callable[[], None], run: Callable[[], None], end: Callable[[], None]) -> Command: + def startRunEnd( + self, + start: Callable[[], None], + run: Callable[[], None], + end: Callable[[], None], + ) -> Command: """ Constructs a command that runs an action once, and then runs an action every iteration until interrupted, and then runs a third action. - every iteration until interrupted, and then runs a third action. Requires + every iteration until interrupted, and then runs a third action. Requires this subsystem. - + :param start the action to run on start :param run the action to run every iteration :param end the action to run on interrupt