public void setShutdownOptions(Boolean unexport, GpioPin... pin) { for (GpioPin p : pin) { if (!pins.contains(p)) { throw new GpioPinNotProvisionedException(p.getPin()); } p.setShutdownOptions(unexport); } }
@Override public GpioPin getProvisionedPin(String name){ for(GpioPin pin : pins){ if(pin.getName().equals(name)){ return pin; } } return null; }
@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(); }
String json = "{\"pin\":{\"name\":\"" + pin.getName() + "\",\"address\":\"" + pin.getPin().getAddress() + "\",\"provider\":\"" + pin.getPin().getProvider() + "\",\"mode\":\"" + pin.getMode().getName() + "\",\"direction\":\"" + pin.getMode().getDirection() + "\",\"pull\":\"" + pin.getPullResistance().getName() + "\"},\"state\":{" + "\"name\":\"" + state.getName() + pin.getName(), // VALUE 1
@Override public GpioPin getProvisionedPin(Pin pin){ for(GpioPin gpio_pin : pins){ if(gpio_pin.getPin().equals(pin)){ return gpio_pin; } } return null; }
if(!pin.getProvider().isShutdown()){ pin.getProvider().shutdown(); GpioPinShutdown shutdownOptions = pin.getShutdownOptions(); if (shutdownOptions != null) { if ((state != null) && pin.isMode(PinMode.DIGITAL_OUTPUT)) { ((GpioPinDigitalOutput)pin).setState(state); pin.setPullResistance(resistance); pin.setMode(mode); pin.unexport();
@Override public GpioPin provisionPin(GpioProvider provider, Pin pin, String name, PinMode mode, PinState defaultState) { // if the provider does not match the pin's provider then throw an error if(!provider.getName().equals(pin.getProvider())){ throw new PinProviderException(provider, pin); } // 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, defaultState); // add this new pin instance to the managed collection pins.add(gpioPin); // return new new pin instance return gpioPin; }
@Override public void setMode(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()); } // set pin mode p.setMode(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); } }
@Override public void export(PinMode mode, PinState defaultState, 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, defaultState); } }
@Override public void unexport(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()); } // unexport the pin p.unexport(); } }
@Override public boolean isPullResistance(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 if(!p.isPullResistance(resistance)) return false; } return true; }
/** * * @param pin * @return <p> * A value of 'true' is returned if the requested pin is exported. * </p> */ @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(p)) { throw new GpioPinNotProvisionedException(p.getPin()); } if (!p.isExported()) { return false; } } // return the pin exported state return true; }
@Override protected void doStop() throws Exception { pin.removeListener(this); log.trace("Stop Listening GPIO {}", pin.getPin().getAddress()); }
@Override protected void doStart() throws Exception { pin.addListener(this); log.trace("Start Listening GPIO {}", pin.getPin().getAddress()); }
private void shutdownOption(GpioPin pin) { pin.setShutdownOptions(shutdownExport, shutdownState, shutdownResistance); }
break; pin.setMode(this.mode); // Force Mode to avoid NPE } else { // enhancement we could manage several pins with one producer throw new IllegalArgumentException(
String json = "{\"pin\":{\"name\":\"" + pin.getName() + "\",\"address\":\"" + pin.getPin().getAddress() + "\",\"provider\":\"" + pin.getPin().getProvider() + "\",\"mode\":\"" + pin.getMode().getName() + "\",\"direction\":\"" + pin.getMode().getDirection() + "\",\"pull\":\"" + pin.getPullResistance().getName() + "\"},\"state\":{" + "\"name\":\"" + state.getName() + pin.getName(), // VALUE 1