mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[commands] Add StartRun command factory (#6572)
This commit is contained in:
@@ -58,6 +58,14 @@ CommandPtr cmd::RunEnd(std::function<void()> run, std::function<void()> end,
|
||||
.ToPtr();
|
||||
}
|
||||
|
||||
CommandPtr cmd::StartRun(std::function<void()> start, std::function<void()> run,
|
||||
Requirements requirements) {
|
||||
return FunctionalCommand(
|
||||
std::move(start), std::move(run), [](bool interrupted) {},
|
||||
[] { return false; }, requirements)
|
||||
.ToPtr();
|
||||
}
|
||||
|
||||
CommandPtr cmd::Print(std::string_view msg) {
|
||||
return PrintCommand(msg).ToPtr();
|
||||
}
|
||||
|
||||
@@ -61,6 +61,11 @@ CommandPtr Subsystem::RunEnd(std::function<void()> run,
|
||||
return cmd::RunEnd(std::move(run), std::move(end), {this});
|
||||
}
|
||||
|
||||
CommandPtr Subsystem::StartRun(std::function<void()> start,
|
||||
std::function<void()> run) {
|
||||
return cmd::StartRun(std::move(start), std::move(run), {this});
|
||||
}
|
||||
|
||||
CommandPtr Subsystem::Defer(wpi::unique_function<CommandPtr()> supplier) {
|
||||
return cmd::Defer(std::move(supplier), {this});
|
||||
}
|
||||
|
||||
@@ -86,6 +86,18 @@ CommandPtr StartEnd(std::function<void()> start, std::function<void()> end,
|
||||
CommandPtr RunEnd(std::function<void()> run, std::function<void()> end,
|
||||
Requirements requirements = {});
|
||||
|
||||
/**
|
||||
* Constructs a command that runs an action once, and then runs an action every
|
||||
* iteration until interrupted.
|
||||
*
|
||||
* @param start the action to run on start
|
||||
* @param run the action to run every iteration
|
||||
* @param requirements subsystems the action requires
|
||||
*/
|
||||
[[nodiscard]]
|
||||
CommandPtr StartRun(std::function<void()> start, std::function<void()> run,
|
||||
Requirements requirements = {});
|
||||
|
||||
/**
|
||||
* Constructs a command that prints a message and finishes.
|
||||
*
|
||||
|
||||
@@ -159,6 +159,16 @@ class Subsystem {
|
||||
[[nodiscard]]
|
||||
CommandPtr RunEnd(std::function<void()> run, std::function<void()> end);
|
||||
|
||||
/**
|
||||
* Constructs a command that runs an action once, and then runs an action
|
||||
* every iteration until interrupted. Requires this subsystem.
|
||||
*
|
||||
* @param start the action to run on start
|
||||
* @param run the action to run every iteration
|
||||
*/
|
||||
[[nodiscard]]
|
||||
CommandPtr StartRun(std::function<void()> start, std::function<void()> run);
|
||||
|
||||
/**
|
||||
* Constructs a DeferredCommand with the provided supplier. This subsystem is
|
||||
* added as a requirement.
|
||||
|
||||
Reference in New Issue
Block a user