@Override public PinMode getMode(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // return cached mode value return getPinCache(pin).getMode(); }
@Override public PinMode getMode(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // return cached mode value 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 int getPwm(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // return cached pin PWM value return getPinCache(pin).getPwmValue(); }
@Override public int getPwm(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // return cached pin PWM value return getPinCache(pin).getPwmValue(); }
@Override public PinPullResistance getPullResistance(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // return cached resistance return getPinCache(pin).getResistance(); }
@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 PinPullResistance getPullResistance(Pin pin) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } // return cached resistance return getPinCache(pin).getResistance(); }
@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 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 PinState getState(Pin pin) { // the getMode() will validate the pin exists with the hasPin() function PinMode mode = getMode(pin); // only permit invocation on pins set to DIGITAL modes if (!PinMode.allDigital().contains(mode)) { throw new InvalidPinModeException(pin, "Invalid pin mode on pin [" + pin.getName() + "]; cannot getState() when pin mode is [" + mode.getName() + "]"); } // return cached pin state return getPinCache(pin).getState(); }
@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 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 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 PinState getState(Pin pin) { // the getMode() will validate the pin exists with the hasPin() function PinMode mode = getMode(pin); // only permit invocation on pins set to DIGITAL modes if (!PinMode.allDigital().contains(mode)) { throw new InvalidPinModeException(pin, "Invalid pin mode on pin [" + pin.getName() + "]; cannot getState() when pin mode is [" + mode.getName() + "]"); } // return cached pin state return getPinCache(pin).getState(); }
@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 setPwm(Pin pin, int value) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } PinMode mode = getMode(pin); if (mode != PinMode.PWM_OUTPUT || mode != PinMode.SOFT_PWM_OUTPUT) { throw new InvalidPinModeException(pin, "Invalid pin mode [" + mode.getName() + "]; unable to setPwm(" + value + ")"); } // cache pin PWM value getPinCache(pin).setPwmValue(value); }
@Override public void setPwm(Pin pin, int value) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } PinMode mode = getMode(pin); if (mode != PinMode.PWM_OUTPUT || mode != PinMode.SOFT_PWM_OUTPUT) { throw new InvalidPinModeException(pin, "Invalid pin mode [" + mode.getName() + "]; unable to setPwm(" + value + ")"); } // cache pin PWM value getPinCache(pin).setPwmValue(value); }