- Type Parameters:
V
- Type of value which gets passed to event handlers.
- All Superinterfaces:
EventProvider<DigitalEventListener<V>,
,V> SimpleEventProvider<V>
- All Known Implementing Classes:
ButtonComponent
,PirMotionSensorComponent
,SoundSensorComponent
,TiltSensorComponent
,TouchSensorComponent
public interface DigitalEventProvider<V>
extends EventProvider<DigitalEventListener<V>,V>, SimpleEventProvider<V>
Generic digital event provider with default implementation for digital components.
Implementing this interface in a component class provides the user with the ability to add and remove event listeners.
Transformation of raw DigitalState
into target type DigitalEventProvider
is made by mapDigitalState(DigitalState)
.
The method getDigitalInput()
must return the DigitalInput
instance where the listener should be added.
-
Method Summary
Modifier and TypeMethodDescriptiondefault DigitalEventListener<V>
addListener
(EventHandler<V> handler) Adds a new event listener to this component.com.pi4j.io.gpio.digital.DigitalInput
Returns the Pi4JDigitalInput
associated with this component.mapDigitalState
(com.pi4j.io.gpio.digital.DigitalState digitalState) Maps the Pi4JDigitalState
to the target typeDigitalEventProvider
.default void
removeListener
(DigitalEventListener<V> listener) Removes an existing event listener from this component.Methods inherited from interface com.pi4j.crowpi.components.events.SimpleEventProvider
dispatchSimpleEvents
-
Method Details
-
getDigitalInput
com.pi4j.io.gpio.digital.DigitalInput getDigitalInput()Returns the Pi4JDigitalInput
associated with this component.- Returns:
- Pi4J
DigitalInput
instance
-
mapDigitalState
Maps the Pi4JDigitalState
to the target typeDigitalEventProvider
.- Parameters:
digitalState
- Pi4J digital state to map- Returns:
- Mapped component state
-
addListener
Adds a new event listener to this component.- Specified by:
addListener
in interfaceEventProvider<DigitalEventListener<V>,
V> - Parameters:
handler
- Event handler to call- Returns:
- Event listener instance
-
removeListener
Removes an existing event listener from this component.- Specified by:
removeListener
in interfaceEventProvider<DigitalEventListener<V>,
V> - Parameters:
listener
- Event listener to remove
-