WPILibC++ 2023.1.1-beta-7
frc2::Button Class Reference

A class used to bind command scheduling to button presses. More...

#include <frc2/command/button/Button.h>

Inheritance diagram for frc2::Button:

## Public Member Functions

Button (std::function< bool()> isPressed)
Create a new button that is pressed when the given condition is true. More...

Button ()=default
Create a new button that is pressed active (default constructor) - activity can be further determined by subclass code. More...

Button WhenPressed (Command *command)
Binds a command to start when the button is pressed. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Button WhenPressed (T &&command)
Binds a command to start when the button is pressed. More...

Button WhenPressed (std::function< void()> toRun, std::initializer_list< Subsystem * > requirements)
Binds a runnable to execute when the button is pressed. More...

Button WhenPressed (std::function< void()> toRun, std::span< Subsystem *const > requirements={})
Binds a runnable to execute when the button is pressed. More...

Button WhileHeld (Command *command)
Binds a command to be started repeatedly while the button is pressed, and canceled when it is released. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Button WhileHeld (T &&command)
Binds a command to be started repeatedly while the button is pressed, and canceled when it is released. More...

Button WhileHeld (std::function< void()> toRun, std::initializer_list< Subsystem * > requirements)
Binds a runnable to execute repeatedly while the button is pressed. More...

Button WhileHeld (std::function< void()> toRun, std::span< Subsystem *const > requirements={})
Binds a runnable to execute repeatedly while the button is pressed. More...

Button WhenHeld (Command *command)
Binds a command to be started when the button is pressed, and canceled when it is released. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Button WhenHeld (T &&command)
Binds a command to be started when the button is pressed, and canceled when it is released. More...

Button WhenReleased (Command *command)
Binds a command to start when the button is released. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Button WhenReleased (T &&command)
Binds a command to start when the button is pressed. More...

Button WhenReleased (std::function< void()> toRun, std::initializer_list< Subsystem * > requirements)
Binds a runnable to execute when the button is released. More...

Button WhenReleased (std::function< void()> toRun, std::span< Subsystem *const > requirements={})
Binds a runnable to execute when the button is released. More...

Button ToggleWhenPressed (Command *command)
Binds a command to start when the button is pressed, and be canceled when it is pressed again. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Button ToggleWhenPressed (T &&command)
Binds a command to start when the button is pressed, and be canceled when it is pessed again. More...

Button CancelWhenPressed (Command *command)
Binds a command to be canceled when the button is pressed. More...

Public Member Functions inherited from frc2::Trigger
Trigger (std::function< bool()> condition)
Creates a new trigger based on the given condition. More...

Trigger (frc::EventLoop *loop, std::function< bool()> condition)
Creates a new trigger based on the given condition. More...

Trigger ()
Create a new trigger that is always false. More...

Trigger (const Trigger &other)

Trigger OnTrue (Command *command)
Starts the given command whenever the condition changes from false to true. More...

Trigger OnTrue (CommandPtr &&command)
Starts the given command whenever the condition changes from false to true. More...

Trigger OnFalse (Command *command)
Starts the given command whenever the condition changes from true to false. More...

Trigger OnFalse (CommandPtr &&command)
Starts the given command whenever the condition changes from true to false. More...

Trigger WhileTrue (Command *command)
Starts the given command when the condition changes to true and cancels it when the condition changes to false. More...

Trigger WhileTrue (CommandPtr &&command)
Starts the given command when the condition changes to true and cancels it when the condition changes to false. More...

Trigger WhileFalse (Command *command)
Starts the given command when the condition changes to false and cancels it when the condition changes to true. More...

Trigger WhileFalse (CommandPtr &&command)
Starts the given command when the condition changes to false and cancels it when the condition changes to true. More...

Trigger ToggleOnTrue (Command *command)
Toggles a command when the condition changes from false to true. More...

Trigger ToggleOnTrue (CommandPtr &&command)
Toggles a command when the condition changes from false to true. More...

Trigger ToggleOnFalse (Command *command)
Toggles a command when the condition changes from true to the low state. More...

Trigger ToggleOnFalse (CommandPtr &&command)
Toggles a command when the condition changes from true to the low state. More...

