public synchronized static Future<?> pulse(GpioPinDigitalOutput pin, long duration, PinState pulseState, Callable<?> callback) { // create future return object ScheduledFuture<?> scheduledFuture = null; // perform the initial startup and cleanup for this pin init(pin); // we only pulse for requests with a valid duration in milliseconds if (duration > 0) { // set the active state pin.setState(pulseState); // create future job to return the pin to the low state scheduledFuture = scheduledExecutorService .schedule(new GpioPulseTaskImpl(pin, PinState.getInverseState(pulseState), callback), duration, TimeUnit.MILLISECONDS); // get pending tasks for the current pin ArrayList<ScheduledFuture<?>> tasks; if (!pinTaskQueue.containsKey(pin)) { pinTaskQueue.put(pin, new ArrayList<>()); } tasks = pinTaskQueue.get(pin); // add the new scheduled task to the tasks collection tasks.add(scheduledFuture); // create future task to clean up completed tasks createCleanupTask(duration + 500); } // return future task return scheduledFuture; }
public synchronized static Future<?> pulse(GpioPinDigitalOutput pin, long duration, PinState pulseState, Callable<?> callback) { // create future return object ScheduledFuture<?> scheduledFuture = null; // perform the initial startup and cleanup for this pin init(pin); // we only pulse for requests with a valid duration in milliseconds if (duration > 0) { // set the active state pin.setState(pulseState); // create future job to return the pin to the low state scheduledFuture = scheduledExecutorService .schedule(new GpioPulseTaskImpl(pin, PinState.getInverseState(pulseState), callback), duration, TimeUnit.MILLISECONDS); // get pending tasks for the current pin ArrayList<ScheduledFuture<?>> tasks; if (!pinTaskQueue.containsKey(pin)) { pinTaskQueue.put(pin, new ArrayList<ScheduledFuture<?>>()); } tasks = pinTaskQueue.get(pin); // add the new scheduled task to the tasks collection tasks.add(scheduledFuture); // create future task to clean up completed tasks createCleanupTask(duration + 500); } // return future task return scheduledFuture; }
setState(PinState.getInverseState(pulseState));
setState(PinState.getInverseState(pulseState));
.schedule(new GpioBlinkStopTaskImpl(pin,PinState.getInverseState(blinkState), scheduledFutureBlinkTask), duration, TimeUnit.MILLISECONDS);
.schedule(new GpioBlinkStopTaskImpl(pin,PinState.getInverseState(blinkState), scheduledFutureBlinkTask), duration, TimeUnit.MILLISECONDS);