@Override public void setMode(Pin pin, PinMode mode) { // validate if (!pin.getSupportedPinModes().contains(mode)) { throw new InvalidPinModeException( pin, "Invalid pin mode [" + mode.getName() + "]; pin [" + pin.getName() + "] does not support this mode."); } // validate if (!pin.getSupportedPinModes().contains(mode)) { throw new UnsupportedPinModeException(pin, mode); } // determine A or B port based on pin address try { if (pin.getAddress() < GPIO_B_OFFSET) { setModeA(pin, mode); } else { setModeB(pin, mode); } } catch (IOException ex) { throw new RuntimeException(ex); } // cache mode getPinCache(pin).setMode(mode); // if any pins are configured as input pins, then we need to start the interrupt monitoring // thread if (currentDirectionA > 0 || currentDirectionB > 0) { // if the monitor has not been started, then start it now if (monitor == null) { // start monitoring thread monitor = new GpioStateMonitor(this); monitor.start(); } } else { // shutdown and destroy monitoring thread since there are no input pins configured if (monitor != null) { monitor.shutdown(); monitor = null; } } }
@Override public void shutdown() { // prevent reentrant invocation if (isShutdown()) return; // perform shutdown login in base super.shutdown(); // if a monitor is running, then shut it down now if (monitor != null) { // shutdown monitoring thread monitor.shutdown(); monitor = null; } }