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>
,AutoCloseable
,Consumer<DigitalInputEvent>
- Direct Known Subclasses:
DebouncedDigitalInputDevice
,SmoothedInputDevice
public class WaitableDigitalInputDevice extends DigitalInputDevice
Represents a digital input device with distinct waitable states (active / inactive).
-
Nested Class Summary
Nested classes/interfaces inherited from class com.diozero.api.DigitalInputDevice
DigitalInputDevice.Builder
-
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
pinInfo
-
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 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
builder, builder, 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 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
-
accept
- Specified by:
accept
in interfaceConsumer<DigitalInputEvent>
- Overrides:
accept
in classAbstractDigitalInputDevice
-
waitForActive
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
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
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
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
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.-
-