mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[commands] Enhance Command Sendable implementations (#4822)
This commit is contained in:
@@ -4,13 +4,17 @@
|
||||
|
||||
#include "frc2/command/ProxyCommand.h"
|
||||
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
ProxyCommand::ProxyCommand(wpi::unique_function<Command*()> supplier)
|
||||
: m_supplier(std::move(supplier)) {}
|
||||
|
||||
ProxyCommand::ProxyCommand(Command* command)
|
||||
: m_supplier([command] { return command; }) {}
|
||||
: m_supplier([command] { return command; }) {
|
||||
SetName(std::string{"Proxy("}.append(command->GetName()).append(")"));
|
||||
}
|
||||
|
||||
ProxyCommand::ProxyCommand(std::unique_ptr<Command> command)
|
||||
: m_supplier([command = std::move(command)] { return command.get(); }) {}
|
||||
@@ -35,3 +39,17 @@ bool ProxyCommand::IsFinished() {
|
||||
// do whatever we want -- like return true.
|
||||
return m_command == nullptr || !m_command->IsScheduled();
|
||||
}
|
||||
|
||||
void ProxyCommand::InitSendable(wpi::SendableBuilder& builder) {
|
||||
CommandBase::InitSendable(builder);
|
||||
builder.AddStringProperty(
|
||||
"proxied",
|
||||
[this] {
|
||||
if (m_command) {
|
||||
return m_command->GetName();
|
||||
} else {
|
||||
return std::string{"null"};
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user