java.lang.Object
com.diozero.api.GpioDevice
com.diozero.api.GpioInputDevice<DigitalInputEvent>
com.diozero.api.AbstractDigitalInputDevice
com.diozero.api.DigitalInputDevice
- All Implemented Interfaces:
DeviceInterface
,DigitalInputDeviceInterface
,DeviceEventConsumer<DigitalInputEvent>
,AutoCloseable
,Consumer<DigitalInputEvent>
- Direct Known Subclasses:
Button
,DebouncedDigitalInputDevice
,SmoothedInputDevice
Represents a generic digital input device.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Digital input device builder. -
Field Summary
Fields inherited from class com.diozero.api.AbstractDigitalInputDevice
activeHigh
Fields inherited from class com.diozero.api.GpioDevice
pinInfo
-
Constructor Summary
ConstructorDescriptionDigitalInputDevice
(int gpio) DigitalInputDevice
(int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) DigitalInputDevice
(GpioDeviceFactoryInterface deviceFactory, int gpio) Defaults to "active high".DigitalInputDevice
(GpioDeviceFactoryInterface deviceFactory, int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) DigitalInputDevice
(GpioDeviceFactoryInterface deviceFactory, PinInfo pinInfo, GpioPullUpDown pud, GpioEventTrigger trigger, boolean activeHigh) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this devicegetName()
Get pull up / down configuration.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
protected void
Methods inherited from class com.diozero.api.AbstractDigitalInputDevice
accept, disableDeviceListener, enableDeviceListener, isActiveHigh, waitForActive, waitForActive, waitForInactive, waitForInactive, waitForValue, whenActivated, whenDeactivated
Methods inherited from class com.diozero.api.GpioInputDevice
addListener, hasListeners, removeAllListeners, removeListener
Methods inherited from class com.diozero.api.GpioDevice
getGpio
-
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 connectedpud
- Pull up/down configuration, values: NONE, PULL_UP, PULL_DOWNtrigger
- Event trigger configuration, values: NONE, RISING, FALLING, BOTH- Throws:
RuntimeIOException
- If an I/O error occurs
-
DigitalInputDevice
public DigitalInputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio) throws RuntimeIOException Defaults to "active high".- Parameters:
deviceFactory
- Device factory to use to provision this digital input devicegpio
- GPIO to which the device is connected- Throws:
RuntimeIOException
- If an I/O error occurs
-
DigitalInputDevice
public DigitalInputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException, NoSuchDeviceException - Parameters:
deviceFactory
- Device factory to use to provision this digital input devicegpio
- GPIO to which the device is connectedpud
- Pull up/down configuration, values: NONE, PULL_UP, PULL_DOWNtrigger
- Event trigger configuration, values: NONE, RISING, FALLING, BOTH- Throws:
RuntimeIOException
- If an I/O error occursNoSuchDeviceException
-
DigitalInputDevice
public DigitalInputDevice(GpioDeviceFactoryInterface deviceFactory, PinInfo pinInfo, GpioPullUpDown pud, GpioEventTrigger trigger, boolean activeHigh) throws RuntimeIOException, NoSuchDeviceException - Parameters:
deviceFactory
- Device factory to use to provision this digital input devicepinInfo
- Information about the GPIO pin to which the device is connectedpud
- Pull up/down configuration, values: NONE, PULL_UP, PULL_DOWNtrigger
- Event trigger configuration, values: NONE, RISING, FALLING, BOTHactiveHigh
- Set to true if digital 1 is to be treated as active- Throws:
RuntimeIOException
- If an I/O error occurs.NoSuchDeviceException
-
-
Method Details
-
close
public void close()Description copied from interface:DeviceInterface
Close this device -
getName
-
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
-