double oldValue = getPinCache(pin).getAnalogValue(); getPinCache(pin).setAnalogValue(newValue);
@Override public void setState(Pin pin, PinState state) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } GpioProviderPinCache pinCache = getPinCache(pin); // only permit invocation on pins set to DIGITAL_OUTPUT modes if (pinCache.getMode() != PinMode.DIGITAL_OUTPUT) { throw new InvalidPinModeException(pin, "Invalid pin mode on pin [" + pin.getName() + "]; cannot setState() when pin mode is [" + pinCache.getMode().getName() + "]"); } // for digital output pins, we will echo the event feedback dispatchPinDigitalStateChangeEvent(pin, state); // cache pin state pinCache.setState(state); }
private void evaluatePinForChangeA(Pin pin, int state) { if (getPinCache(pin).isExported()) { // determine pin address int pinAddress = pin.getAddress() - GPIO_A_OFFSET; if ((state & pinAddress) != (currentStatesA & pinAddress)) { PinState newState = (state & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(newState); // determine and cache state value for pin bit if (newState.isHigh()) { currentStatesA |= pinAddress; } else { currentStatesA &= ~pinAddress; } // change detected for INPUT PIN // System.out.println("<<< CHANGE >>> " + pin.getName() + " : " + state); dispatchPinChangeEvent(pin.getAddress(), newState); } } }
@Override public void export(Pin pin, PinMode mode) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // cache exported state getPinCache(pin).setExported(true); // cache mode getPinCache(pin).setMode(mode); }
private PinState getStateA(Pin pin){ // determine pin address int pinAddress = pin.getAddress() - GPIO_A_OFFSET; // determine pin state PinState state = (currentStatesA & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(state); return state; }
public void setAnalogValue(Pin pin, double value) { // cache pin state getPinCache(pin).setAnalogValue(value); // dispatch event dispatchPinAnalogValueChangeEvent(pin, value); }
@Override public void setMode(Pin pin, PinMode mode) { // cache mode getPinCache(pin).setMode(mode); }
@Override public void setPullResistance(Pin pin, PinPullResistance resistance) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } if (!pin.getSupportedPinPullResistance().contains(resistance)) { throw new UnsupportedPinPullResistanceException(pin, resistance); } // cache resistance getPinCache(pin).setResistance(resistance); }
@Override public PinMode getMode(Pin pin) { return getPinCache(pin).getMode(); }
@Override public boolean isExported(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // return cached exported state return getPinCache(pin).isExported(); }
@Override public void unexport(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // cache exported state getPinCache(pin).setExported(false); }
@Override public double getValue(Pin pin) { // the getMode() will validate the pin exists with the hasPin() function PinMode mode = getMode(pin); if (mode == PinMode.DIGITAL_OUTPUT) { return getState(pin).getValue(); } // return cached pin analog value return getPinCache(pin).getAnalogValue(); }
@Override public int getPwm(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // return cached pin PWM value return getPinCache(pin).getPwmValue(); }
protected GpioProviderPinCache getPinCache(Pin pin) { int address = pin.getAddress(); // dynamically resize pin cache storage if needed based on pin address if(address > cache.length){ // create a new array with existing contents // that is 100 elements larger than the requested address // (we add the extra 100 elements to provide additional overhead capacity in // an attempt to minimize further array expansion) cache = Arrays.copyOf(cache, address + 100); } // get the cached pin object from the cache GpioProviderPinCache pc = cache[address]; // if no pin object is found in the cache, then we need to create one at this address index in the cache array if(pc == null){ pc = cache[pin.getAddress()] = new GpioProviderPinCache(pin); } return pc; }
@Override public void export(Pin pin, PinMode mode) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } if (!pin.getSupportedPinModes().contains(mode)) { throw new UnsupportedPinModeException(pin, mode); } // cache exported state getPinCache(pin).setExported(true); // cache mode getPinCache(pin).setMode(mode); }
private PinState getStateB(Pin pin){ // determine pin address int pinAddress = pin.getAddress() - GPIO_B_OFFSET; // determine pin state PinState state = (currentStatesB & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(state); return state; }
@Override public void setValue(Pin pin, double value) { // the getMode() will validate the pin exists with the hasPin() function PinMode mode = getMode(pin); // only permit invocation on pins set to OUTPUT modes if (!PinMode.allOutput().contains(mode)) { throw new InvalidPinModeException(pin, "Invalid pin mode on pin [" + pin.getName() + "]; cannot setValue(" + value + ") when pin mode is [" + mode.getName() + "]"); } // for digital analog pins, we will echo the event feedback dispatchPinAnalogValueChangeEvent(pin, value); // cache pin analog value getPinCache(pin).setAnalogValue(value); }
@Override public void setMode(Pin pin, PinMode mode) { if (!pin.getSupportedPinModes().contains(mode)) { throw new InvalidPinModeException(pin, "Invalid pin mode [" + mode.getName() + "]; pin [" + pin.getName() + "] does not support this mode."); } if (!pin.getSupportedPinModes().contains(mode)) { throw new UnsupportedPinModeException(pin, mode); } // cache mode getPinCache(pin).setMode(mode); }
@Override public void setPullResistance(Pin pin, PinPullResistance resistance) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } if (!pin.getSupportedPinPullResistance().contains(resistance)) { throw new UnsupportedPinPullResistanceException(pin, resistance); } // cache resistance getPinCache(pin).setResistance(resistance); }
@Override public PinMode getMode(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // return cached mode value return getPinCache(pin).getMode(); }