@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 setPwm(Pin pin, int value) { // validate pin if (!hasPin(pin)) { throw new InvalidPinException(pin); } // get pin configured mode PinMode mode = getMode(pin); // validate mode; set PWM value based on pin mode if (mode == PinMode.PWM_OUTPUT) { // set pin hardware PWM value com.pi4j.wiringpi.Gpio.pwmWrite(pin.getAddress(), value); } else if(mode == PinMode.SOFT_PWM_OUTPUT) { // set pin software emulated PWM value com.pi4j.wiringpi.SoftPwm.softPwmWrite(pin.getAddress(), value); } else { // unsupported pin mode throw new InvalidPinModeException(pin, "Invalid pin mode [" + mode.getName() + "]; unable to setPwm(" + value + ")"); } // cache updated pin PWM value getPinCache(pin).setPwmValue(value); }
@Override public void setPwm(Pin pin, int value) { // validate pin if (!hasPin(pin)) { throw new InvalidPinException(pin); } // get pin configured mode PinMode mode = getMode(pin); // validate mode; set PWM value based on pin mode if (mode == PinMode.PWM_OUTPUT) { // set pin hardware PWM value com.pi4j.wiringpi.Gpio.pwmWrite(pin.getAddress(), value); } else if(mode == PinMode.SOFT_PWM_OUTPUT) { // set pin software emulated PWM value com.pi4j.wiringpi.SoftPwm.softPwmWrite(pin.getAddress(), value); } else { // unsupported pin mode throw new InvalidPinModeException(pin, "Invalid pin mode [" + mode.getName() + "]; unable to setPwm(" + value + ")"); } // cache updated pin PWM value getPinCache(pin).setPwmValue(value); }