Package com.diozero.api
Class AbstractDigitalInputDevice
- All Implemented Interfaces:
DeviceInterface
,DigitalInputDeviceInterface
,DeviceEventConsumer<DigitalInputEvent>
,AutoCloseable
,Consumer<DigitalInputEvent>
- Direct Known Subclasses:
DigitalInputDevice
,DigitalInputOutputDevice
public abstract class AbstractDigitalInputDevice extends GpioInputDevice<DigitalInputEvent> implements DigitalInputDeviceInterface
Abstract base class for low-level GPIO digital input devices.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
activeHigh
Fields inherited from class com.diozero.api.GpioDevice
pinInfo
-
Constructor Summary
Constructors Constructor Description AbstractDigitalInputDevice(PinInfo pinInfo, boolean activeHigh)
-
Method Summary
Modifier and Type Method Description void
accept(DigitalInputEvent event)
protected void
disableDeviceListener()
protected void
enableDeviceListener()
boolean
isActiveHigh()
Get active high configuration.protected abstract void
removeListener()
protected abstract void
setListener()
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 the specified value, not taking into account active high / low logic.void
whenActivated(LongConsumer consumer)
Action to perform when the device state is active.void
whenDeactivated(LongConsumer consumer)
Action to perform when the device state is inactive.Methods inherited from class com.diozero.api.GpioInputDevice
addListener, hasListeners, removeAllListeners, removeListener
Methods inherited from class com.diozero.api.GpioDevice
getGpio
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.diozero.api.DeviceInterface
close
Methods inherited from interface com.diozero.api.DigitalInputDeviceInterface
getValue
-
Field Details
-
activeHigh
protected boolean activeHigh
-
-
Constructor Details
-
AbstractDigitalInputDevice
-
-
Method Details
-
isActiveHigh
public boolean isActiveHigh()Get active high configuration.- Returns:
- Returns false if configured as pull-up, true for all other pull up / down options.
-
enableDeviceListener
protected void enableDeviceListener()- Specified by:
enableDeviceListener
in classGpioInputDevice<DigitalInputEvent>
-
disableDeviceListener
protected void disableDeviceListener()- Specified by:
disableDeviceListener
in classGpioInputDevice<DigitalInputEvent>
-
accept
- Specified by:
accept
in interfaceConsumer<DigitalInputEvent>
- Overrides:
accept
in classGpioInputDevice<DigitalInputEvent>
-
whenActivated
Action to perform when the device state is active.- Parameters:
consumer
- Callback object to be invoked when activated (long parameter is nanoseconds time).
-
whenDeactivated
Action to perform when the device state is inactive.- Parameters:
consumer
- Callback object to be invoked when activated (long parameter is nanoseconds time)
-
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 the specified value, not taking into account active high / low logic.- 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.
-
setListener
protected abstract void setListener() -
removeListener
protected abstract void removeListener()
-