- All Implemented Interfaces:
Describable,Identity,Lifecycle,Extension,Bindable<DigitalOutput,,DigitalBinding> Digital<DigitalOutput,,DigitalOutputConfig, DigitalOutputProvider> DigitalOutput,com.pi4j.io.gpio.Gpio<DigitalOutput,,DigitalOutputConfig, DigitalOutputProvider> IO<DigitalOutput,,DigitalOutputConfig, DigitalOutputProvider> OnOff<DigitalOutput>,OnOffRead<DigitalOutput>,OnOffWrite<DigitalOutput>,Output
Abstract DigitalOutputBase class.
- Version:
- $Id: $Id
- Author:
- Robert Savage (http://www.savagehomeautomation.com)
-
Field Summary
FieldsFields inherited from class com.pi4j.io.gpio.digital.DigitalBase
bindings, stateChangeEventManagerFields inherited from class com.pi4j.common.IdentityBase
description, id, logger, metadata, name -
Constructor Summary
ConstructorsConstructorDescriptionDigitalOutputBase(DigitalOutputProvider provider, DigitalOutputConfig config) Constructor for DigitalOutputBase. -
Method Summary
Modifier and TypeMethodDescriptionblink(int delay, int duration, TimeUnit unit, DigitalState state, Callable<Void> callback) This method will blink an output pin of the RPi according the given specifications.Future<?> blinkAsync(int delay, int duration, TimeUnit unit, DigitalState state, Callable<Void> callback) This method is exactly the same as the blink() method, except that this method is non-blocking and returns aFuturewith which the action can be cancelled, or it can be detected if the task is completeinitialize(Context context) initialize.off()on()pulse(int interval, TimeUnit unit, DigitalState state, Callable<Void> callback) pulse.Future<?> pulseAsync(int interval, TimeUnit unit, DigitalState state, Callable<Void> callback) pulseAsync.shutdown.state()state.state(DigitalState state) state.Methods inherited from class com.pi4j.io.gpio.digital.DigitalBase
addListener, bind, dispatch, isOn, removeListener, unbindMethods inherited from class com.pi4j.io.gpio.GpioBase
toStringMethods inherited from class com.pi4j.io.IOBase
config, context, describe, description, name, providerMethods inherited from class com.pi4j.common.IdentityBase
description, id, metadata, nameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.pi4j.io.gpio.digital.Digital
addListener, equals, equals, equals, equals, equals, equals, equals, equals, equals, isHigh, isLow, removeListenerMethods inherited from interface com.pi4j.io.gpio.digital.DigitalOutput
blink, blink, blink, blinkAsync, blinkAsync, blinkAsync, high, low, pulse, pulse, pulseAsync, pulseAsync, pulseHigh, pulseHighAsync, pulseLow, pulseLowAsync, setState, setState, setState, setState, setState, setState, setState, toggleMethods inherited from interface com.pi4j.io.gpio.Gpio
address, getAddressMethods inherited from interface com.pi4j.common.Identity
description, getDescription, getId, getMetadata, getName, id, metadata, name
-
Field Details
-
state
-
-
Constructor Details
-
DigitalOutputBase
Constructor for DigitalOutputBase.
- Parameters:
provider- aDigitalOutputProviderobject.config- aDigitalOutputConfigobject.
-
-
Method Details
-
initialize
initialize.
- Specified by:
initializein interfaceLifecycle- Overrides:
initializein classIOBase<DigitalOutput,DigitalOutputConfig, DigitalOutputProvider> - Parameters:
context- aContextobject.- Returns:
- a T object.
- Throws:
InitializeException- if an error occurs during initialization.
-
state
state.
- Specified by:
statein interfaceDigitalOutput- Parameters:
state- aDigitalStateobject.- Returns:
- a
DigitalOutputobject. - Throws:
IOException- if any.
-
pulse
public DigitalOutput pulse(int interval, TimeUnit unit, DigitalState state, Callable<Void> callback) throws IOException pulse.
- Specified by:
pulsein interfaceDigitalOutput- Parameters:
interval- a int.unit- aTimeUnitobject.state- aDigitalStateobject.callback- aCallableobject.- Returns:
- a
DigitalOutputobject. - Throws:
IOException- if any.
-
pulseAsync
public Future<?> pulseAsync(int interval, TimeUnit unit, DigitalState state, Callable<Void> callback) pulseAsync.
- Specified by:
pulseAsyncin interfaceDigitalOutput- Parameters:
interval- a int.unit- aTimeUnitobject.state- aDigitalStateobject.callback- aCallableobject.- Returns:
- a
Futureobject.
-
blink
public DigitalOutput blink(int delay, int duration, TimeUnit unit, DigitalState state, Callable<Void> callback) This method will blink an output pin of the RPi according the given specifications. The pin itself is created while creating a DigitalOutput configuration where one of the parameters is an address (= a BCM pin number).- Specified by:
blinkin interfaceDigitalOutput- Parameters:
delay- The toggle time.duration- The amount of times the output has to toggle.Representation:
Output HIGH +-----+ +-----+ +-----+ +-----+ +-----+ | | | | | | | | | | Output LOW + +-----+ +-----+ +-----+ +-----+ +-----+ ^ ^ start -┘ └- stop \___/ \___/ delay delay \___________________________________________________________/ durationExample:Delay = 1 sec / duration = 5
Output will be like so (suppose the initial state is set to HIGH):
1 - 0 - 1 - 0 - 1 - 0 - 1 - 0 - 1 - 0 with each state lasting for 1 second.
So, if you would connect a LED to the pin, you would see the LED switching
on and off for 5 times.
Note: this is a blocking method!
For as long as it takes to manipulate the output pin, the method will not return.
In the example given above, it means the method will block for 10 seconds (5 times high for a second
and 5 times low for a second), also for calling the callback function.If you don't want the
blink()method to block the calling thread, pls. use theblinkAsync()method instead.
unit- The time unit used to calculate the delay.state- The initial state of the pin.callback- The method to call, if any, once the blinking is done.- Returns:
- The DigitalOutputBase object itself.
-
blinkAsync
public Future<?> blinkAsync(int delay, int duration, TimeUnit unit, DigitalState state, Callable<Void> callback) This method is exactly the same as the blink() method, except that this method is non-blocking and returns aFuturewith which the action can be cancelled, or it can be detected if the task is completeSee the
blink()method for a more detailed explanation on how the method works.- Specified by:
blinkAsyncin interfaceDigitalOutput- Parameters:
delay- The toggle time.duration- The amount of times the output has to toggle.unit- The time unit used to calculate the delay.state- The initial state of the pin.callback- The method to call, if any, once the blinking is done.- Returns:
- A Future object that can be used to observe the end of the async blinking.
-
state
state.
- Specified by:
statein interfaceDigital<DigitalOutput,DigitalOutputConfig, DigitalOutputProvider> - Returns:
- a
DigitalStateobject.
-
shutdown
shutdown.
- Specified by:
shutdownin interfaceLifecycle- Overrides:
shutdownin classDigitalBase<DigitalOutput,DigitalOutputConfig, DigitalOutputProvider> - Parameters:
context- aContextobject.- Returns:
- a T object.
- Throws:
ShutdownException- if an error occurs during shutdown.
-
on
- Specified by:
onin interfaceOnOffWrite<DigitalOutput>- Throws:
IOException
-
off
- Specified by:
offin interfaceOnOffWrite<DigitalOutput>- Throws:
IOException
-