[commands] Refactor lambda-based commands to inherit FunctionalCommand (#4451)

This commit is contained in:
Starlight220
2022-10-07 01:49:27 +03:00
committed by GitHub
parent b2276e47de
commit 5cf961edb9
9 changed files with 44 additions and 119 deletions

View File

@@ -9,8 +9,8 @@
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
#include "frc2/command/FunctionalCommand.h"
namespace frc2 {
/**
@@ -20,7 +20,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class InstantCommand : public CommandHelper<CommandBase, InstantCommand> {
class InstantCommand : public CommandHelper<FunctionalCommand, InstantCommand> {
public:
/**
* Creates a new InstantCommand that runs the given Runnable with the given
@@ -51,12 +51,5 @@ class InstantCommand : public CommandHelper<CommandBase, InstantCommand> {
* only as a no-arg constructor to call implicitly from subclass constructors.
*/
InstantCommand();
void Initialize() override;
bool IsFinished() final;
private:
std::function<void()> m_toRun;
};
} // namespace frc2

View File

@@ -9,8 +9,8 @@
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
#include "frc2/command/FunctionalCommand.h"
namespace frc2 {
/**
@@ -21,7 +21,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class RunCommand : public CommandHelper<CommandBase, RunCommand> {
class RunCommand : public CommandHelper<FunctionalCommand, RunCommand> {
public:
/**
* Creates a new RunCommand. The Runnable will be run continuously until the
@@ -46,10 +46,5 @@ class RunCommand : public CommandHelper<CommandBase, RunCommand> {
RunCommand(RunCommand&& other) = default;
RunCommand(const RunCommand& other) = default;
void Execute() override;
protected:
std::function<void()> m_toRun;
};
} // namespace frc2

View File

@@ -9,8 +9,8 @@
#include <wpi/span.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
#include "frc2/command/FunctionalCommand.h"
namespace frc2 {
/**
@@ -22,7 +22,8 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class StartEndCommand : public CommandHelper<CommandBase, StartEndCommand> {
class StartEndCommand
: public CommandHelper<FunctionalCommand, StartEndCommand> {
public:
/**
* Creates a new StartEndCommand. Will run the given runnables when the
@@ -48,14 +49,6 @@ class StartEndCommand : public CommandHelper<CommandBase, StartEndCommand> {
StartEndCommand(StartEndCommand&& other) = default;
StartEndCommand(const StartEndCommand& other);
void Initialize() override;
void End(bool interrupted) override;
protected:
std::function<void()> m_onInit;
std::function<void()> m_onEnd;
StartEndCommand(const StartEndCommand& other) = default;
};
} // namespace frc2