From 5d4c9e1bd53923f5dce6d519a9163e525187fa8f Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Fri, 1 Sep 2023 23:41:29 -0400 Subject: [PATCH] Add proxy factory to Commands --- .../edu/wpi/first/wpilibj2/command/Commands.java | 12 ++++++++++++ .../main/native/cpp/frc2/command/Commands.cpp | 9 +++++++++ .../main/native/include/frc2/command/Commands.h | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index 0130905fb4d..b39e8706731 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -100,6 +100,18 @@ public static Command print(String message) { return new PrintCommand(message); } + /** + * Constructs a command that schedules the supplied command when initialized, and ends when it is + * no longer scheduled. + * + * @param supplier the command supplier + * @return the command + * @see ProxyCommand + */ + public static Command proxy(Supplier supplier) { + return new ProxyCommand(supplier); + } + // Idling Commands /** diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp index f3c47765322..48d8f4515e0 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp @@ -11,6 +11,7 @@ #include "frc2/command/ParallelDeadlineGroup.h" #include "frc2/command/ParallelRaceGroup.h" #include "frc2/command/PrintCommand.h" +#include "frc2/command/ProxyCommand.h" #include "frc2/command/RunCommand.h" #include "frc2/command/SequentialCommandGroup.h" #include "frc2/command/WaitCommand.h" @@ -86,6 +87,14 @@ CommandPtr cmd::Print(std::string_view msg) { return PrintCommand(msg).ToPtr(); } +CommandPtr cmd::Proxy(wpi::unique_function supplier) { + return ProxyCommand(std::move(supplier)).ToPtr(); +} + +CommandPtr cmd::Proxy(wpi::unique_function supplier) { + return ProxyCommand(std::move(supplier)).ToPtr(); +} + CommandPtr cmd::Wait(units::second_t duration) { return WaitCommand(duration).ToPtr(); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h index f31bab98e05..e08fe6b625b 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h @@ -137,6 +137,22 @@ CommandPtr RunEnd(std::function run, std::function end, [[nodiscard]] CommandPtr Print(std::string_view msg); +/** + * Constructs a command that schedules the supplied command when initialized, + * and ends when it is no longer scheduled + * + * @param supplier the command supplier + */ +[[nodiscard]] CommandPtr Proxy(wpi::unique_function supplier); + +/** + * Constructs a command that schedules the supplied command when initialized, + * and ends when it is no longer scheduled + * + * @param supplier the command supplier + */ +[[nodiscard]] CommandPtr Proxy(wpi::unique_function supplier); + // Idling Commands /**