public class Delay extends java.lang.Object implements ScheduledEventListener
final int GPIO_OUTPUT = 23; GPIODigitalOutput outputPin = GPIODigitalOutput.getOutputPin(GPIO_OUTPUT); if (outputPin != null) { outputPin.setState(true); // now we will turn it off after 5 seconds new Delay(5000, outputPin, (delay_offset, param) - > { // delay_offset is how far out we were from our exact delay time in ms and is a double // param is the parameter we passed in, which was the output pin ((GPIODigitalOutput) o).setState(false); }); }More detail is in
Delay.DelayListener.delayComplete(double, Object)
Modifier and Type | Class and Description |
---|---|
static interface |
Delay.DelayListener
DelayReceived interface for receiving delay complete.
|
Constructor and Description |
---|
Delay(double interval,
java.lang.Object param,
Delay.DelayListener listener)
Constructor using default Scheduler.
|
Delay(double interval,
java.lang.Object param,
Delay.DelayListener listener,
HBScheduler scheduler)
Constructor using an independent
HBScheduler . |
Modifier and Type | Method and Description |
---|---|
void |
doScheduledEvent(double scheduledTime,
java.lang.Object param)
Notification interface that a scheduled event is occuring
|
boolean |
isRunning()
See if delay object is pending
|
void |
stop()
Cancel the delay event and stop it from occurring.
|
public Delay(double interval, java.lang.Object param, Delay.DelayListener listener)
final int GPIO_OUTPUT = 23; GPIODigitalOutput outputPin = GPIODigitalOutput.getOutputPin(GPIO_OUTPUT); if (outputPin != null) { outputPin.setState(true); // now we will turn it off after 5 seconds new Delay(5000, outputPin, (delay_offset, param) - > { // delay_offset is how far out we were from our exact delay time in ms and is a double // param is the parameter we passed in, which was the output pin ((GPIODigitalOutput) o).setState(false); }); }
interval
- the interval in milliseconds.param
- the parameter we want t pass back when our delay has completedlistener
- the Delay.DelayListener
to receive the callback when delay has finishedpublic Delay(double interval, java.lang.Object param, Delay.DelayListener listener, HBScheduler scheduler)
HBScheduler
. Specifics about delay constructor are in
Delay(double, Object, DelayListener)
interval
- the interval in milliseconds If less than zero, the delay will call back on next schedule updateparam
- the parameter we want t pass back when our delay has completedlistener
- the Delay.DelayListener
to receive the callback when delay has finishedscheduler
- the HBScheduler
to usepublic void doScheduledEvent(double scheduledTime, java.lang.Object param)
ScheduledEventListener
doScheduledEvent
in interface ScheduledEventListener
scheduledTime
- the time that was scheduled for the callback to occurparam
- the parameter to pass to the listener.public boolean isRunning()
public void stop()
// This delay will take 50 seconds Delay longdelay = new Delay(50000, null, (delay_offset, param) - > { // delay_offset is how far out we were from our exact delay time in ms and is a double // param is the parameter we passed in type your code below this line System.out.println("Delay Complete"); // type your code above this line }); // 30 seconds in the future - we will stop longdelay completing longdelay.stop();