@Override public void setState(Pin pin, PinState state) { super.setState(pin, state); LOG.info("State {} {}", pin, state); }
@Override public void setValue(Pin pin, double value) { super.setValue(pin, value); throw new RuntimeException("This GPIO provider does not support analog pins."); }
@Override public void export(Pin pin, PinMode mode, PinState defaultState) { // export the pin and set it's mode export(pin, mode); // apply default state if one was provided and only if this pin is a digital output if(defaultState != null && mode == PinMode.DIGITAL_OUTPUT) { setState(pin, defaultState); } }
@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 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 PinState getState(Pin pin) { return super.getState(pin); }
@Override public void setMode(Pin pin, PinMode mode) { // ALL PIN MODES ARE PREDEFINED // // an exception will be throw by the base impl // if an alternate mode is selected for a pin // instance super.setMode(pin, mode); }
@Override public void unexport(Pin pin) { super.unexport(pin); setMode(pin, PinMode.DIGITAL_OUTPUT); }
@Override public void export(Pin pin, PinMode mode) { // make sure to set the pin mode super.export(pin, mode); setMode(pin, mode); }
@Override public PinMode getMode(Pin pin) { return super.getMode(pin); }
@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 double getValue(Pin pin) { super.getValue(pin); throw new RuntimeException("This GPIO provider does not support analog pins."); }
@Override public void addListener(Pin pin, PinListener listener) { super.addListener(pin, listener); // update the native interrupt listener thread for callbacks updateInterruptListener(pin); }
@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 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 PinState getState(Pin pin) { super.getState(pin); // calculate current state from the bitmask value int bit = (int)Math.pow(2, (pin.getAddress()-1)); int state = (currentStates & bit); return (state == bit) ? PinState.HIGH : PinState.LOW; }
@Override public void setMode(Pin pin, PinMode mode) { super.setMode(pin, mode); }
@Override public void unexport(Pin pin) { super.unexport(pin); setMode(pin, PinMode.DIGITAL_OUTPUT); }