Class WaitableDigitalInputDevice

All Implemented Interfaces:
DeviceInterface, DigitalInputDeviceInterface, DeviceEventConsumer<DigitalInputEvent>, AutoCloseable, Consumer<DigitalInputEvent>
Direct Known Subclasses:
DebouncedDigitalInputDevice, SmoothedInputDevice

public class WaitableDigitalInputDevice
extends DigitalInputDevice
Represents a digital input device with distinct waitable states (active / inactive).
  • Constructor Details

    • WaitableDigitalInputDevice

      public WaitableDigitalInputDevice​(int gpio) throws RuntimeIOException
      Parameters:
      gpio - GPIO to which the device is connected.
      Throws:
      RuntimeIOException - If an I/O error occurred.
    • WaitableDigitalInputDevice

      public WaitableDigitalInputDevice​(int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException
      Parameters:
      gpio - GPIO to which the device is connected.
      pud - Pull up/down configuration, values: NONE, PULL_UP, PULL_DOWN.
      trigger - Event trigger configuration, values: NONE, RISING, FALLING, BOTH.
      Throws:
      RuntimeIOException - If an I/O error occurred.
    • WaitableDigitalInputDevice

      public WaitableDigitalInputDevice​(GpioDeviceFactoryInterface deviceFactory, int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException
      Parameters:
      deviceFactory - Device factory to use to construct the device.
      gpio - GPIO to which the device is connected.
      pud - Pull up/down configuration, values: NONE, PULL_UP, PULL_DOWN.
      trigger - Event trigger configuration, values: NONE, RISING, FALLING, BOTH.
      Throws:
      RuntimeIOException - If an I/O error occurred.
  • Method Details

    • disableDeviceListener

      protected void disableDeviceListener()
      Overrides:
      disableDeviceListener in class AbstractDigitalInputDevice
    • accept

      public void accept​(DigitalInputEvent event)
      Specified by:
      accept in interface Consumer<DigitalInputEvent>
      Overrides:
      accept in class AbstractDigitalInputDevice
    • waitForActive

      public boolean waitForActive() throws InterruptedException
      Wait indefinitely for the device state to go active.
      Returns:
      False if timed out waiting for the specified value, otherwise true.
      Throws:
      InterruptedException - If interrupted while waiting.-
    • waitForActive

      public boolean waitForActive​(int timeout) throws InterruptedException
      Wait the specified time period for the device state to go active.
      Parameters:
      timeout - Timeout value if milliseconds, <= 0 is indefinite.
      Returns:
      False if timed out waiting for the specified value, otherwise true.
      Throws:
      InterruptedException - If interrupted while waiting.-
    • waitForInactive

      public boolean waitForInactive() throws InterruptedException
      Wait indefinitely for the device state to go inactive.
      Returns:
      False if timed out waiting for the specified value, otherwise true.
      Throws:
      InterruptedException - If interrupted while waiting.-
    • waitForInactive

      public boolean waitForInactive​(int timeout) throws InterruptedException
      Wait the specified time period for the device state to go inactive.
      Parameters:
      timeout - Timeout value if milliseconds, <= 0 is indefinite.
      Returns:
      False if timed out waiting for the specified value, otherwise true.
      Throws:
      InterruptedException - If interrupted while waiting.-
    • waitForValue

      public boolean waitForValue​(boolean value, int timeout) throws InterruptedException
      Wait the specified time period for the device state to switch to value.
      Parameters:
      value - The desired device state to wait for.
      timeout - Timeout value if milliseconds, <= 0 is indefinite.
      Returns:
      False if timed out waiting for the specified value, otherwise true.
      Throws:
      InterruptedException - If interrupted while waiting.-