WPILibC++ 2023.4.3
|
This class provides an easy way to link actions to inputs. More...
#include <frc/event/BooleanEvent.h>
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. More... | |
void | IfHigh (std::function< void()> action) |
Bind an action to this event. More... | |
operator std::function< bool ()>() | |
template<class T > | |
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... | |
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()
.
frc::BooleanEvent::BooleanEvent | ( | EventLoop * | loop, |
std::function< bool()> | condition | ||
) |
Creates a new event with the given condition determining whether it is active.
loop | the loop that polls this event |
condition | returns whether or not the event should be active |
|
inline |
A method to "downcast" a BooleanEvent instance to a subclass (for example, to a command-based version of this class).
ctor | a method reference to the constructor of the subclass that accepts the loop as the first parameter and the condition/signal as the second. |
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.
debounceTime | The debounce period. |
type | The debounce type. |
BooleanEvent frc::BooleanEvent::Falling | ( | ) |
Get a new event that triggers only when this one newly changes to false.
bool frc::BooleanEvent::GetAsBoolean | ( | ) | const |
Check whether this event is active or not.
void frc::BooleanEvent::IfHigh | ( | std::function< void()> | action | ) |
Bind an action to this event.
action | the action to run if this event is active. |
frc::BooleanEvent::operator std::function< bool | ( | ) |
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.
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 new event will use this event's polling loop.
rhs | the event to compose with |
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 new event will use this event's polling loop.
rhs | the event to compose with |
BooleanEvent frc::BooleanEvent::Rising | ( | ) |
Get a new event that events only when this one newly changes to true.