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:
DeviceInterface
,DigitalInputDeviceInterface
,DeviceEventConsumer<DigitalInputEvent>
,AutoCloseable
,Consumer<DigitalInputEvent>
- Direct Known Subclasses:
Button
,DebouncedDigitalInputDevice
,SmoothedInputDevice
public class DigitalInputDevice extends AbstractDigitalInputDevice
Represents a generic digital input device.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DigitalInputDevice.Builder
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
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, boolean activeHigh)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this deviceGpioPullUpDown
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, 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 Detail
-
DigitalInputDevice
public DigitalInputDevice(int gpio) throws RuntimeIOException, NoSuchDeviceException
- Parameters:
gpio
- GPIO to which the device is connected.- Throws:
RuntimeIOException
- If an I/O error occurs.NoSuchDeviceException
-
DigitalInputDevice
public DigitalInputDevice(int gpio, GpioPullUpDown pud, GpioEventTrigger trigger) throws RuntimeIOException, NoSuchDeviceException
- 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 occursNoSuchDeviceException
-
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 Detail
-
close
public void close()
Description copied from interface:DeviceInterface
Close this device
-
getPullUpDown
public GpioPullUpDown getPullUpDown()
Get pull up / down configuration.- Returns:
- Pull up / down configuration.
-
getTrigger
public GpioEventTrigger getTrigger()
Get event trigger configuration.- Returns:
- Event trigger configuration.
-
getValue
public boolean getValue() throws RuntimeIOException
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
public boolean isActive() throws RuntimeIOException
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
-
-