WPILibC++  2020.3.2-60-g3011ebe
frc2::Button Class Reference

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

#include <Button.h>

Inheritance diagram for frc2::Button:
frc2::Trigger frc2::JoystickButton frc2::NetworkButton frc2::POVButton

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.
 
Button WhenPressed (Command *command, bool interruptible=true)
 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, bool interruptible=true)
 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, wpi::ArrayRef< Subsystem * > requirements={})
 Binds a runnable to execute when the button is pressed. More...
 
Button WhileHeld (Command *command, bool interruptible=true)
 Binds a command to be started repeatedly while the button is pressed, and cancelled 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, bool interruptible=true)
 Binds a command to be started repeatedly while the button is pressed, and cancelled 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, wpi::ArrayRef< Subsystem * > requirements={})
 Binds a runnable to execute repeatedly while the button is pressed. More...
 
Button WhenHeld (Command *command, bool interruptible=true)
 Binds a command to be started when the button is pressed, and cancelled 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, bool interruptible=true)
 Binds a command to be started when the button is pressed, and cancelled when it is released. More...
 
Button WhenReleased (Command *command, bool interruptible=true)
 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, bool interruptible=true)
 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, wpi::ArrayRef< Subsystem * > requirements={})
 Binds a runnable to execute when the button is released. More...
 
Button ToggleWhenPressed (Command *command, bool interruptible=true)
 Binds a command to start when the button is pressed, and be cancelled 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, bool interruptible=true)
 Binds a command to start when the button is pressed, and be cancelled when it is pessed again. More...
 
Button CancelWhenPressed (Command *command)
 Binds a command to be cancelled when the button is pressed. More...
 
- Public Member Functions inherited from frc2::Trigger
 Trigger (std::function< bool()> isActive)
 Create a new trigger that is active when the given condition is true. More...
 
 Trigger ()
 Create a new trigger that is never active (default constructor) - activity can be further determined by subclass code.
 
 Trigger (const Trigger &other)
 
Trigger WhenActive (Command *command, bool interruptible=true)
 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, bool interruptible=true)
 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, wpi::ArrayRef< Subsystem * > requirements={})
 Binds a runnable to execute when the trigger becomes active. More...
 
Trigger WhileActiveContinous (Command *command, bool interruptible=true)
 Binds a command to be started repeatedly while the trigger is active, and cancelled 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, bool interruptible=true)
 Binds a command to be started repeatedly while the trigger is active, and cancelled 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, wpi::ArrayRef< Subsystem * > requirements={})
 Binds a runnable to execute repeatedly while the trigger is active. More...
 
Trigger WhileActiveOnce (Command *command, bool interruptible=true)
 Binds a command to be started when the trigger becomes active, and cancelled 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, bool interruptible=true)
 Binds a command to be started when the trigger becomes active, and cancelled when it becomes inactive. More...
 
Trigger WhenInactive (Command *command, bool interruptible=true)
 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, bool interruptible=true)
 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, wpi::ArrayRef< Subsystem * > requirements={})
 Binds a runnable to execute when the trigger becomes inactive. More...
 
Trigger ToggleWhenActive (Command *command, bool interruptible=true)
 Binds a command to start when the trigger becomes active, and be cancelled 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, bool interruptible=true)
 Binds a command to start when the trigger becomes active, and be cancelled when it again becomes active. More...
 
Trigger CancelWhenActive (Command *command)
 Binds a command to be cancelled when the trigger becomes active. More...
 
Trigger operator&& (Trigger rhs)
 Composes two triggers with logical AND. More...
 
Trigger operator|| (Trigger rhs)
 Composes two triggers with logical OR. More...
 
Trigger operator! ()
 Composes a trigger with logical NOT. More...
 

Detailed Description

A class used to bind command scheduling to button presses.

Can be composed with other buttons with the operators in Trigger.

See also
Trigger

Constructor & Destructor Documentation

◆ Button()

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

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

Parameters
isActiveWhether the button is pressed.

Member Function Documentation

◆ CancelWhenPressed()

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

Binds a command to be cancelled 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
commandThe command to bind.
Returns
The button, for chained calls.

◆ ToggleWhenPressed() [1/2]

Button frc2::Button::ToggleWhenPressed ( Command command,
bool  interruptible = true 
)

Binds a command to start when the button is pressed, and be cancelled when it is pressed again.

Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.

Parameters
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The button, for chained calls.

◆ 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,
bool  interruptible = true 
)
inline

Binds a command to start when the button is pressed, and be cancelled 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
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The button, for chained calls.

◆ WhenHeld() [1/2]

Button frc2::Button::WhenHeld ( Command command,
bool  interruptible = true 
)

Binds a command to be started when the button is pressed, and cancelled when it is released.

Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.

Parameters
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The button, for chained calls.

◆ 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,
bool  interruptible = true 
)
inline

Binds a command to be started when the button is pressed, and cancelled 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
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The button, for chained calls.

◆ WhenPressed() [1/4]

Button frc2::Button::WhenPressed ( Command command,
bool  interruptible = true 
)

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
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The trigger, for chained calls.

◆ 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
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ WhenPressed() [3/4]

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

Binds a runnable to execute when the button is pressed.

Parameters
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ 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,
bool  interruptible = true 
)
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
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The trigger, for chained calls.

◆ WhenReleased() [1/4]

Button frc2::Button::WhenReleased ( Command command,
bool  interruptible = true 
)

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
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The button, for chained calls.

◆ 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
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ WhenReleased() [3/4]

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

Binds a runnable to execute when the button is released.

Parameters
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ 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,
bool  interruptible = true 
)
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
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The button, for chained calls.

◆ WhileHeld() [1/4]

Button frc2::Button::WhileHeld ( Command command,
bool  interruptible = true 
)

Binds a command to be started repeatedly while the button is pressed, and cancelled when it is released.

Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.

Parameters
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The button, for chained calls.

◆ 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
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ WhileHeld() [3/4]

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

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

Parameters
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ 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,
bool  interruptible = true 
)
inline

Binds a command to be started repeatedly while the button is pressed, and cancelled 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
commandThe command to bind.
interruptibleWhether the command should be interruptible.
Returns
The button, for chained calls.

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