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:
DigitalInputDeviceInterface
,InputEventListener<DigitalInputEvent>
,java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
DebouncedDigitalInputDevice
,SmoothedInputDevice
public class WaitableDigitalInputDevice extends DigitalInputDevice
Represents a digital input device with distinct waitable states (active / inactive).
-
Field Summary
-
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
Modifier and Type Method Description protected void
disableDeviceListener()
void
valueChanged(DigitalInputEvent event)
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
-
Constructor Details
-
WaitableDigitalInputDevice
- 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 classAbstractDigitalInputDevice
-
valueChanged
- Specified by:
valueChanged
in interfaceInputEventListener<DigitalInputEvent>
- Overrides:
valueChanged
in classAbstractDigitalInputDevice
-
waitForActive
public boolean waitForActive() throws java.lang.InterruptedExceptionWait indefinitely for the device state to go active.- Returns:
- False if timed out waiting for the specified value, otherwise true.
- Throws:
java.lang.InterruptedException
- If interrupted while waiting.-
-
waitForActive
public boolean waitForActive(int timeout) throws java.lang.InterruptedExceptionWait 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:
java.lang.InterruptedException
- If interrupted while waiting.-
-
waitForInactive
public boolean waitForInactive() throws java.lang.InterruptedExceptionWait indefinitely for the device state to go inactive.- Returns:
- False if timed out waiting for the specified value, otherwise true.
- Throws:
java.lang.InterruptedException
- If interrupted while waiting.-
-
waitForInactive
public boolean waitForInactive(int timeout) throws java.lang.InterruptedExceptionWait 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:
java.lang.InterruptedException
- If interrupted while waiting.-
-
waitForValue
public boolean waitForValue(boolean value, int timeout) throws java.lang.InterruptedExceptionWait 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:
java.lang.InterruptedException
- If interrupted while waiting.-
-