[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:
Ryan Blue
2023-07-10 12:56:18 -04:00
committed by GitHub
parent b250a03944
commit 7a099cb02a
49 changed files with 82 additions and 2031 deletions

View File

@@ -115,25 +115,6 @@ public interface Command {
return until(() -> !condition.getAsBoolean());
}
/**
* Decorates this command with an interrupt condition. If the specified condition becomes true
* before the command finishes normally, the command will be interrupted and un-scheduled.
*
* <p>Note: This decorator works by adding this command to a composition. The command the
* decorator was called on cannot be scheduled independently or be added to a different
* composition (namely, decorators), unless it is manually cleared from the list of composed
* commands with {@link CommandScheduler#removeComposedCommand(Command)}. The command composition
* returned from this method can be further decorated without issue.
*
* @param condition the interrupt condition
* @return the command with the interrupt condition added
* @deprecated Replace with {@link #until(BooleanSupplier)}
*/
@Deprecated(since = "2023")
default ParallelRaceGroup withInterrupt(BooleanSupplier condition) {
return until(condition);
}
/**
* Decorates this command with a runnable to run before this command starts.
*
@@ -261,28 +242,6 @@ public interface Command {
return group;
}
/**
* Decorates this command to run perpetually, ignoring its ordinary end conditions. The decorated
* command can still be interrupted or canceled.
*
* <p>Note: This decorator works by adding this command to a composition. The command the
* decorator was called on cannot be scheduled independently or be added to a different
* composition (namely, decorators), unless it is manually cleared from the list of composed
* commands with {@link CommandScheduler#removeComposedCommand(Command)}. The command composition
* returned from this method can be further decorated without issue.
*
* @return the decorated command
* @deprecated PerpetualCommand violates the assumption that execute() doesn't get called after
* isFinished() returns true -- an assumption that should be valid. This was unsafe/undefined
* behavior from the start, and RepeatCommand provides an easy way to achieve similar end
* results with slightly different (and safe) semantics.
*/
@SuppressWarnings("removal") // PerpetualCommand
@Deprecated(forRemoval = true, since = "2023")
default PerpetualCommand perpetually() {
return new PerpetualCommand(this);
}
/**
* Decorates this command to run repeatedly, restarting it when it ends, until this command is
* interrupted. The decorated command can still be canceled.

View File

@@ -1,71 +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.
package edu.wpi.first.wpilibj2.command;
/**
* A base for CommandGroups.
*
* <p>This class is provided by the NewCommands VendorDep
*
* @deprecated This class is an empty abstraction. Inherit directly from CommandBase/Command.
*/
@Deprecated(forRemoval = true)
public abstract class CommandGroupBase extends CommandBase {
/**
* Adds the given commands to the command group.
*
* @param commands The commands to add.
*/
public abstract void addCommands(Command... commands);
/**
* Factory method for {@link SequentialCommandGroup}, included for brevity/convenience.
*
* @param commands the commands to include
* @return the command group
* @deprecated Replace with {@link Commands#sequence(Command...)}
*/
@Deprecated
public static SequentialCommandGroup sequence(Command... commands) {
return new SequentialCommandGroup(commands);
}
/**
* Factory method for {@link ParallelCommandGroup}, included for brevity/convenience.
*
* @param commands the commands to include
* @return the command group
* @deprecated Replace with {@link Commands#parallel(Command...)}
*/
@Deprecated
public static ParallelCommandGroup parallel(Command... commands) {
return new ParallelCommandGroup(commands);
}
/**
* Factory method for {@link ParallelRaceGroup}, included for brevity/convenience.
*
* @param commands the commands to include
* @return the command group
* @deprecated Replace with {@link Commands#race(Command...)}
*/
@Deprecated
public static ParallelRaceGroup race(Command... commands) {
return new ParallelRaceGroup(commands);
}
/**
* Factory method for {@link ParallelDeadlineGroup}, included for brevity/convenience.
*
* @param deadline the deadline command
* @param commands the commands to include
* @return the command group
* @deprecated Replace with {@link Commands#deadline(Command, Command...)}
*/
@Deprecated
public static ParallelDeadlineGroup deadline(Command deadline, Command... commands) {
return new ParallelDeadlineGroup(deadline, commands);
}
}

View File

@@ -151,27 +151,6 @@ public final class CommandScheduler implements NTSendable, AutoCloseable {
requireNonNullParam(loop, "loop", "CommandScheduler" + ".replaceButtonEventLoop");
}
/**
* Adds a button binding to the scheduler, which will be polled to schedule commands.
*
* @param button The button to add
* @deprecated Use {@link edu.wpi.first.wpilibj2.command.button.Trigger}
*/
@Deprecated(since = "2023")
public void addButton(Runnable button) {
m_activeButtonLoop.bind(requireNonNullParam(button, "button", "addButton"));
}
/**
* Removes all button bindings from the scheduler.
*
* @deprecated call {@link EventLoop#clear()} on {@link #getActiveButtonLoop()} directly instead.
*/
@Deprecated(since = "2023")
public void clearButtons() {
m_activeButtonLoop.clear();
}
/**
* Initializes a given command, adds its requirements to the list, and performs the init actions.
*

View File

@@ -17,8 +17,7 @@ import java.util.Map;
*
* <p>This class is provided by the NewCommands VendorDep
*/
@SuppressWarnings("removal")
public class ParallelCommandGroup extends CommandGroupBase {
public class ParallelCommandGroup extends CommandBase {
// maps commands in this composition to whether they are still running
private final Map<Command, Boolean> m_commands = new HashMap<>();
private boolean m_runWhenDisabled = true;
@@ -35,7 +34,11 @@ public class ParallelCommandGroup extends CommandGroupBase {
addCommands(commands);
}
@Override
/**
* Adds the given commands to the group.
*
* @param commands Commands to add to the group.
*/
public final void addCommands(Command... commands) {
if (m_commands.containsValue(true)) {
throw new IllegalStateException(

View File

@@ -20,8 +20,7 @@ import java.util.Map;
*
* <p>This class is provided by the NewCommands VendorDep
*/
@SuppressWarnings("removal")
public class ParallelDeadlineGroup extends CommandGroupBase {
public class ParallelDeadlineGroup extends CommandBase {
// maps commands in this composition to whether they are still running
private final Map<Command, Boolean> m_commands = new HashMap<>();
private boolean m_runWhenDisabled = true;
@@ -59,7 +58,11 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
m_deadline = deadline;
}
@Override
/**
* Adds the given commands to the group.
*
* @param commands Commands to add to the group.
*/
public final void addCommands(Command... commands) {
if (!m_finished) {
throw new IllegalStateException(

View File

@@ -18,8 +18,7 @@ import java.util.Set;
*
* <p>This class is provided by the NewCommands VendorDep
*/
@SuppressWarnings("removal")
public class ParallelRaceGroup extends CommandGroupBase {
public class ParallelRaceGroup extends CommandBase {
private final Set<Command> m_commands = new HashSet<>();
private boolean m_runWhenDisabled = true;
private boolean m_finished = true;
@@ -36,7 +35,11 @@ public class ParallelRaceGroup extends CommandGroupBase {
addCommands(commands);
}
@Override
/**
* Adds the given commands to the group.
*
* @param commands Commands to add to the group.
*/
public final void addCommands(Command... commands) {
if (!m_finished) {
throw new IllegalStateException(

View File

@@ -1,57 +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.
package edu.wpi.first.wpilibj2.command;
/**
* A command that runs another command in perpetuity, ignoring that command's end conditions. While
* this class does not extend {@link CommandGroupBase}, it is still considered a composition, as it
* allows one to compose another command within it; the command instances that are passed to it
* cannot be added to any other groups, or scheduled individually.
*
* <p>As a rule, CommandGroups require the union of the requirements of their component commands.
*
* <p>This class is provided by the NewCommands VendorDep
*
* @deprecated PerpetualCommand violates the assumption that execute() doesn't get called after
* isFinished() returns true -- an assumption that should be valid. This was unsafe/undefined
* behavior from the start, and RepeatCommand provides an easy way to achieve similar end
* results with slightly different (and safe) semantics.
*/
@Deprecated(forRemoval = true, since = "2023")
public class PerpetualCommand extends CommandBase {
protected final Command m_command;
/**
* Creates a new PerpetualCommand. Will run another command in perpetuity, ignoring that command's
* end conditions, unless this command itself is interrupted.
*
* @param command the command to run perpetually
*/
public PerpetualCommand(Command command) {
CommandScheduler.getInstance().registerComposedCommands(command);
m_command = command;
m_requirements.addAll(command.getRequirements());
}
@Override
public void initialize() {
m_command.initialize();
}
@Override
public void execute() {
m_command.execute();
}
@Override
public void end(boolean interrupted) {
m_command.end(interrupted);
}
@Override
public boolean runsWhenDisabled() {
return m_command.runsWhenDisabled();
}
}

View File

@@ -1,61 +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.
package edu.wpi.first.wpilibj2.command;
import java.util.Set;
/**
* Schedules the given commands when this command is initialized, and ends when all the commands are
* no longer scheduled. Useful for forking off from CommandGroups. If this command is interrupted,
* it will cancel all the commands.
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class ProxyScheduleCommand extends CommandBase {
private final Set<Command> m_toSchedule;
private boolean m_finished;
/**
* Creates a new ProxyScheduleCommand that schedules the given commands when initialized, and ends
* when they are all no longer scheduled.
*
* @param toSchedule the commands to schedule
* @deprecated Replace with {@link ProxyCommand}, composing multiple of them in a {@link
* ParallelRaceGroup} if needed.
*/
@Deprecated
public ProxyScheduleCommand(Command... toSchedule) {
m_toSchedule = Set.of(toSchedule);
}
@Override
public void initialize() {
for (Command command : m_toSchedule) {
command.schedule();
}
}
@Override
public void end(boolean interrupted) {
if (interrupted) {
for (Command command : m_toSchedule) {
command.cancel();
}
}
}
@Override
public void execute() {
m_finished = true;
for (Command command : m_toSchedule) {
m_finished &= !command.isScheduled();
}
}
@Override
public boolean isFinished() {
return m_finished;
}
}

View File

@@ -23,7 +23,6 @@ import java.util.function.Supplier;
public class SelectCommand extends CommandBase {
private final Map<Object, Command> m_commands;
private final Supplier<Object> m_selector;
private final Supplier<Command> m_toRun;
private Command m_selectedCommand;
private boolean m_runsWhenDisabled = true;
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;
@@ -41,8 +40,6 @@ public class SelectCommand extends CommandBase {
CommandScheduler.getInstance()
.registerComposedCommands(commands.values().toArray(new Command[] {}));
m_toRun = null;
for (Command command : m_commands.values()) {
m_requirements.addAll(command.getRequirements());
m_runsWhenDisabled &= command.runsWhenDisabled();
@@ -52,35 +49,13 @@ public class SelectCommand extends CommandBase {
}
}
/**
* Creates a new SelectCommand.
*
* @param toRun a supplier providing the command to run
* @deprecated Replace with {@link ProxyCommand}
*/
@Deprecated
public SelectCommand(Supplier<Command> toRun) {
m_commands = null;
m_selector = null;
m_toRun = requireNonNullParam(toRun, "toRun", "SelectCommand");
// we have no way of checking the underlying command, so default.
m_runsWhenDisabled = false;
m_interruptBehavior = InterruptionBehavior.kCancelSelf;
}
@Override
public void initialize() {
if (m_selector != null) {
if (!m_commands.containsKey(m_selector.get())) {
m_selectedCommand =
new PrintCommand(
"SelectCommand selector value does not correspond to" + " any command!");
return;
}
m_selectedCommand = m_commands.get(m_selector.get());
if (!m_commands.containsKey(m_selector.get())) {
m_selectedCommand =
new PrintCommand("SelectCommand selector value does not correspond to any command!");
} else {
m_selectedCommand = m_toRun.get();
m_selectedCommand = m_commands.get(m_selector.get());
}
m_selectedCommand.initialize();
}

View File

@@ -17,8 +17,7 @@ import java.util.List;
*
* <p>This class is provided by the NewCommands VendorDep
*/
@SuppressWarnings("removal")
public class SequentialCommandGroup extends CommandGroupBase {
public class SequentialCommandGroup extends CommandBase {
private final List<Command> m_commands = new ArrayList<>();
private int m_currentCommandIndex = -1;
private boolean m_runWhenDisabled = true;
@@ -34,7 +33,11 @@ public class SequentialCommandGroup extends CommandGroupBase {
addCommands(commands);
}
@Override
/**
* Adds the given commands to the group.
*
* @param commands Commands to add, in order of execution.
*/
public final void addCommands(Command... commands) {
if (m_currentCommandIndex != -1) {
throw new IllegalStateException(

View File

@@ -1,169 +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.
package edu.wpi.first.wpilibj2.command.button;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Subsystem;
import java.util.function.BooleanSupplier;
/**
* This class provides an easy way to link commands to OI inputs.
*
* <p>It is very easy to link a button to a command. For instance, you could link the trigger button
* of a joystick to a "score" command.
*
* <p>This class represents a subclass of Trigger that is specifically aimed at buttons on an
* operator interface as a common use case of the more generalized Trigger objects. This is a simple
* wrapper around Trigger with the method names renamed to fit the Button object use.
*
* @deprecated Replace with {@link Trigger}.
*/
@Deprecated
public class Button extends Trigger {
/**
* Default constructor; creates a button that is never pressed.
*
* @deprecated Replace with {@code new Button(() -> false) }.
*/
@Deprecated(since = "2023")
public Button() {}
/**
* Creates a new button with the given condition determining whether it is pressed.
*
* @param isPressed returns whether the trigger should be active
* @deprecated Replace with Trigger.
*/
@Deprecated
public Button(BooleanSupplier isPressed) {
super(isPressed);
}
/**
* Starts the given command whenever the button is newly pressed.
*
* @param command the command to start
* @return this button, so calls can be chained
* @deprecated Replace with {@link Trigger#onTrue(Command)}
*/
@Deprecated
public Button whenPressed(final Command command) {
whenActive(command);
return this;
}
/**
* Runs the given runnable whenever the button is newly pressed.
*
* @param toRun the runnable to run
* @param requirements the required subsystems
* @return this button, so calls can be chained
* @deprecated Replace with {@link #onTrue(Command)}, creating the InstantCommand manually
*/
@Deprecated
public Button whenPressed(final Runnable toRun, Subsystem... requirements) {
whenActive(toRun, requirements);
return this;
}
/**
* Constantly starts the given command while the button is held.
*
* <p>{@link Command#schedule()} will be called repeatedly while the button is held, and will be
* canceled when the button is released.
*
* @param command the command to start
* @return this button, so calls can be chained
* @deprecated Use {@link #whileTrue(Command)} with {@link
* edu.wpi.first.wpilibj2.command.RepeatCommand RepeatCommand}.
*/
@Deprecated
public Button whileHeld(final Command command) {
whileActiveContinuous(command);
return this;
}
/**
* Constantly runs the given runnable while the button is held.
*
* @param toRun the runnable to run
* @param requirements the required subsystems
* @return this button, so calls can be chained
* @deprecated Use {@link #whileTrue(Command)} and construct a RunCommand manually
*/
@Deprecated
public Button whileHeld(final Runnable toRun, Subsystem... requirements) {
whileActiveContinuous(toRun, requirements);
return this;
}
/**
* Starts the given command when the button is first pressed, and cancels it when it is released,
* but does not start it again if it ends or is otherwise interrupted.
*
* @param command the command to start
* @return this button, so calls can be chained
* @deprecated Replace with {@link Trigger#whileTrue(Command)}
*/
@Deprecated
public Button whenHeld(final Command command) {
whileActiveOnce(command);
return this;
}
/**
* Starts the command when the button is released. The command is set to be interruptible.
*
* @param command the command to start
* @return this button, so calls can be chained
* @deprecated Replace with {@link Trigger#onFalse(Command)}
*/
@Deprecated
public Button whenReleased(final Command command) {
whenInactive(command);
return this;
}
/**
* Runs the given runnable when the button is released.
*
* @param toRun the runnable to run
* @param requirements the required subsystems
* @return this button, so calls can be chained
* @deprecated Replace with {@link Trigger#onFalse(Command)}, creating the InstantCommand manually
*/
@Deprecated
public Button whenReleased(final Runnable toRun, Subsystem... requirements) {
whenInactive(toRun, requirements);
return this;
}
/**
* Toggles the command whenever the button is pressed (on, then off, then on). The command is set
* to be interruptible.
*
* @param command the command to start
* @return this button, so calls can be chained
* @deprecated Replace with {@link Trigger#toggleOnTrue(Command)}
*/
@Deprecated
public Button toggleWhenPressed(final Command command) {
toggleWhenActive(command);
return this;
}
/**
* Cancels the command when the button is pressed.
*
* @param command the command to start
* @return this button, so calls can be chained
* @deprecated Instead, pass this as an end condition to {@link Command#until(BooleanSupplier)}.
*/
@Deprecated
public Button cancelWhenPressed(final Command command) {
cancelWhenActive(command);
return this;
}
}

View File

@@ -12,8 +12,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
*
* <p>This class is provided by the NewCommands VendorDep
*/
@SuppressWarnings("deprecation")
public class InternalButton extends Button {
public class InternalButton extends Trigger {
// need to be references, so they can be mutated after being captured in the constructor.
private final AtomicBoolean m_pressed;
private final AtomicBoolean m_inverted;

View File

@@ -9,12 +9,11 @@ import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.wpilibj.GenericHID;
/**
* A {@link Button} that gets its state from a {@link GenericHID}.
* A {@link Trigger} that gets its state from a {@link GenericHID}.
*
* <p>This class is provided by the NewCommands VendorDep
*/
@SuppressWarnings("deprecation")
public class JoystickButton extends Button {
public class JoystickButton extends Trigger {
/**
* Creates a joystick button for triggering commands.
*

View File

@@ -12,12 +12,11 @@ import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
/**
* A {@link Button} that uses a {@link NetworkTable} boolean field.
* A {@link Trigger} that uses a {@link NetworkTable} boolean field.
*
* <p>This class is provided by the NewCommands VendorDep
*/
@SuppressWarnings("deprecation")
public class NetworkButton extends Button {
public class NetworkButton extends Trigger {
/**
* Creates a NetworkButton that commands can be bound to.
*

View File

@@ -9,12 +9,11 @@ import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.wpilibj.GenericHID;
/**
* A {@link Button} that gets its state from a POV on a {@link GenericHID}.
* A {@link Trigger} that gets its state from a POV on a {@link GenericHID}.
*
* <p>This class is provided by the NewCommands VendorDep
*/
@SuppressWarnings("deprecation")
public class POVButton extends Button {
public class POVButton extends Trigger {
/**
* Creates a POV button for triggering commands.
*

View File

@@ -7,12 +7,9 @@ package edu.wpi.first.wpilibj2.command.button;
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.math.filter.Debouncer;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.Subsystem;
import java.util.function.BooleanSupplier;
/**
@@ -52,12 +49,6 @@ public class Trigger implements BooleanSupplier {
this(CommandScheduler.getInstance().getDefaultButtonLoop(), condition);
}
/** Creates a new trigger that is always `false`. */
@Deprecated
public Trigger() {
this(() -> false);
}
/**
* Starts the given command whenever the condition changes from `false` to `true`.
*
@@ -234,238 +225,6 @@ public class Trigger implements BooleanSupplier {
return this;
}
/**
* Starts the given command whenever the trigger just becomes active.
*
* @param command the command to start
* @return this trigger, so calls can be chained
* @deprecated Use {@link #onTrue(Command)} instead.
*/
@Deprecated
public Trigger whenActive(final Command command) {
requireNonNullParam(command, "command", "whenActive");
m_loop.bind(
new Runnable() {
private boolean m_pressedLast = m_condition.getAsBoolean();
@Override
public void run() {
boolean pressed = m_condition.getAsBoolean();
if (!m_pressedLast && pressed) {
command.schedule();
}
m_pressedLast = pressed;
}
});
return this;
}
/**
* Runs the given runnable whenever the trigger just becomes active.
*
* @param toRun the runnable to run
* @param requirements the required subsystems
* @return this trigger, so calls can be chained
* @deprecated Replace with {@link #onTrue(Command)}, creating the InstantCommand manually
*/
@Deprecated
public Trigger whenActive(final Runnable toRun, Subsystem... requirements) {
return whenActive(new InstantCommand(toRun, requirements));
}
/**
* Constantly starts the given command while the button is held.
*
* <p>{@link Command#schedule()} will be called repeatedly while the trigger is active, and will
* be canceled when the trigger becomes inactive.
*
* @param command the command to start
* @return this trigger, so calls can be chained
* @deprecated Use {@link #whileTrue(Command)} with {@link
* edu.wpi.first.wpilibj2.command.RepeatCommand RepeatCommand}, or bind {@link
* Command#schedule() command::schedule} to {@link BooleanEvent#ifHigh(Runnable)} (passing no
* requirements).
*/
@Deprecated
public Trigger whileActiveContinuous(final Command command) {
requireNonNullParam(command, "command", "whileActiveContinuous");
m_loop.bind(
new Runnable() {
private boolean m_pressedLast = m_condition.getAsBoolean();
@Override
public void run() {
boolean pressed = m_condition.getAsBoolean();
if (pressed) {
command.schedule();
} else if (m_pressedLast) {
command.cancel();
}
m_pressedLast = pressed;
}
});
return this;
}
/**
* Constantly runs the given runnable while the button is held.
*
* @param toRun the runnable to run
* @param requirements the required subsystems
* @return this trigger, so calls can be chained
* @deprecated Use {@link #whileTrue(Command)} and construct a RunCommand manually
*/
@Deprecated
public Trigger whileActiveContinuous(final Runnable toRun, Subsystem... requirements) {
return whileActiveContinuous(new InstantCommand(toRun, requirements));
}
/**
* Starts the given command when the trigger initially becomes active, and ends it when it becomes
* inactive, but does not re-start it in-between.
*
* @param command the command to start
* @return this trigger, so calls can be chained
* @deprecated Use {@link #whileTrue(Command)} instead.
*/
@Deprecated
public Trigger whileActiveOnce(final Command command) {
requireNonNullParam(command, "command", "whileActiveOnce");
m_loop.bind(
new Runnable() {
private boolean m_pressedLast = m_condition.getAsBoolean();
@Override
public void run() {
boolean pressed = m_condition.getAsBoolean();
if (!m_pressedLast && pressed) {
command.schedule();
} else if (m_pressedLast && !pressed) {
command.cancel();
}
m_pressedLast = pressed;
}
});
return this;
}
/**
* Starts the command when the trigger becomes inactive.
*
* @param command the command to start
* @return this trigger, so calls can be chained
* @deprecated Use {@link #onFalse(Command)} instead.
*/
@Deprecated
public Trigger whenInactive(final Command command) {
requireNonNullParam(command, "command", "whenInactive");
m_loop.bind(
new Runnable() {
private boolean m_pressedLast = m_condition.getAsBoolean();
@Override
public void run() {
boolean pressed = m_condition.getAsBoolean();
if (m_pressedLast && !pressed) {
command.schedule();
}
m_pressedLast = pressed;
}
});
return this;
}
/**
* Runs the given runnable when the trigger becomes inactive.
*
* @param toRun the runnable to run
* @param requirements the required subsystems
* @return this trigger, so calls can be chained
* @deprecated Construct the InstantCommand manually and replace with {@link #onFalse(Command)}
*/
@Deprecated
public Trigger whenInactive(final Runnable toRun, Subsystem... requirements) {
return whenInactive(new InstantCommand(toRun, requirements));
}
/**
* Toggles a command when the trigger becomes active.
*
* @param command the command to toggle
* @return this trigger, so calls can be chained
* @deprecated Use {@link #toggleOnTrue(Command)} instead.
*/
@Deprecated
public Trigger toggleWhenActive(final Command command) {
requireNonNullParam(command, "command", "toggleWhenActive");
m_loop.bind(
new Runnable() {
private boolean m_pressedLast = m_condition.getAsBoolean();
@Override
public void run() {
boolean pressed = m_condition.getAsBoolean();
if (!m_pressedLast && pressed) {
if (command.isScheduled()) {
command.cancel();
} else {
command.schedule();
}
}
m_pressedLast = pressed;
}
});
return this;
}
/**
* Cancels a command when the trigger becomes active.
*
* @param command the command to cancel
* @return this trigger, so calls can be chained
* @deprecated Instead, pass this as an end condition to {@link Command#until(BooleanSupplier)}.
*/
@Deprecated
public Trigger cancelWhenActive(final Command command) {
requireNonNullParam(command, "command", "cancelWhenActive");
m_loop.bind(
new Runnable() {
private boolean m_pressedLast = m_condition.getAsBoolean();
@Override
public void run() {
boolean pressed = m_condition.getAsBoolean();
if (!m_pressedLast && pressed) {
command.cancel();
}
m_pressedLast = pressed;
}
});
return this;
}
@Override
public boolean getAsBoolean() {
return m_condition.getAsBoolean();