/** * Turn off the device (same as {@code setValue(0)}). * * @throws RuntimeIOException * If an I/O error occurred. */ public void off() throws RuntimeIOException { stopLoops(); setValueInternal(0); }
/** * Turn on the device (same as {@code setValue(1)}). * * @throws RuntimeIOException * If an I/O error occurred. */ public void on() throws RuntimeIOException { stopLoops(); setValueInternal(1); }
/** * Set the PWM output value (0..1). * * @param value * New PWM output value. * @throws RuntimeIOException * If an I/O error occurred. */ @Override public void setValue(float value) throws RuntimeIOException { stopLoops(); setValueInternal(value); }
/** * Toggle the state of the device (same as {@code setValue(1 - getvalue())} * ). * * @throws RuntimeIOException * If an I/O error occurred. */ public void toggle() throws RuntimeIOException { stopLoops(); setValueInternal(1 - device.getValue()); }
@Override public void close() { Logger.debug("close()"); if (running.get()) { stopLoops(); Logger.debug("Interrupting background thread " + backgroundThread.getName()); backgroundThread.interrupt(); } Logger.debug("Setting value to 0"); try { device.setValue(0); } catch (RuntimeIOException e) { } device.close(); Logger.debug("device closed"); }
protected void onOffLoop(float onTime, float offTime, int n, boolean background) throws RuntimeIOException { stopLoops(); if (background) { DioZeroScheduler.getDaemonInstance().execute(() -> { backgroundThread = Thread.currentThread(); onOffLoop(onTime, offTime, n); Logger.debug("Background on-off loop finished"); }); } else { onOffLoop(onTime, offTime, n); } }
protected void fadeInOutLoop(float fadeTime, int steps, int iterations, boolean background) throws RuntimeIOException { stopLoops(); if (background) { DioZeroScheduler.getDaemonInstance().execute(() -> { backgroundThread = Thread.currentThread(); fadeInOutLoop(fadeTime, steps, iterations); Logger.debug("Background fade in-out loop finished"); }); } else { fadeInOutLoop(fadeTime, steps, iterations); } }