Package com.diozero.api
Class DigitalOutputDevice
- java.lang.Object
-
- com.diozero.api.GpioDevice
-
- com.diozero.api.DigitalOutputDevice
-
- All Implemented Interfaces:
DeviceInterface
,AutoCloseable
public class DigitalOutputDevice extends GpioDevice
Provides generic digital (on/off) output control with support for active high and low logic.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DigitalOutputDevice.Builder
-
Field Summary
Fields Modifier and Type Field Description static int
INFINITE_ITERATIONS
-
Fields inherited from class com.diozero.api.GpioDevice
pinInfo
-
-
Constructor Summary
Constructors Constructor Description DigitalOutputDevice(int gpio)
Defaults to active high logic, initial value is off.DigitalOutputDevice(int gpio, boolean activeHigh, boolean initialValue)
DigitalOutputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio, boolean activeHigh, boolean initialValue)
DigitalOutputDevice(GpioDeviceFactoryInterface deviceFactory, PinInfo pinInfo, boolean activeHigh, boolean initialValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this deviceint
getCycleCount()
boolean
isActiveHigh()
boolean
isOn()
Get the device on / off status.void
off()
Turn off the device compensating for active low/high logic levels.void
on()
Turn on the device compensating for active low/high logic levels.void
onOffLoop(float onTime, float offTime, int n, boolean background, Action stopAction)
Toggle the device on-off.void
setOn(boolean on)
Turn the device on or off.void
setValue(boolean value)
Set the device output value without compensating for active low/high logic levels.void
stopOnOffLoop()
void
toggle()
Toggle the state of the device.-
Methods inherited from class com.diozero.api.GpioDevice
getGpio
-
-
-
-
Field Detail
-
INFINITE_ITERATIONS
public static final int INFINITE_ITERATIONS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DigitalOutputDevice
public DigitalOutputDevice(int gpio) throws RuntimeIOException
Defaults to active high logic, initial value is off.- Parameters:
gpio
- GPIO to which the output device is connected.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
DigitalOutputDevice
public DigitalOutputDevice(int gpio, boolean activeHigh, boolean initialValue) throws RuntimeIOException
- Parameters:
gpio
- GPIO to which the output device is connected.activeHigh
- If true then setting the value to true will turn on the connected device.initialValue
- Initial output value.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
DigitalOutputDevice
public DigitalOutputDevice(GpioDeviceFactoryInterface deviceFactory, int gpio, boolean activeHigh, boolean initialValue) throws RuntimeIOException
- Parameters:
deviceFactory
- Device factory to use to construct the device.gpio
- GPIO to which the output device is connected.activeHigh
- If true then setting the value to true will turn on the connected device.initialValue
- Initial output value.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
DigitalOutputDevice
public DigitalOutputDevice(GpioDeviceFactoryInterface deviceFactory, PinInfo pinInfo, boolean activeHigh, boolean initialValue) throws RuntimeIOException
- Parameters:
deviceFactory
- Device factory to use to construct the device.pinInfo
- Information about the GPIO pin to which the output device is connected.activeHigh
- If true then setting the value to true will turn on the connected device.initialValue
- Initial output value.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
-
Method Detail
-
close
public void close()
Description copied from interface:DeviceInterface
Close this device
-
stopOnOffLoop
public void stopOnOffLoop()
-
on
public void on() throws RuntimeIOException
Turn on the device compensating for active low/high logic levels. Note that this method does not check if the on-off loop is running.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
off
public void off() throws RuntimeIOException
Turn off the device compensating for active low/high logic levels. Note that this method does not check if the on-off loop is running.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
toggle
public void toggle() throws RuntimeIOException
Toggle the state of the device.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
isOn
public boolean isOn() throws RuntimeIOException
Get the device on / off status.- Returns:
- Returns true if the device is currently on.
- Throws:
RuntimeIOException
- If an I/O error occurred.
-
setOn
public void setOn(boolean on) throws RuntimeIOException
Turn the device on or off.- Parameters:
on
- New on/off value.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
setValue
public void setValue(boolean value) throws RuntimeIOException
Set the device output value without compensating for active low/high logic levels. Note that this method does not check if the on-off loop is running.- Parameters:
value
- The new value- Throws:
RuntimeIOException
- If an I/O error occurs
-
onOffLoop
public void onOffLoop(float onTime, float offTime, int n, boolean background, Action stopAction) throws RuntimeIOException
Toggle the device on-off.- Parameters:
onTime
- On time in seconds.offTime
- Off time in seconds.n
- Number of iterations. Set to <0 to blink indefinitely.background
- If true start a background thread to control the blink and return immediately. If false, only return once the blink iterations have finished.stopAction
- Action to perform when the loop finishes- Throws:
RuntimeIOException
- If an I/O error occurs
-
isActiveHigh
public boolean isActiveHigh()
-
getCycleCount
public int getCycleCount()
-
-