[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,6 +4,8 @@
#include "frc2/command/ConditionalCommand.h"
#include <wpi/sendable/SendableBuilder.h>
using namespace frc2;
ConditionalCommand::ConditionalCommand(std::unique_ptr<Command>&& onTrue,
@@ -50,3 +52,21 @@ bool ConditionalCommand::IsFinished() {
bool ConditionalCommand::RunsWhenDisabled() const {
return m_runsWhenDisabled;
}
void ConditionalCommand::InitSendable(wpi::SendableBuilder& builder) {
CommandBase::InitSendable(builder);
builder.AddStringProperty(
"onTrue", [this] { return m_onTrue->GetName(); }, nullptr);
builder.AddStringProperty(
"onFalse", [this] { return m_onFalse->GetName(); }, nullptr);
builder.AddStringProperty(
"selected",
[this] {
if (m_selectedCommand) {
return m_selectedCommand->GetName();
} else {
return std::string{"null"};
}
},
nullptr);
}