This class provides an easy way to link actions to active high logic signals.
More...
#include <frc/event/BooleanEvent.h>
|
| 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 > |
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.
|
|
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()
.
◆ BooleanEvent()
frc::BooleanEvent::BooleanEvent |
( |
EventLoop * | loop, |
|
|
std::function< bool()> | signal ) |
Creates a new event that is active when the condition is true.
- Parameters
-
loop | the loop that polls this event |
signal | the digital signal represented by this object. |
◆ 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
-
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. |
- Returns
- an instance of the subclass.
◆ Debounce()
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
-
debounceTime | The debounce period. |
type | The debounce type. |
- Returns
- The debounced event.
◆ 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
-
action | the action to run if this event is active. |
◆ operator std::function< bool()
frc::BooleanEvent::operator std::function< bool |
( |
| ) |
|
◆ 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
-
rhs | the 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
-
rhs | the event to compose with |
- Returns
- the event that is active when either event is active
◆ 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: