WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
frc::BooleanEvent Class Reference

This class provides an easy way to link actions to active high logic signals. More...

#include <frc/event/BooleanEvent.h>

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

Public Member Functions

 BooleanEvent (EventLoop *loop, std::function< bool()> signal)
 Creates a new event that is active when the condition is true.
 
bool GetAsBoolean () const
 Returns the state of this signal (high or low) as of the last loop poll.
 
 operator std::function< bool ()>()
 
void IfHigh (std::function< void()> action)
 Bind an action to this event.
 
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).
 
BooleanEvent operator! ()
 Creates a new event that is active when this event is inactive.
 
BooleanEvent operator&& (std::function< bool()> rhs)
 Composes this event with another event, returning a new event that is active when both events are active.
 
BooleanEvent operator|| (std::function< bool()> rhs)
 Composes this event with another event, returning a new event that is active when either event is active.
 
BooleanEvent Rising ()
 Creates a new event that triggers when this one changes from false to true.
 
BooleanEvent Falling ()
 Creates a new event that triggers when this one changes from true to false.
 
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.
 

Detailed Description

This class provides an easy way to link actions to active high logic signals.

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

BooleanEvents can easily be composed for advanced functionality using operator&&, operator||, and operator!.

To get a new BooleanEvent that triggers when this one changes see Falling() and Rising().

Constructor & Destructor Documentation

◆ BooleanEvent()

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

Creates a new event that is active when the condition is true.

Parameters
loopthe loop that polls this event
signalthe digital signal represented by this object.

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 ( )

Creates a new event that triggers when this one changes from true to false.

Returns
the event.

◆ GetAsBoolean()

bool frc::BooleanEvent::GetAsBoolean ( ) const

Returns the state of this signal (high or low) as of the last loop poll.

Returns
true for the high state, false for the low state. 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.

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 ( )

Creates a new event that triggers when this one changes from false to true.

Returns
the new event.

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