/** * Turn the device on or off. * * @param on * New on/off value. * @throws RuntimeIOException * If an I/O error occurred. */ public void setOn(boolean on) throws RuntimeIOException { stopOnOffLoop(); setValueUnsafe(activeHigh & on); }
/** * Turn on the device. * * @throws RuntimeIOException * If an I/O error occurred. */ public void on() throws RuntimeIOException { stopOnOffLoop(); setValueUnsafe(activeHigh); }
/** * Turn off the device. * * @throws RuntimeIOException * If an I/O error occurred. */ public void off() throws RuntimeIOException { stopOnOffLoop(); setValueUnsafe(!activeHigh); }
/** * Toggle the state of the device. * * @throws RuntimeIOException * If an I/O error occurred. */ public void toggle() throws RuntimeIOException { stopOnOffLoop(); setValueUnsafe(!device.getValue()); }
/** * Toggle the device on-off. * * @param onTime * On time in seconds. * @param offTime * Off time in seconds. * @param n * Number of iterations. Set to <0 to blink indefinitely. * @param background * If true start a background thread to control the blink and * return immediately. If false, only return once the blink * iterations have finished. * @param stopAction * Action to perform when the loop finishes * @throws RuntimeIOException * If an I/O error occurs */ public void onOffLoop(float onTime, float offTime, int n, boolean background, Action stopAction) throws RuntimeIOException { stopOnOffLoop(); if (background) { DioZeroScheduler.getDaemonInstance().execute(() -> onOffLoop(onTime, offTime, n, stopAction)); } else { onOffLoop(onTime, offTime, n, stopAction); } } }