@Override public GpioPin provisionPin(GpioProvider provider, Pin pin, String name, PinMode mode) { // if an existing pin has been previously created, then throw an error for (GpioPin p : pins) { if (p.getProvider().equals(provider) && p.getPin().equals(pin)) { throw new GpioPinExistsException(pin); } } // create new GPIO pin instance GpioPin gpioPin = new GpioPinImpl(this, provider, pin); // set the gpio pin name if (name != null) { gpioPin.setName(name); } // export this pin gpioPin.export(mode); // add this new pin instance to the managed collection pins.add(gpioPin); // return new new pin instance return gpioPin; }
public void setShutdownOptions(Boolean unexport, PinState state, GpioPin... pin) { for (GpioPin p : pin) { if (!pins.contains(p)) { throw new GpioPinNotProvisionedException(p.getPin()); } p.setShutdownOptions(unexport, state); } }
public void setShutdownOptions(GpioPinShutdown options, GpioPin... pin) { for (GpioPin p : pin) { if (!pins.contains(p)) { throw new GpioPinNotProvisionedException(p.getPin()); } p.setShutdownOptions(options); } }
private void unprovision(Pin pin) { for (GpioPin e : gpioContoller.getProvisionedPins()) { if (e.getPin().equals(pin)) { gpioContoller.unprovisionPin(e); break; } } }
@Override public PinPullResistance getPullResistance(GpioPin pin) { // ensure the requested pin has been provisioned if (!pins.contains(pin)) { throw new GpioPinNotProvisionedException(pin.getPin()); } // get pin pull resistance return pin.getPullResistance(); }
@Override public PinMode getMode(GpioPin pin) { // ensure the requested pin has been provisioned if (!pins.contains(pin)) { throw new GpioPinNotProvisionedException(pin.getPin()); } // return pin edge setting return pin.getMode(); }
@Override public void export(PinMode mode, GpioPin... pin) { if (pin == null || pin.length == 0) { throw new IllegalArgumentException("Missing pin argument."); } for (GpioPin p : pin) { // ensure the requested pin has been provisioned if (!pins.contains(p)) { throw new GpioPinNotProvisionedException(p.getPin()); } // export the pin p.export(mode); } }
@Override public void setPullResistance(PinPullResistance resistance, GpioPin... pin) { if (pin == null || pin.length == 0) { throw new IllegalArgumentException("Missing pin argument."); } for (GpioPin p : pin) { // ensure the requested pin has been provisioned if (!pins.contains(p)) { throw new GpioPinNotProvisionedException(p.getPin()); } // set pin pull resistance p.setPullResistance(resistance); } }
/** * @param pin * @return * <p>A value of 'true' is returned if the requested pin is exported. */ @Override public boolean isExported(GpioPin... pin) { if (pin == null || pin.length == 0) { throw new IllegalArgumentException("Missing pin argument."); } for (GpioPin p : pin) { // ensure the requested pin has been provisioned if (!pins.contains(pin)) { throw new GpioPinNotProvisionedException(p.getPin()); } if (!p.isExported()) { return false; } } // return the pin exported state return true; }
@Override public void unprovisionPin(GpioPin... pin) { if (pin == null || pin.length == 0) { throw new IllegalArgumentException("Missing pin argument."); } for (int index = (pin.length - 1); index >= 0; index--) { GpioPin p = pin[index]; // ensure the requested pin has been provisioned if (!pins.contains(p)) { throw new GpioPinNotProvisionedException(p.getPin()); } // remove all listeners and triggers if (p instanceof GpioPinInput) { ((GpioPinInput) p).removeAllListeners(); ((GpioPinInput) p).removeAllTriggers(); } // remove this pin instance from the managed collection pins.remove(p); } }