WPILibC++ 2024.3.2
frc::BooleanEvent Class Reference

This class provides an easy way to link actions to inputs. More...

#include <frc/event/BooleanEvent.h>

Inheritance diagram for frc::BooleanEvent:
frc::NetworkBooleanEvent

Public Member Functions

 BooleanEvent (EventLoop *loop, std::function< bool()> condition)
 Creates a new event with the given condition determining whether it is active. More...
 
bool GetAsBoolean () const
 Check whether this event is active or not as of the last loop poll. More...
 
void IfHigh (std::function< void()> action)
 Bind an action to this event. More...
 
 operator std::function< bool ()>()
 
template<class T >
CastTo (std::function< T(EventLoop *, std::function< bool()>)> ctor=[](EventLoop *loop, std::function< bool()> condition) { return T(loop, condition);})
 A method to "downcast" a BooleanEvent instance to a subclass (for example, to a command-based version of this class). More...
 
BooleanEvent operator! ()
 Creates a new event that is active when this event is inactive, i.e. More...
 
BooleanEvent operator&& (std::function< bool()> rhs)
 Composes this event with another event, returning a new event that is active when both events are active. More...
 
BooleanEvent operator|| (std::function< bool()> rhs)
 Composes this event with another event, returning a new event that is active when either event is active. More...
 
BooleanEvent Rising ()
 Get a new event that events only when this one newly changes to true. More...
 
BooleanEvent Falling ()
 Get a new event that triggers only when this one newly changes to false. More...
 
BooleanEvent Debounce (units::second_t debounceTime, frc::Debouncer::DebounceType type=frc::Debouncer::DebounceType::kRising)
 Creates a new debounced event from this event - it will become active when this event has been active for longer than the specified period. More...
 

Detailed Description

This class provides an easy way to link actions to inputs.

Each object represents a boolean condition to which callback actions can be bound using IfHigh(std::function<void()>).

These events can easily be composed using factories such as operator!, operator||, operator&& etc.

To get an event that activates only when this one changes, see Falling() and Rising().

Constructor & Destructor Documentation

◆ BooleanEvent()

frc::BooleanEvent::BooleanEvent ( EventLoop loop,
std::function< bool()>  condition 
)

Creates a new event with the given condition determining whether it is active.

Parameters
loopthe loop that polls this event
conditionreturns whether or not the event should be active

Member Function Documentation

◆ CastTo()

template<class T >
T frc::BooleanEvent::CastTo ( std::function< T(EventLoop *, std::function< bool()>)>  ctor = [](EventLoop* loop, std::function<bool()> condition) { return T(loop, condition); })
inline

A method to "downcast" a BooleanEvent instance to a subclass (for example, to a command-based version of this class).

Parameters
ctora method reference to the constructor of the subclass that accepts the loop as the first parameter and the condition/signal as the second.
Returns
an instance of the subclass.

◆ Debounce()

BooleanEvent frc::BooleanEvent::Debounce ( units::second_t  debounceTime,
frc::Debouncer::DebounceType  type = frc::Debouncer::DebounceType::kRising 
)

Creates a new debounced event from this event - it will become active when this event has been active for longer than the specified period.

Parameters
debounceTimeThe debounce period.
typeThe debounce type.
Returns
The debounced event.

◆ Falling()

BooleanEvent frc::BooleanEvent::Falling ( )

Get a new event that triggers only when this one newly changes to false.

Returns
a new event representing when this one newly changes to false.

◆ GetAsBoolean()

bool frc::BooleanEvent::GetAsBoolean ( ) const

Check whether this event is active or not as of the last loop poll.

Returns
true if active, false if not active. If the event was never polled, it returns the state at event construction.

◆ IfHigh()

void frc::BooleanEvent::IfHigh ( std::function< void()>  action)

Bind an action to this event.

Parameters
actionthe action to run if this event is active.

◆ operator std::function< bool()

frc::BooleanEvent::operator std::function< bool ( )

◆ operator!()

BooleanEvent frc::BooleanEvent::operator! ( )

Creates a new event that is active when this event is inactive, i.e.

that acts as the negation of this event.

Returns
the negated event

◆ operator&&()

BooleanEvent frc::BooleanEvent::operator&& ( std::function< bool()>  rhs)

Composes this event with another event, returning a new event that is active when both events are active.

The events must use the same event loop. If the events use different event loops, the composed signal won't update until both loops are polled.

Parameters
rhsthe event to compose with
Returns
the event that is active when both events are active

◆ operator||()

BooleanEvent frc::BooleanEvent::operator|| ( std::function< bool()>  rhs)

Composes this event with another event, returning a new event that is active when either event is active.

The events must use the same event loop. If the events use different event loops, the composed signal won't update until both loops are polled.

Parameters
rhsthe event to compose with
Returns
the event that is active when either event is active

◆ Rising()

BooleanEvent frc::BooleanEvent::Rising ( )

Get a new event that events only when this one newly changes to true.

Returns
a new event representing when this one newly changes to true.

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