Search in sources :

Example 1 with GpioPinDigital

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);
    }
}
Also used : GpioPinDigital(com.pi4j.io.gpio.GpioPinDigital) Pin(com.pi4j.io.gpio.Pin) RaspiPin(com.pi4j.io.gpio.RaspiPin) EdgeCounter(org.openmuc.framework.driver.rpi.gpio.count.EdgeCounter) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Aggregations

GpioPinDigital (com.pi4j.io.gpio.GpioPinDigital)1 Pin (com.pi4j.io.gpio.Pin)1 RaspiPin (com.pi4j.io.gpio.RaspiPin)1 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)1 EdgeCounter (org.openmuc.framework.driver.rpi.gpio.count.EdgeCounter)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1