@Override public void pinValueChange(AnalogInputEvent event){ // we need to re-address the pin for Odroid boards int analogPinAddress = event.getPin() + AIN_ADDRESS_OFFSET; // iterate over the pin listeners map for (Pin pin : listeners.keySet()) { // dispatch this event to the listener // if a matching pin address is found if (pin.getAddress() == analogPinAddress) { dispatchPinAnalogValueChangeEvent(pin, event.getValue()); } } }
@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); }
@Override public void export(Pin pin, PinMode mode, PinState defaultState) { // no need to export an Odroid AIN pin if (mode == PinMode.ANALOG_INPUT) { // set the pin input/output mode setMode(pin, mode); return; } super.export(pin, mode, defaultState); }
@Override public boolean isExported(Pin pin) { // Odroid AIN pins are not exported if (getMode(pin) == PinMode.ANALOG_INPUT) { return false; } return super.isExported(pin); }
@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); }
public static GpioProvider getGpioProvider(Platform platform) { // create the provider based on the PlatformManager's selected platform switch (PlatformManager.getPlatform()) { case RASPBERRYPI: { return new RaspiGpioProvider(); } case BANANAPI: { return new BananaPiGpioProvider(); } case BANANAPRO: { return new BananaProGpioProvider(); } case ODROID: { return new OdroidGpioProvider(); } default: { // if a platform cannot be determine, then assume it's the default RaspberryPi return new RaspiGpioProvider(); } } }
OdroidGpioProvider.setAnalogInputPollingRate(100); // milliseconds OdroidGpioProvider.setAnalogInputListenerChangeThreshold(5);
@Override public boolean isExported(Pin pin) { // Odroid AIN pins are not exported if (getMode(pin) == PinMode.ANALOG_INPUT) { return false; } return super.isExported(pin); }
@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); }
return new OdroidGpioProvider();
OdroidGpioProvider.setAnalogInputPollingRate(100); // milliseconds OdroidGpioProvider.setAnalogInputListenerChangeThreshold(5);
@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); }
@Override public void export(Pin pin, PinMode mode, PinState defaultState) { // no need to export an Odroid AIN pin if (mode == PinMode.ANALOG_INPUT) { // set the pin input/output mode setMode(pin, mode); return; } super.export(pin, mode, defaultState); }
@Override public void pinValueChange(AnalogInputEvent event){ // we need to re-address the pin for Odroid boards int analogPinAddress = event.getPin() + AIN_ADDRESS_OFFSET; // iterate over the pin listeners map for (Pin pin : listeners.keySet()) { // dispatch this event to the listener // if a matching pin address is found if (pin.getAddress() == analogPinAddress) { dispatchPinAnalogValueChangeEvent(pin, event.getValue()); } } }