mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[commands] Add onlyWhile and onlyIf (#5291)
This commit is contained in:
@@ -137,6 +137,17 @@ class Command {
|
||||
*/
|
||||
[[nodiscard]] CommandPtr Until(std::function<bool()> condition) &&;
|
||||
|
||||
/**
|
||||
* Decorates this command with a run condition. If the specified condition
|
||||
* becomes false before the command finishes normally, the command will be
|
||||
* interrupted and un-scheduled. Note that this only applies to the command
|
||||
* returned by this method; the calling command is not itself changed.
|
||||
*
|
||||
* @param condition the interrupt condition
|
||||
* @return the command with the interrupt condition added
|
||||
*/
|
||||
[[nodiscard]] CommandPtr OnlyWhile(std::function<bool()> condition) &&;
|
||||
|
||||
/**
|
||||
* Decorates this command with an interrupt condition. If the specified
|
||||
* condition becomes true before the command finishes normally, the command
|
||||
@@ -245,6 +256,17 @@ safe) semantics.
|
||||
*/
|
||||
[[nodiscard]] CommandPtr Unless(std::function<bool()> condition) &&;
|
||||
|
||||
/**
|
||||
* Decorates this command to only run if this condition is met. If the command
|
||||
* is already running and the condition changes to false, the command will not
|
||||
* stop running. The requirements of this command will be kept for the new
|
||||
* conditional command.
|
||||
*
|
||||
* @param condition the condition that will allow the command to run
|
||||
* @return the decorated command
|
||||
*/
|
||||
[[nodiscard]] CommandPtr OnlyIf(std::function<bool()> condition) &&;
|
||||
|
||||
/**
|
||||
* Decorates this command to run or stop when disabled.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user