use of com.pi4j.io.gpio.GpioPinDigital in project OpenMUC by isc-konstanz.
the class GpioDriver method newDevice.
@Override
public GpioPin newDevice(Address address, Settings settings) throws ArgumentSyntaxException, ConnectionException {
try {
GpioConfigs configs = new GpioConfigs(address, settings);
GpioPin connection;
logger.trace("Connect Raspberry Pi {} pin {}", configs.getPinMode().getName(), configs.getPin());
Pin p = RaspiPin.getPinByAddress(configs.getPin());
if (p == null) {
throw new ConnectionException("Unable to configure GPIO pin: " + configs.getPin());
}
GpioPinDigital pin = null;
switch(configs.getPinMode()) {
case DIGITAL_INPUT:
pin = gpio.provisionDigitalInputPin(p, configs.getPullResistance());
if (configs.isCounter()) {
connection = new EdgeCounter(pin, configs.getPullResistance(), configs.getBounceTime());
} else {
connection = new InputPin(pin);
}
break;
case DIGITAL_OUTPUT:
pin = gpio.provisionDigitalOutputPin(p, configs.getDefaultState());
connection = new OutputPin(pin);
break;
default:
throw new ArgumentSyntaxException("GPIO pins not supported for mode: " + configs.getPinMode());
}
pin.setShutdownOptions(true, configs.getShutdownState(), configs.getShutdownPullResistance());
return connection;
} catch (RuntimeException e) {
throw new ArgumentSyntaxException("Unable to configure GPIO pin: " + e);
}
}
Aggregations