Trigger WhenActive (Command *command)
Binds a command to start when the trigger becomes active. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger WhenActive (T &&command)
Binds a command to start when the trigger becomes active. More...

Trigger WhenActive (std::function< void()> toRun, std::initializer_list< Subsystem * > requirements)
Binds a runnable to execute when the trigger becomes active. More...

Trigger WhenActive (std::function< void()> toRun, std::span< Subsystem *const > requirements={})
Binds a runnable to execute when the trigger becomes active. More...

Trigger WhileActiveContinous (Command *command)
Binds a command to be started repeatedly while the trigger is active, and canceled when it becomes inactive. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger WhileActiveContinous (T &&command)
Binds a command to be started repeatedly while the trigger is active, and canceled when it becomes inactive. More...

Trigger WhileActiveContinous (std::function< void()> toRun, std::initializer_list< Subsystem * > requirements)
Binds a runnable to execute repeatedly while the trigger is active. More...

Trigger WhileActiveContinous (std::function< void()> toRun, std::span< Subsystem *const > requirements={})
Binds a runnable to execute repeatedly while the trigger is active. More...

Trigger WhileActiveOnce (Command *command)
Binds a command to be started when the trigger becomes active, and canceled when it becomes inactive. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger WhileActiveOnce (T &&command)
Binds a command to be started when the trigger becomes active, and canceled when it becomes inactive. More...

Trigger WhenInactive (Command *command)
Binds a command to start when the trigger becomes inactive. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger WhenInactive (T &&command)
Binds a command to start when the trigger becomes inactive. More...

Trigger WhenInactive (std::function< void()> toRun, std::initializer_list< Subsystem * > requirements)
Binds a runnable to execute when the trigger becomes inactive. More...

Trigger WhenInactive (std::function< void()> toRun, std::span< Subsystem *const > requirements={})
Binds a runnable to execute when the trigger becomes inactive. More...

Trigger ToggleWhenActive (Command *command)
Binds a command to start when the trigger becomes active, and be canceled when it again becomes active. More...

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger ToggleWhenActive (T &&command)
Binds a command to start when the trigger becomes active, and be canceled when it again becomes active. More...

Trigger CancelWhenActive (Command *command)
Binds a command to be canceled when the trigger becomes active. More...

Trigger operator&& (std::function< bool()> rhs)
Composes two triggers with logical AND. More...

Trigger operator&& (Trigger rhs)
Composes two triggers with logical AND. More...

Trigger operator|| (std::function< bool()> rhs)
Composes two triggers with logical OR. More...

Trigger operator|| (Trigger rhs)
Composes two triggers with logical OR. More...

Trigger operator! ()
Composes a trigger with logical NOT. More...

Trigger Debounce (units::second_t debounceTime, frc::Debouncer::DebounceType type=frc::Debouncer::DebounceType::kRising)
Creates a new debounced trigger from this trigger - it will become active when this trigger has been active for longer than the specified period. More...

## Detailed Description

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

Trigger

## ◆ Button() [1/2]

 frc2::Button::Button ( std::function< bool()> isPressed )
explicit

Create a new button that is pressed when the given condition is true.

Parameters
 isPressed Whether the button is pressed.
Deprecated:
Replace with Trigger

## ◆ Button() [2/2]

 frc2::Button::Button ( )
default

Create a new button that is pressed active (default constructor) - activity can be further determined by subclass code.

Deprecated:
Replace with Trigger

## ◆ CancelWhenPressed()

 Button frc2::Button::CancelWhenPressed ( Command * command )

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.

Parameters
 command The command to bind.
Returns
The button, for chained calls.
Deprecated:
Pass this as a command end condition with Until() instead.

## ◆ ToggleWhenPressed() [1/2]

 Button frc2::Button::ToggleWhenPressed ( Command * command )

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.

Parameters
 command The command to bind.
Returns
The button, for chained calls.
Deprecated:
Replace with Trigger::ToggleOnTrue()

## ◆ ToggleWhenPressed() [2/2]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
 Button frc2::Button::ToggleWhenPressed ( T && command )
inline

Binds a command to start when the button is pressed, and be canceled when it is pessed 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.

Parameters
 command The command to bind.
Returns
The button, for chained calls.
Deprecated:
Replace with Trigger::ToggleOnTrue()

