Package com.diozero.api
Class WaitableDigitalInputDevice
- java.lang.Object
-
- com.diozero.api.GpioDevice
-
- com.diozero.api.GpioInputDevice<DigitalInputEvent>
-
- com.diozero.api.AbstractDigitalInputDevice
-
- com.diozero.api.DigitalInputDevice
-
- com.diozero.api.WaitableDigitalInputDevice
-
- All Implemented Interfaces:
DeviceInterface
,DigitalInputDeviceInterface
,DeviceEventConsumer<DigitalInputEvent>
,Closeable
,AutoCloseable
,Consumer<DigitalInputEvent>
- Direct Known Subclasses:
DebouncedDigitalInputDevice
,SmoothedInputDevice
public class WaitableDigitalInputDevice extends DigitalInputDevice
Represents a digital input device with distinct waitable states (active / inactive).
-
-
Field Summary
-
Fields inherited from class com.diozero.api.DigitalInputDevice
device
-
Fields inherited from class com.diozero.api.AbstractDigitalInputDevice
activeHigh
-
Fields inherited from class com.diozero.api.GpioDevice
gpio
-
-
Constructor Summary
Constructors Constructor Description WaitableDigitalInputDevice(int gpio)
WaitableDigitalInputDevice(int gpio, GpioPullUpDown pud, GpioEventTrigger trigger)
WaitableDigitalInputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio, GpioPullUpDown pud, GpioEventTrigger trigger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(DigitalInputEvent event)
protected void
disableDeviceListener()
boolean
waitForActive()
Wait indefinitely for the device state to go active.boolean
waitForActive(int timeout)
Wait the specified time period for the device state to go active.boolean
waitForInactive()
Wait indefinitely for the device state to go inactive.boolean
waitForInactive(int timeout)
Wait the specified time period for the device state to go inactive.boolean
waitForValue(boolean value, int timeout)
Wait the specified time period for the device state to switch to value.-
Methods inherited from class com.diozero.api.DigitalInputDevice
close, getPullUpDown, getTrigger, getValue, isActive, removeListener, setListener
-
Methods inherited from class com.diozero.api.AbstractDigitalInputDevice
enableDeviceListener, isActiveHigh, whenActivated, whenDeactivated
-
Methods inherited from class com.diozero.api.GpioInputDevice
addListener, removeAllListeners, removeListener
-
Methods inherited from class com.diozero.api.GpioDevice
getGpio
-
-
-
-
Constructor Detail
-
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 Detail
-
disableDeviceListener
protected void disableDeviceListener()
- Overrides:
disableDeviceListener
in classAbstractDigitalInputDevice
-
accept
public void accept(DigitalInputEvent event)
- Specified by:
accept
in interfaceConsumer<DigitalInputEvent>
- Overrides:
accept
in classAbstractDigitalInputDevice
-
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.-
-
-