@Override public void setPwmRange(Pin pin, int range){ // 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.pwmSetRange(range); } else if(mode == PinMode.SOFT_PWM_OUTPUT) { // first, stop the software emulated PWM driver for this pin com.pi4j.wiringpi.SoftPwm.softPwmStop(pin.getAddress()); // update the PWM range for this pin com.pi4j.wiringpi.SoftPwm.softPwmCreate(pin.getAddress(), 0, range); } else { // unsupported operation throw new UnsupportedOperationException(); } }
@Override public void setPwmRange(Pin pin, int range){ // 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.pwmSetRange(range); } else if(mode == PinMode.SOFT_PWM_OUTPUT) { // first, stop the software emulated PWM driver for this pin com.pi4j.wiringpi.SoftPwm.softPwmStop(pin.getAddress()); // update the PWM range for this pin com.pi4j.wiringpi.SoftPwm.softPwmCreate(pin.getAddress(), 0, range); } else { // unsupported operation throw new UnsupportedOperationException(); } }
@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. }
@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); }