public void setAnalogValue(Pin pin, double value) { // cache pin state getPinCache(pin).setAnalogValue(value); // dispatch event dispatchPinAnalogValueChangeEvent(pin, value); }
getPinCache(pin).setAnalogValue(newValue);
@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); }
getPinCache(pin).setAnalogValue(newValue);
@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); }
getPinCache(pin).setAnalogValue(value); return value;
@Override public double getValue(Pin pin) { // the getMode() will validate the pin exists with the hasPin() function PinMode mode = getMode(pin); // handle analog input reading for Odroid boards if (mode == PinMode.ANALOG_INPUT) { // read latest analog input value from WiringPi // we need to re-address the pin for Odroid boards (analog_address = assigned_pin_address - AIN_ADDRESS_OFFSET) double value = com.pi4j.wiringpi.Gpio.analogRead(pin.getAddress() - AIN_ADDRESS_OFFSET); // cache latest analog input value getPinCache(pin).setAnalogValue(value); // return latest analog input value return value; } return super.getValue(pin); }
getPinCache(pin).setAnalogValue(value); return value;
@Override public double getValue(Pin pin) { // the getMode() will validate the pin exists with the hasPin() function PinMode mode = getMode(pin); // handle analog input reading for Odroid boards if (mode == PinMode.ANALOG_INPUT) { // read latest analog input value from WiringPi // we need to re-address the pin for Odroid boards (analog_address = assigned_pin_address - AIN_ADDRESS_OFFSET) double value = com.pi4j.wiringpi.Gpio.analogRead(pin.getAddress() - AIN_ADDRESS_OFFSET); // cache latest analog input value getPinCache(pin).setAnalogValue(value); // return latest analog input value return value; } return super.getValue(pin); }
/** * This method will perform an immediate data acquisition directly to the ADC chip to get the requested pin's input * conversion value. * * @param pin requested input pin to acquire conversion value * * @return conversion value for requested analog input pin * @throws IOException */ @Override public double getImmediateValue(final Pin pin) throws IOException { if (isInitiated()) { // read in value from ADC chip final double value = readAnalog(toCommand((short) pin.getAddress())); // validate value withing acceptable range if (value >= MIN_VALUE && value <= MAX_VALUE) { getPinCache(pin).setAnalogValue(value); return value; } } return INVALID_VALUE; }