java.lang.Object
com.pi4j.crowpi.components.events.DigitalEventListener<V>
- Type Parameters:
V
- Target type of event value which gets passed to event handler.
- All Implemented Interfaces:
EventListener
,com.pi4j.event.Listener
,com.pi4j.io.gpio.digital.DigitalListener<com.pi4j.io.gpio.digital.DigitalStateChangeEvent>
,com.pi4j.io.gpio.digital.DigitalStateChangeListener
public class DigitalEventListener<V>
extends Object
implements EventListener, com.pi4j.io.gpio.digital.DigitalStateChangeListener
Generic implementation of
EventListener
for Pi4J DigitalInput
instances.
Can be registered as a DigitalStateChangeListener
within Pi4J.
Whenever a Pi4J DigitalStateChangeEvent
occurs, the provided DigitalState
gets converted into the target type DigitalEventListener
by calling the provided mapper
function. This mapped value then gets passed to the provided EventHandler
to actually
handle the event with the function provided by the user.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final com.pi4j.io.gpio.digital.DigitalInput
Pi4J digital input to which this digital event listener has been attachedprotected final EventHandler<V>
Handler function which gets calledMapper function which transformsDigitalState
intoDigitalEventListener
-
Constructor Summary
ConstructorDescriptionDigitalEventListener
(com.pi4j.io.gpio.digital.DigitalInput digitalInput, Function<com.pi4j.io.gpio.digital.DigitalState, V> mapper, EventHandler<V> handler) Creates a new digital event listener for the given digital input which uses the provided mapper and event handler. -
Method Summary
Modifier and TypeMethodDescriptionvoid
onDigitalStateChange
(com.pi4j.io.gpio.digital.DigitalStateChangeEvent event) void
remove()
Removes this digital event listener, therefore preventing any future execution.
-
Field Details
-
digitalInput
protected final com.pi4j.io.gpio.digital.DigitalInput digitalInputPi4J digital input to which this digital event listener has been attached -
mapper
Mapper function which transformsDigitalState
intoDigitalEventListener
-
handler
Handler function which gets called
-
-
Constructor Details
-
DigitalEventListener
public DigitalEventListener(com.pi4j.io.gpio.digital.DigitalInput digitalInput, Function<com.pi4j.io.gpio.digital.DigitalState, V> mapper, EventHandler<V> handler) Creates a new digital event listener for the given digital input which uses the provided mapper and event handler. This class instance gets automatically registered as aDigitalStateChangeListener
for the passedDigitalInput
.- Parameters:
digitalInput
- Digital input where event listener gets attachedmapper
- Mapping function fromDigitalState
to target typeDigitalEventListener
handler
- Handler function which gets called
-
-
Method Details
-
onDigitalStateChange
public void onDigitalStateChange(com.pi4j.io.gpio.digital.DigitalStateChangeEvent event) - Specified by:
onDigitalStateChange
in interfacecom.pi4j.io.gpio.digital.DigitalStateChangeListener
- Parameters:
event
- Pi4J event
-
remove
public void remove()Removes this digital event listener, therefore preventing any future execution.- Specified by:
remove
in interfaceEventListener
-