Interface DigitalEventProvider<V>

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 Details

    • getDigitalInput

      com.pi4j.io.gpio.digital.DigitalInput getDigitalInput()
      Returns the Pi4J DigitalInput associated with this component.
      Returns:
      Pi4J DigitalInput instance
    • mapDigitalState

      V mapDigitalState(com.pi4j.io.gpio.digital.DigitalState digitalState)
      Maps the Pi4J DigitalState to the target type DigitalEventProvider.
      Parameters:
      digitalState - Pi4J digital state to map
      Returns:
      Mapped component state
    • addListener

      default DigitalEventListener<V> addListener(EventHandler<V> handler)
      Adds a new event listener to this component.
      Specified by:
      addListener in interface EventProvider<DigitalEventListener<V>,V>
      Parameters:
      handler - Event handler to call
      Returns:
      Event listener instance
    • removeListener

      default void removeListener(DigitalEventListener<V> listener)
      Removes an existing event listener from this component.
      Specified by:
      removeListener in interface EventProvider<DigitalEventListener<V>,V>
      Parameters:
      listener - Event listener to remove