Package com.diozero.api
Class DigitalInputDevice
java.lang.Object
com.diozero.api.GpioDevice
com.diozero.api.GpioInputDevice<DigitalInputEvent>
com.diozero.api.AbstractDigitalInputDevice
com.diozero.api.DigitalInputDevice
- All Implemented Interfaces:
DigitalInputDeviceInterface
,DeviceEventConsumer<DigitalInputEvent>
,Closeable
,AutoCloseable
,Consumer<DigitalInputEvent>
- Direct Known Subclasses:
Button
,WaitableDigitalInputDevice
public class DigitalInputDevice extends AbstractDigitalInputDevice
Represents a generic digital input device.
-
Field Summary
Fields Modifier and Type Field Description protected GpioDigitalInputDeviceInterface
device
Fields inherited from class com.diozero.api.AbstractDigitalInputDevice
activeHigh
Fields inherited from class com.diozero.api.GpioDevice
gpio
-
Constructor Summary
Constructors Constructor Description DigitalInputDevice(int gpio)
DigitalInputDevice(int gpio, GpioPullUpDown pud, GpioEventTrigger trigger)
DigitalInputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio, GpioPullUpDown pud, GpioEventTrigger trigger)
DigitalInputDevice(GpioDeviceFactoryInterface deviceFactory, PinInfo pinInfo, GpioPullUpDown pud, GpioEventTrigger trigger)
-
Method Summary
Modifier and Type Method Description void
close()
GpioPullUpDown
getPullUpDown()
Get pull up / down configuration.GpioEventTrigger
getTrigger()
Get event trigger configuration.boolean
getValue()
Read the current underlying state of the input pin.boolean
isActive()
Read the current on/off state for this device taking into account the pull up / down configuration.protected void
removeListener()
protected void
setListener()
Methods inherited from class com.diozero.api.AbstractDigitalInputDevice
accept, disableDeviceListener, enableDeviceListener, isActiveHigh, whenActivated, whenDeactivated
Methods inherited from class com.diozero.api.GpioInputDevice
addListener, removeAllListeners, removeListener
Methods inherited from class com.diozero.api.GpioDevice
getGpio
-
Field Details
-
device
-
-
Constructor Details
-
DigitalInputDevice
- Parameters:
gpio
- GPIO to which the device is connected.- Throws:
RuntimeIOException
- If an I/O error occurs.
-
DigitalInputDevice
public DigitalInputDevice(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 occurs.
-
DigitalInputDevice
public DigitalInputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException- Parameters:
deviceFactory
- Device factory to use to provision this digital input 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 occurs.
-
DigitalInputDevice
public DigitalInputDevice(GpioDeviceFactoryInterface deviceFactory, PinInfo pinInfo, GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException- Parameters:
deviceFactory
- Device factory to use to provision this digital input device.pinInfo
- Information about the GPIO pin 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 occurs.
-
-
Method Details
-
close
public void close() -
getPullUpDown
Get pull up / down configuration.- Returns:
- Pull up / down configuration.
-
getTrigger
Get event trigger configuration.- Returns:
- Event trigger configuration.
-
getValue
Read the current underlying state of the input pin. Does not factor in active high logic.- Returns:
- Device state.
- Throws:
RuntimeIOException
- If an I/O error occurred.
-
isActive
Read the current on/off state for this device taking into account the pull up / down configuration. If the input is pulled upisActive()
will returntrue
when when the value isfalse
.- Returns:
- Device active state.
- Throws:
RuntimeIOException
- If an I/O error occurred.
-
setListener
protected void setListener()- Specified by:
setListener
in classAbstractDigitalInputDevice
-
removeListener
protected void removeListener()- Specified by:
removeListener
in classAbstractDigitalInputDevice
-