## ◆ WhenHeld() [1/2]

 Button frc2::Button::WhenHeld ( Command * command )

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.

Parameters
 command The command to bind.
Returns
The button, for chained calls.
Deprecated:
Replace with Trigger::WhileTrue()

## ◆ WhenHeld() [2/2]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
 Button frc2::Button::WhenHeld ( T && command )
inline

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.

Parameters
 command The command to bind.
Returns
The button, for chained calls.
Deprecated:
Replace with Trigger::WhileTrue()

## ◆ WhenPressed() [1/4]

 Button frc2::Button::WhenPressed ( Command * command )

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.

Parameters
 command The command to bind.
Returns
The trigger, for chained calls.
Deprecated:
Replace with Trigger::OnTrue()

## ◆ WhenPressed() [2/4]

 Button frc2::Button::WhenPressed ( std::function< void()> toRun, std::initializer_list< Subsystem * > requirements )

Binds a runnable to execute when the button is pressed.

Parameters
 toRun the runnable to execute. requirements the required subsystems.
Deprecated:
Replace with Trigger::OnTrue(cmd::RunOnce())

## ◆ WhenPressed() [3/4]

 Button frc2::Button::WhenPressed ( std::function< void()> toRun, std::span< Subsystem *const > requirements = {} )

Binds a runnable to execute when the button is pressed.

Parameters
 toRun the runnable to execute. requirements the required subsystems.
Deprecated:
Replace with Trigger::OnTrue(cmd::RunOnce())

## ◆ WhenPressed() [4/4]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
 Button frc2::Button::WhenPressed ( T && command )
inline

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.

Parameters
 command The command to bind.
Returns
The trigger, for chained calls.
Deprecated:
Replace with Trigger::OnTrue()

## ◆ WhenReleased() [1/4]

 Button frc2::Button::WhenReleased ( Command * command )

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.

Parameters
 command The command to bind.
Returns
The button, for chained calls.
Deprecated:
Replace with Trigger::OnFalse()

## ◆ WhenReleased() [2/4]

 Button frc2::Button::WhenReleased ( std::function< void()> toRun, std::initializer_list< Subsystem * > requirements )

Binds a runnable to execute when the button is released.

Parameters
 toRun the runnable to execute. requirements the required subsystems.
Deprecated:
Replace with Trigger::OnFalse(cmd::RunOnce())

## ◆ WhenReleased() [3/4]

 Button frc2::Button::WhenReleased ( std::function< void()> toRun, std::span< Subsystem *const > requirements = {} )

Binds a runnable to execute when the button is released.

Parameters
 toRun the runnable to execute. requirements the required subsystems.
Deprecated:
Replace with Trigger::OnFalse(cmd::RunOnce())

## ◆ WhenReleased() [4/4]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
 Button frc2::Button::WhenReleased ( T && command )
inline

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.

Parameters
 command The command to bind.
Returns
The button, for chained calls.
Deprecated:
Replace with Trigger::OnFalse()

## ◆ WhileHeld() [1/4]

 Button frc2::Button::WhileHeld ( Command * command )

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.

Parameters
 command The command to bind.
Returns
The button, for chained calls.
Deprecated:
Replace with Trigger::WhileTrue(command.Repeatedly())

## ◆ WhileHeld() [2/4]

 Button frc2::Button::WhileHeld ( std::function< void()> toRun, std::initializer_list< Subsystem * > requirements )

Binds a runnable to execute repeatedly while the button is pressed.

Parameters
 toRun the runnable to execute. requirements the required subsystems.
Deprecated:
Replace with Trigger::WhileTrue(cmd::Run())

## ◆ WhileHeld() [3/4]

 Button frc2::Button::WhileHeld ( std::function< void()> toRun, std::span< Subsystem *const > requirements = {} )

Binds a runnable to execute repeatedly while the button is pressed.

Parameters
 toRun the runnable to execute. requirements the required subsystems.
Deprecated:
Replace with Trigger::WhileTrue(cmd::Run())

## ◆ WhileHeld() [4/4]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
 Button frc2::Button::WhileHeld ( T && command )
inline

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.

Parameters
 command The command to bind.
Returns
The button, for chained calls.
Deprecated:
Replace with Trigger::WhileTrue(command.Repeatedly())

The documentation for this class was generated from the following file: