mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[command] Add ignoringDisable decorator (#4305)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "frc2/command/Command.h"
|
||||
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/ConditionalCommand.h"
|
||||
#include "frc2/command/EndlessCommand.h"
|
||||
@@ -17,6 +18,7 @@
|
||||
#include "frc2/command/SequentialCommandGroup.h"
|
||||
#include "frc2/command/WaitCommand.h"
|
||||
#include "frc2/command/WaitUntilCommand.h"
|
||||
#include "frc2/command/WrapperCommand.h"
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
@@ -47,6 +49,24 @@ ParallelRaceGroup Command::Until(std::function<bool()> condition) && {
|
||||
return ParallelRaceGroup(std::move(temp));
|
||||
}
|
||||
|
||||
std::unique_ptr<Command> Command::IgnoringDisable(bool doesRunWhenDisabled) && {
|
||||
class RunsWhenDisabledCommand
|
||||
: public CommandHelper<WrapperCommand, RunsWhenDisabledCommand> {
|
||||
public:
|
||||
RunsWhenDisabledCommand(std::unique_ptr<Command>&& command,
|
||||
bool doesRunWhenDisabled)
|
||||
: CommandHelper(std::move(command)),
|
||||
m_runsWhenDisabled(doesRunWhenDisabled) {}
|
||||
bool RunsWhenDisabled() const override { return m_runsWhenDisabled; }
|
||||
|
||||
private:
|
||||
bool m_runsWhenDisabled;
|
||||
};
|
||||
|
||||
return std::make_unique<RunsWhenDisabledCommand>(
|
||||
std::move(*this).TransferOwnership(), doesRunWhenDisabled);
|
||||
}
|
||||
|
||||
ParallelRaceGroup Command::WithInterrupt(std::function<bool()> condition) && {
|
||||
std::vector<std::unique_ptr<Command>> temp;
|
||||
temp.emplace_back(std::make_unique<WaitUntilCommand>(std::move(condition)));
|
||||
|
||||
Reference in New Issue
Block a user