Class DigitalEventListener<V>

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

    Fields
    Modifier and Type
    Field
    Description
    protected final com.pi4j.io.gpio.digital.DigitalInput
    Pi4J digital input to which this digital event listener has been attached
    protected final EventHandler<V>
    Handler function which gets called
    protected final Function<com.pi4j.io.gpio.digital.DigitalState,V>
    Mapper function which transforms DigitalState into DigitalEventListener
  • Constructor Summary

    Constructors
    Constructor
    Description
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onDigitalStateChange(com.pi4j.io.gpio.digital.DigitalStateChangeEvent event)
    Handles incoming Pi4J events by calling our own handler with the mapped value from mapper.
    void
    Removes this digital event listener, therefore preventing any future execution.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • digitalInput

      protected final com.pi4j.io.gpio.digital.DigitalInput digitalInput
      Pi4J digital input to which this digital event listener has been attached
    • mapper

      protected final Function<com.pi4j.io.gpio.digital.DigitalState,V> mapper
      Mapper function which transforms DigitalState into DigitalEventListener
    • handler

      protected final EventHandler<V> 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 a DigitalStateChangeListener for the passed DigitalInput.
      Parameters:
      digitalInput - Digital input where event listener gets attached
      mapper - Mapping function from DigitalState to target type DigitalEventListener
      handler - Handler function which gets called
  • Method Details

    • onDigitalStateChange

      public void onDigitalStateChange(com.pi4j.io.gpio.digital.DigitalStateChangeEvent event)
      Handles incoming Pi4J events by calling our own handler with the mapped value from mapper.
      Specified by:
      onDigitalStateChange in interface com.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 interface EventListener