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

A class used to bind command scheduling to events. More...

#include <Trigger.h>

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

Public Member Functions

 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 events.

The Trigger class is a base for all command-event-binding classes, and so the methods are named fairly abstractly; for purpose-specific wrappers, see Button.

See also
Button

Constructor & Destructor Documentation

◆ Trigger()

frc2::Trigger::Trigger ( std::function< bool()>  isActive)
inlineexplicit

Create a new trigger that is active when the given condition is true.

Parameters
isActiveWhether the trigger is active.

Member Function Documentation

◆ CancelWhenActive()

Trigger frc2::Trigger::CancelWhenActive ( Command command)

Binds a command to be cancelled 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.

Parameters
commandThe command to bind.
Returns
The trigger, for chained calls.

◆ operator!()

Trigger frc2::Trigger::operator! ( )
inline

Composes a trigger with logical NOT.

Returns
A trigger which is active when the component trigger is inactive, and vice-versa.

◆ operator&&()

Trigger frc2::Trigger::operator&& ( Trigger  rhs)
inline

Composes two triggers with logical AND.

Returns
A trigger which is active when both component triggers are active.

◆ operator||()

Trigger frc2::Trigger::operator|| ( Trigger  rhs)
inline

Composes two triggers with logical OR.

Returns
A trigger which is active when either component trigger is active.

◆ ToggleWhenActive() [1/2]

Trigger frc2::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.

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.

◆ ToggleWhenActive() [2/2]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger frc2::Trigger::ToggleWhenActive ( T &&  command,
bool  interruptible = true 
)
inline

Binds a command to start when the trigger becomes active, and be cancelled 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.

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

◆ WhenActive() [1/4]

Trigger frc2::Trigger::WhenActive ( Command command,
bool  interruptible = true 
)

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.

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

◆ WhenActive() [2/4]

Trigger frc2::Trigger::WhenActive ( std::function< void()>  toRun,
std::initializer_list< Subsystem * >  requirements 
)

Binds a runnable to execute when the trigger becomes active.

Parameters
toRunthe runnable to execute. @paaram requirements the required subsystems.

◆ WhenActive() [3/4]

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

Binds a runnable to execute when the trigger becomes active.

Parameters
toRunthe runnable to execute. @paaram requirements the required subsystems.

◆ WhenActive() [4/4]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger frc2::Trigger::WhenActive ( T &&  command,
bool  interruptible = true 
)
inline

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.

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

◆ WhenInactive() [1/4]

Trigger frc2::Trigger::WhenInactive ( Command command,
bool  interruptible = true 
)

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.

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

◆ WhenInactive() [2/4]

Trigger frc2::Trigger::WhenInactive ( std::function< void()>  toRun,
std::initializer_list< Subsystem * >  requirements 
)

Binds a runnable to execute when the trigger becomes inactive.

Parameters
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ WhenInactive() [3/4]

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

Binds a runnable to execute when the trigger becomes inactive.

Parameters
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ WhenInactive() [4/4]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger frc2::Trigger::WhenInactive ( T &&  command,
bool  interruptible = true 
)
inline

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.

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

◆ WhileActiveContinous() [1/4]

Trigger frc2::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.

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.

◆ WhileActiveContinous() [2/4]

Trigger frc2::Trigger::WhileActiveContinous ( std::function< void()>  toRun,
std::initializer_list< Subsystem * >  requirements 
)

Binds a runnable to execute repeatedly while the trigger is active.

Parameters
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ WhileActiveContinous() [3/4]

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

Binds a runnable to execute repeatedly while the trigger is active.

Parameters
toRunthe runnable to execute.
requirementsthe required subsystems.

◆ WhileActiveContinous() [4/4]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger frc2::Trigger::WhileActiveContinous ( T &&  command,
bool  interruptible = true 
)
inline

Binds a command to be started repeatedly while the trigger is active, and cancelled 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.

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

◆ WhileActiveOnce() [1/2]

Trigger frc2::Trigger::WhileActiveOnce ( Command command,
bool  interruptible = true 
)

Binds a command to be started when the trigger becomes active, and cancelled when it becomes inactive.

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.

◆ WhileActiveOnce() [2/2]

template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>>
Trigger frc2::Trigger::WhileActiveOnce ( T &&  command,
bool  interruptible = true 
)
inline

Binds a command to be started when the trigger becomes active, and cancelled 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.

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

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