public UnsupportedPinModeException(Pin pin, PinMode mode) { super("This GPIO pin [" + pin.getName() + "] does not support the pin mode specified [" + mode.getName() + "]"); this.pin = pin; this.mode = mode; }
public UnsupportedPinModeException(Pin pin, PinMode mode) { super("This GPIO pin [" + pin.getName() + "] does not support the pin mode specified [" + mode.getName() + "]"); this.pin = pin; this.mode = mode; }
@Override public String toString() { return "PIN [" + pin.getName() + "] CACHE :: mode=" + mode.getName() + "; state=" + state.getName(); }
@Override public String toString() { return "PIN [" + pin.getName() + "] CACHE :: mode=" + mode.getName() + "; state=" + state.getName(); }
private void validatePin(Pin pin, int onPosition, int offPosition) { if (hasPin(pin) == false) { throw new InvalidPinException(pin); } PinMode mode = getMode(pin); if (mode != PinMode.PWM_OUTPUT) { throw new InvalidPinModeException(pin, "Invalid pin mode [" + mode.getName() + "]; unable to setPwm(" + onPosition + ", " + offPosition + ")"); } }
@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 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 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 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) { // no need to export an Odroid AIN pin if (mode == PinMode.ANALOG_INPUT) { if (!pin.getSupportedPinModes().contains(mode)) { throw new InvalidPinModeException(pin, "Invalid pin mode [" + mode.getName() + "]; pin [" + pin.getName() + "] does not support this mode."); } // local pin mode cache pinModeCache[pin.getAddress()] = mode; // cache mode getPinCache(pin).setMode(mode); return; } super.setMode(pin, mode); }
@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); }
@Override public void setMode(Pin pin, PinMode mode) { super.setMode(pin, mode); // local pin mode cache pinModeCache[pin.getAddress()] = 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); // set pin mode on hardware com.pi4j.wiringpi.Gpio.pinMode(pin.getAddress(), mode.getValue()); }
@Override public void setMode(Pin pin, PinMode mode) { super.setMode(pin, mode); // local pin mode cache pinModeCache[pin.getAddress()] = 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); // set pin mode on hardware com.pi4j.wiringpi.Gpio.pinMode(pin.getAddress(), mode.getValue()); }
@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); }
@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); }
@Override public void setState(Pin pin, PinState state) { // validate pin if (!hasPin(pin)) { throw new InvalidPinException(pin); } // only permit invocation on pins set to DIGITAL_OUTPUT modes if (pinModeCache[pin.getAddress()] != PinMode.DIGITAL_OUTPUT) { throw new InvalidPinModeException(pin, "Invalid pin mode on pin [" + pin.getName() + "]; cannot setState() when pin mode is [" + pinModeCache[pin.getAddress()].getName() + "]"); } // control GPIO pin com.pi4j.wiringpi.Gpio.digitalWrite(pin.getAddress(), state.getValue()); // for digital output pins, we will echo the event feedback dispatchPinDigitalStateChangeEvent(pin, state); // for the Raspberry pi, we will not cache pin state since we never use the cache to get state. }
@Override public void setState(Pin pin, PinState state) { // validate pin if (!hasPin(pin)) { throw new InvalidPinException(pin); } // only permit invocation on pins set to DIGITAL_OUTPUT modes if (pinModeCache[pin.getAddress()] != PinMode.DIGITAL_OUTPUT) { throw new InvalidPinModeException(pin, "Invalid pin mode on pin [" + pin.getName() + "]; cannot setState() when pin mode is [" + pinModeCache[pin.getAddress()].getName() + "]"); } // control GPIO pin com.pi4j.wiringpi.Gpio.digitalWrite(pin.getAddress(), state.getValue()); // for digital output pins, we will echo the event feedback dispatchPinDigitalStateChangeEvent(pin, state); // for the Raspberry pi, we will not cache pin state since we never use the cache to get state. }