Package edu.wpi.first.wpilibj.event
Class BooleanEvent
java.lang.Object
edu.wpi.first.wpilibj.event.BooleanEvent
- All Implemented Interfaces:
BooleanSupplier
- Direct Known Subclasses:
NetworkBooleanEvent
public class BooleanEvent extends Object implements BooleanSupplier
This class provides an easy way to link actions to high-active logic signals. Each object
represents a digital signal to which callback actions can be bound using
ifHigh(Runnable)
.
These signals can easily be composed for advanced functionality using and(BooleanSupplier)
, or(BooleanSupplier)
, negate()
etc.
To get an event that activates only when this one changes, see falling()
and rising()
.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BooleanEvent(EventLoop loop, BooleanSupplier signal)
Creates a new event with the given signal determining whether it is active. -
Method Summary
Modifier and Type Method Description BooleanEvent
and(BooleanSupplier other)
Composes this event with another event, returning a new signal that is in the high state when both signals are in the high state.<T extends BooleanSupplier>
TcastTo(BiFunction<EventLoop,BooleanSupplier,T> ctor)
A method to "downcast" a BooleanEvent instance to a subclass (for example, to a command-based version of this class).BooleanEvent
debounce(double seconds)
Creates a new debounced event from this event - it will become active when this event has been active for longer than the specified period.BooleanEvent
debounce(double seconds, Debouncer.DebounceType type)
Creates a new debounced event from this event - it will become active when this event has been active for longer than the specified period.BooleanEvent
falling()
Get a new event that triggers only when this one newly changes to false.boolean
getAsBoolean()
Check the state of this signal (high or low).void
ifHigh(Runnable action)
Bind an action to this event.BooleanEvent
negate()
Creates a new event that is active when this event is inactive, i.e.BooleanEvent
or(BooleanSupplier other)
Composes this event with another event, returning a new signal that is high when either signal is high.BooleanEvent
rising()
Get a new event that events only when this one newly changes to true.
-
Field Details
-
m_loop
Poller loop.
-
-
Constructor Details
-
BooleanEvent
Creates a new event with the given signal determining whether it is active.- Parameters:
loop
- the loop that polls this eventsignal
- the digital signal represented by this object.
-
-
Method Details
-
getAsBoolean
Check the state of this signal (high or low).- Specified by:
getAsBoolean
in interfaceBooleanSupplier
- Returns:
- true for the high state, false for the low state.
-
ifHigh
Bind an action to this event.- Parameters:
action
- the action to run if this event is active.
-
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.
-
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.
-
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:
seconds
- The debounce period.- Returns:
- The debounced event (rising edges debounced only)
-
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:
seconds
- The debounce period.type
- The debounce type.- Returns:
- The debounced event.
-
negate
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
-
and
Composes this event with another event, returning a new signal that is in the high state when both signals are in the high state.The new event will use this event's polling loop.
- Parameters:
other
- the event to compose with- Returns:
- the event that is active when both events are active
-
or
Composes this event with another event, returning a new signal that is high when either signal is high.The new event will use this event's polling loop.
- Parameters:
other
- the event to compose with- Returns:
- a signal that is high when either signal is high.
-
castTo
A method to "downcast" a BooleanEvent instance to a subclass (for example, to a command-based version of this class).- Type Parameters:
T
- the subclass type- 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.
-