[commands] Enhance Command Sendable implementations (#4822)

This commit is contained in:
Starlight220
2022-12-16 04:28:52 +02:00
committed by GitHub
parent 7713f68772
commit fbabd0ef15
33 changed files with 239 additions and 17 deletions

View File

@@ -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);
}