Package com.diozero.api
Class DigitalInputOutputDevice
java.lang.Object
com.diozero.api.GpioDevice
com.diozero.api.GpioInputDevice<DigitalInputEvent>
com.diozero.api.AbstractDigitalInputDevice
com.diozero.api.DigitalInputOutputDevice
- All Implemented Interfaces:
DigitalInputDeviceInterface
,DeviceEventConsumer<DigitalInputEvent>
,Closeable
,AutoCloseable
,Consumer<DigitalInputEvent>
public class DigitalInputOutputDevice extends AbstractDigitalInputDevice
-
Field Summary
Fields inherited from class com.diozero.api.AbstractDigitalInputDevice
activeHigh
Fields inherited from class com.diozero.api.GpioDevice
gpio
-
Constructor Summary
Constructors Constructor Description DigitalInputOutputDevice(int gpio, DeviceMode mode)
DigitalInputOutputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio, DeviceMode mode)
DigitalInputOutputDevice(GpioDeviceFactoryInterface deviceFactory, PinInfo pinInfo, DeviceMode mode)
-
Method Summary
Modifier and Type Method Description void
close()
DeviceMode
getMode()
Get the input / output modeboolean
getValue()
Read the current underlying state of the input pin.protected void
removeListener()
protected void
setListener()
void
setMode(DeviceMode mode)
Set the input / output modevoid
setValue(boolean value)
Set the output value (if in output mode).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
-
Constructor Details
-
DigitalInputOutputDevice
- Parameters:
gpio
- GPIO to which the device is connected.mode
- Input or outputMode
- Throws:
RuntimeIOException
- If an I/O error occurs.
-
DigitalInputOutputDevice
public DigitalInputOutputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio, DeviceMode mode) throws RuntimeIOException- Parameters:
deviceFactory
- Device factory to use to provision this digital input device.gpio
- GPIO to which the device is connected.mode
- Input or outputMode
- Throws:
RuntimeIOException
- If an I/O error occurs.
-
DigitalInputOutputDevice
public DigitalInputOutputDevice(GpioDeviceFactoryInterface deviceFactory, PinInfo pinInfo, DeviceMode mode) 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.mode
- Input or outputMode
- Throws:
RuntimeIOException
- If an I/O error occurs.
-
-
Method Details
-
close
- Throws:
RuntimeIOException
-
getMode
Get the input / output mode- Returns:
- current mode
-
setMode
Set the input / output mode- Parameters:
mode
- new mode, valid values areDIGITAL_INPUT
andDIGITAL_OUTPUT
-
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.
-
setValue
Set the output value (if in output mode).- Parameters:
value
- The new value- Throws:
RuntimeIOException
- If an I/O error occurs
-
setListener
protected void setListener()- Specified by:
setListener
in classAbstractDigitalInputDevice
-
removeListener
protected void removeListener()- Specified by:
removeListener
in classAbstractDigitalInputDevice
-