mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[commands] Remove deprecated classes and functions (#5409)
Removes:
- PerpetualCommand
- Command.perpetually()
- CommandGroupBase
- Command.IsGrouped() (C++ only)
- Command.SetGrouped() (C++ only)
- Command.withInterrupt()
- ProxyScheduleCommand
- Button
- InternalButton, JoystickButton, NetworkButton and POVButton now subclass Trigger
- Old style Trigger functions:
- Trigger.whenActive
- Trigger.whileActiveOnce
- Trigger.whileActiveContinuous
- Trigger.whenInactive
- Trigger.toggleWhenActive
- Trigger.cancelWhenActive
- CommandScheduler.clearButtons()
- CommandScheduler.addButtons() (Java only)
- Command supplier constructor of SelectCommand
This commit is contained in:
@@ -1,269 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <span>
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandPtr.h"
|
||||
|
||||
namespace frc2 {
|
||||
class Command;
|
||||
/**
|
||||
* A class used to bind command scheduling to button presses. Can be composed
|
||||
* with other buttons with the operators in Trigger.
|
||||
*
|
||||
* This class is provided by the NewCommands VendorDep
|
||||
*
|
||||
* @see Trigger
|
||||
*/
|
||||
class Button : public Trigger {
|
||||
public:
|
||||
/**
|
||||
* Create a new button that is pressed when the given condition is true.
|
||||
*
|
||||
* @param isPressed Whether the button is pressed.
|
||||
* @deprecated Replace with Trigger
|
||||
*/
|
||||
WPI_DEPRECATED("Replace with Trigger")
|
||||
explicit Button(std::function<bool()> isPressed);
|
||||
|
||||
/**
|
||||
* Create a new button that is pressed active (default constructor) - activity
|
||||
* can be further determined by subclass code.
|
||||
* @deprecated Replace with Trigger
|
||||
*/
|
||||
[[deprecated("Replace with Trigger")]] Button() = default;
|
||||
|
||||
/**
|
||||
* Binds a command to start when the button is pressed. Takes a
|
||||
* raw pointer, and so is non-owning; users are responsible for the lifespan
|
||||
* of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Replace with Trigger::OnTrue()
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#OnTrue()")]]
|
||||
Button WhenPressed(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to start when the button is pressed. Transfers
|
||||
* command ownership to the button scheduler, so the user does not have to
|
||||
* worry about lifespan - rvalue refs will be *moved*, lvalue refs will be
|
||||
* *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Replace with Trigger::OnTrue()
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated("Replace with Trigger#OnTrue()")]]
|
||||
Button WhenPressed(T&& command) {
|
||||
WhenActive(std::forward<T>(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute when the button is pressed.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Replace with Trigger::OnTrue(cmd::RunOnce())
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#OnTrue(cmd::RunOnce())")]]
|
||||
Button WhenPressed(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements);
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute when the button is pressed.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Replace with Trigger::OnTrue(cmd::RunOnce())
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#OnTrue(cmd::RunOnce())")]]
|
||||
Button WhenPressed(std::function<void()> toRun,
|
||||
std::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Binds a command to be started repeatedly while the button is pressed, and
|
||||
* canceled when it is released. Takes a raw pointer, and so is non-owning;
|
||||
* users are responsible for the lifespan of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::WhileTrue(command.Repeatedly())
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#WhileTrue(command.Repeatedly())")]]
|
||||
Button WhileHeld(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to be started repeatedly while the button is pressed, and
|
||||
* canceled when it is released. Transfers command ownership to the button
|
||||
* scheduler, so the user does not have to worry about lifespan - rvalue refs
|
||||
* will be *moved*, lvalue refs will be *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::WhileTrue(command.Repeatedly())
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated("Replace with Trigger#WhileTrue(command.Repeatedly())")]]
|
||||
Button WhileHeld(T&& command) {
|
||||
WhileActiveContinous(std::forward<T>(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute repeatedly while the button is pressed.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Replace with Trigger::WhileTrue(cmd::Run())
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#WhileTrue(cmd::Run())")]]
|
||||
Button WhileHeld(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements);
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute repeatedly while the button is pressed.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Replace with Trigger::WhileTrue(cmd::Run())
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#WhileTrue(cmd::Run())")]]
|
||||
Button WhileHeld(std::function<void()> toRun,
|
||||
std::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Binds a command to be started when the button is pressed, and canceled
|
||||
* when it is released. Takes a raw pointer, and so is non-owning; users are
|
||||
* responsible for the lifespan of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::WhileTrue()
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#WhileTrue()")]]
|
||||
Button WhenHeld(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to be started when the button is pressed, and canceled
|
||||
* when it is released. Transfers command ownership to the button scheduler,
|
||||
* so the user does not have to worry about lifespan - rvalue refs will be
|
||||
* *moved*, lvalue refs will be *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::WhileTrue()
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated("Replace with Trigger#WhileTrue()")]]
|
||||
Button WhenHeld(T&& command) {
|
||||
WhileActiveOnce(std::forward<T>(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a command to start when the button is released. Takes a
|
||||
* raw pointer, and so is non-owning; users are responsible for the lifespan
|
||||
* of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::OnFalse()
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#OnFalse()")]]
|
||||
Button WhenReleased(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to start when the button is pressed. Transfers
|
||||
* command ownership to the button scheduler, so the user does not have to
|
||||
* worry about lifespan - rvalue refs will be *moved*, lvalue refs will be
|
||||
* *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::OnFalse()
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated("Replace with Trigger#OnFalse()")]]
|
||||
Button WhenReleased(T&& command) {
|
||||
WhenInactive(std::forward<T>(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute when the button is released.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Replace with Trigger::OnFalse(cmd::RunOnce())
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#OnFalse(cmd::RunOnce())")]]
|
||||
Button WhenReleased(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements);
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute when the button is released.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Replace with Trigger::OnFalse(cmd::RunOnce())
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#OnFalse(cmd::RunOnce())")]]
|
||||
Button WhenReleased(std::function<void()> toRun,
|
||||
std::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Binds a command to start when the button is pressed, and be canceled when
|
||||
* it is pressed again. Takes a raw pointer, and so is non-owning; users are
|
||||
* responsible for the lifespan of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::ToggleOnTrue()
|
||||
*/
|
||||
[[deprecated("Replace with Trigger#ToggleOnTrue()")]]
|
||||
Button ToggleWhenPressed(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to start when the button is pressed, and be canceled when
|
||||
* it is pressed again. Transfers command ownership to the button scheduler,
|
||||
* so the user does not have to worry about lifespan - rvalue refs will be
|
||||
* *moved*, lvalue refs will be *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Replace with Trigger::ToggleOnTrue()
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated("Replace with Trigger#ToggleOnTrue()")]]
|
||||
Button ToggleWhenPressed(T&& command) {
|
||||
ToggleWhenActive(std::forward<T>(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a command to be canceled when the button is pressed. Takes a
|
||||
* raw pointer, and so is non-owning; users are responsible for the lifespan
|
||||
* and scheduling of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The button, for chained calls.
|
||||
* @deprecated Pass this as a command end condition with Until() instead.
|
||||
*/
|
||||
[[deprecated("Pass this as a command end condition with Until() instead.")]]
|
||||
Button CancelWhenPressed(Command* command);
|
||||
};
|
||||
} // namespace frc2
|
||||
@@ -4,9 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <frc/GenericHID.h>
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "Button.h"
|
||||
#include "Trigger.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
@@ -17,7 +16,7 @@ namespace frc2 {
|
||||
*
|
||||
* @see Trigger
|
||||
*/
|
||||
class JoystickButton : public Button {
|
||||
class JoystickButton : public Trigger {
|
||||
public:
|
||||
/**
|
||||
* Creates a JoystickButton that commands can be bound to.
|
||||
@@ -25,11 +24,9 @@ class JoystickButton : public Button {
|
||||
* @param joystick The joystick on which the button is located.
|
||||
* @param buttonNumber The number of the button on the joystick.
|
||||
*/
|
||||
WPI_IGNORE_DEPRECATED
|
||||
explicit JoystickButton(frc::GenericHID* joystick, int buttonNumber)
|
||||
: Button([joystick, buttonNumber] {
|
||||
: Trigger([joystick, buttonNumber] {
|
||||
return joystick->GetRawButton(buttonNumber);
|
||||
}) {}
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
|
||||
#include "Button.h"
|
||||
#include "Trigger.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
@@ -19,7 +19,7 @@ namespace frc2 {
|
||||
*
|
||||
* This class is provided by the NewCommands VendorDep
|
||||
*/
|
||||
class NetworkButton : public Button {
|
||||
class NetworkButton : public Trigger {
|
||||
public:
|
||||
/**
|
||||
* Creates a NetworkButton that commands can be bound to.
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <frc/GenericHID.h>
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "Button.h"
|
||||
#include "Trigger.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
@@ -18,7 +17,7 @@ namespace frc2 {
|
||||
*
|
||||
* @see Trigger
|
||||
*/
|
||||
class POVButton : public Button {
|
||||
class POVButton : public Trigger {
|
||||
public:
|
||||
/**
|
||||
* Creates a POVButton that commands can be bound to.
|
||||
@@ -27,11 +26,9 @@ class POVButton : public Button {
|
||||
* @param angle The angle of the POV corresponding to a button press.
|
||||
* @param povNumber The number of the POV on the joystick.
|
||||
*/
|
||||
WPI_IGNORE_DEPRECATED
|
||||
POVButton(frc::GenericHID* joystick, int angle, int povNumber = 0)
|
||||
: Button([joystick, angle, povNumber] {
|
||||
: Trigger([joystick, angle, povNumber] {
|
||||
return joystick->GetPOV(povNumber) == angle;
|
||||
}) {}
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -204,305 +204,6 @@ class Trigger {
|
||||
*/
|
||||
Trigger ToggleOnFalse(CommandPtr&& command);
|
||||
|
||||
/**
|
||||
* Binds a command to start when the trigger becomes active. Takes a
|
||||
* raw pointer, and so is non-owning; users are responsible for the lifespan
|
||||
* of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use OnTrue(Command) instead
|
||||
*/
|
||||
[[deprecated("Use OnTrue(Command) instead")]]
|
||||
Trigger WhenActive(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to start when the trigger becomes active. Transfers
|
||||
* command ownership to the button scheduler, so the user does not have to
|
||||
* worry about lifespan - rvalue refs will be *moved*, lvalue refs will be
|
||||
* *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use OnTrue(Command) instead
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated("Use OnTrue(Command) instead")]]
|
||||
Trigger WhenActive(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
if (!previous && current) {
|
||||
command->Schedule();
|
||||
}
|
||||
|
||||
previous = current;
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute when the trigger becomes active.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Use OnTrue(Command) instead and construct the InstantCommand
|
||||
* manually
|
||||
*/
|
||||
[[deprecated(
|
||||
"Use OnTrue(Command) instead and construct the InstantCommand manually")]]
|
||||
Trigger WhenActive(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements);
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute when the trigger becomes active.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Use OnTrue(Command) instead and construct the InstantCommand
|
||||
* manually
|
||||
*/
|
||||
[[deprecated(
|
||||
"Use OnTrue(Command) instead and construct the InstantCommand manually")]]
|
||||
Trigger WhenActive(std::function<void()> toRun,
|
||||
std::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Binds a command to be started repeatedly while the trigger is active, and
|
||||
* canceled when it becomes inactive. Takes a raw pointer, and so is
|
||||
* non-owning; users are responsible for the lifespan of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use WhileTrue(Command) with RepeatCommand, or bind
|
||||
command::Schedule with IfHigh(std::function<void()>).
|
||||
*/
|
||||
[[deprecated(
|
||||
"Use WhileTrue(Command) with RepeatCommand, or bind command::Schedule "
|
||||
"with IfHigh(std::function<void()>).")]]
|
||||
Trigger WhileActiveContinous(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to be started repeatedly while the trigger is active, and
|
||||
* canceled when it becomes inactive. Transfers command ownership to the
|
||||
* button scheduler, so the user does not have to worry about lifespan -
|
||||
* rvalue refs will be *moved*, lvalue refs will be *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use WhileTrue(Command) with RepeatCommand, or bind
|
||||
command::Schedule with IfHigh(std::function<void()>).
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated(
|
||||
"Use WhileTrue(Command) with RepeatCommand, or bind command::Schedule "
|
||||
"with IfHigh(std::function<void()>).")]]
|
||||
Trigger WhileActiveContinous(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
if (current) {
|
||||
command->Schedule();
|
||||
} else if (previous && !current) {
|
||||
command->Cancel();
|
||||
}
|
||||
|
||||
previous = current;
|
||||
});
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute repeatedly while the trigger is active.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Use WhileTrue(Command) and construct a RunCommand manually
|
||||
*/
|
||||
[[deprecated("Use WhileTrue(Command) and construct a RunCommand manually")]]
|
||||
Trigger WhileActiveContinous(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements);
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute repeatedly while the trigger is active.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Use WhileTrue(Command) and construct a RunCommand manually
|
||||
*/
|
||||
[[deprecated("Use WhileTrue(Command) and construct a RunCommand manually")]]
|
||||
Trigger WhileActiveContinous(std::function<void()> toRun,
|
||||
std::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Binds a command to be started when the trigger becomes active, and
|
||||
* canceled when it becomes inactive. Takes a raw pointer, and so is
|
||||
* non-owning; users are responsible for the lifespan of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use WhileTrue(Command) instead.
|
||||
*/
|
||||
[[deprecated("Use WhileTrue(Command) instead.")]]
|
||||
Trigger WhileActiveOnce(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to be started when the trigger becomes active, and
|
||||
* canceled when it becomes inactive. Transfers command ownership to the
|
||||
* button scheduler, so the user does not have to worry about lifespan -
|
||||
* rvalue refs will be *moved*, lvalue refs will be *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use WhileTrue(Command) instead.
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated("Use WhileTrue(Command) instead.")]]
|
||||
Trigger WhileActiveOnce(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
if (!previous && current) {
|
||||
command->Schedule();
|
||||
} else if (previous && !current) {
|
||||
command->Cancel();
|
||||
}
|
||||
|
||||
previous = current;
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a command to start when the trigger becomes inactive. Takes a
|
||||
* raw pointer, and so is non-owning; users are responsible for the lifespan
|
||||
* of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use OnFalse(Command) instead.
|
||||
*/
|
||||
[[deprecated("Use OnFalse(Command) instead.")]]
|
||||
Trigger WhenInactive(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to start when the trigger becomes inactive. Transfers
|
||||
* command ownership to the button scheduler, so the user does not have to
|
||||
* worry about lifespan - rvalue refs will be *moved*, lvalue refs will be
|
||||
* *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use OnFalse(Command) instead.
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated("Use OnFalse(Command) instead.")]]
|
||||
Trigger WhenInactive(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
if (previous && !current) {
|
||||
command->Schedule();
|
||||
}
|
||||
|
||||
previous = current;
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute when the trigger becomes inactive.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Use OnFalse(Command) instead and construct the InstantCommand
|
||||
* manually
|
||||
*/
|
||||
[[deprecated(
|
||||
"Use OnFalse(Command) instead and construct the InstantCommand "
|
||||
"manually")]]
|
||||
Trigger WhenInactive(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements);
|
||||
|
||||
/**
|
||||
* Binds a runnable to execute when the trigger becomes inactive.
|
||||
*
|
||||
* @param toRun the runnable to execute.
|
||||
* @param requirements the required subsystems.
|
||||
* @deprecated Use OnFalse(Command) instead and construct the InstantCommand
|
||||
* manually
|
||||
*/
|
||||
[[deprecated(
|
||||
"Use OnFalse(Command) instead and construct the InstantCommand "
|
||||
"manually")]]
|
||||
Trigger WhenInactive(std::function<void()> toRun,
|
||||
std::span<Subsystem* const> requirements = {});
|
||||
|
||||
/**
|
||||
* Binds a command to start when the trigger becomes active, and be canceled
|
||||
* when it again becomes active. Takes a raw pointer, and so is non-owning;
|
||||
* users are responsible for the lifespan of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use ToggleOnTrue(Command) instead.
|
||||
*/
|
||||
[[deprecated("Use ToggleOnTrue(Command) instead.")]]
|
||||
Trigger ToggleWhenActive(Command* command);
|
||||
|
||||
/**
|
||||
* Binds a command to start when the trigger becomes active, and be canceled
|
||||
* when it again becomes active. Transfers command ownership to the button
|
||||
* scheduler, so the user does not have to worry about lifespan - rvalue refs
|
||||
* will be *moved*, lvalue refs will be *copied.*
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Use ToggleOnTrue(Command) instead.
|
||||
*/
|
||||
template <std::derived_from<Command> T>
|
||||
[[deprecated("Use ToggleOnTrue(Command) instead.")]]
|
||||
Trigger ToggleWhenActive(T&& command) {
|
||||
m_loop->Bind([condition = m_condition, previous = m_condition(),
|
||||
command = std::make_unique<std::decay_t<T>>(
|
||||
std::forward<T>(command))]() mutable {
|
||||
bool current = condition();
|
||||
|
||||
if (!previous && current) {
|
||||
if (command->IsScheduled()) {
|
||||
command->Cancel();
|
||||
} else {
|
||||
command->Schedule();
|
||||
}
|
||||
}
|
||||
|
||||
previous = current;
|
||||
});
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a command to be canceled when the trigger becomes active. Takes a
|
||||
* raw pointer, and so is non-owning; users are responsible for the lifespan
|
||||
* and scheduling of the command.
|
||||
*
|
||||
* @param command The command to bind.
|
||||
* @return The trigger, for chained calls.
|
||||
* @deprecated Pass this as a command end condition with Until() instead.
|
||||
*/
|
||||
[[deprecated("Pass this as a command end condition with Until() instead.")]]
|
||||
Trigger CancelWhenActive(Command* command);
|
||||
|
||||
/**
|
||||
* Composes two triggers with logical AND.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user