Search in sources :

Example 1 with GpioPin

use of com.pi4j.io.gpio.GpioPin in project openhab1-addons by openhab.

the class MCP3424Binding method unBindGpioPin.

private void unBindGpioPin(MCP3424BindingProvider provider, String itemName) {
    GpioPin pin = gpioPins.remove(itemName);
    gpio.unprovisionPin(pin);
    logger.debug("Unbound item {}", itemName);
}
Also used : GpioPin(com.pi4j.io.gpio.GpioPin)

Example 2 with GpioPin

use of com.pi4j.io.gpio.GpioPin in project openhab1-addons by openhab.

the class MCP23017Binding method unBindGpioPin.

private void unBindGpioPin(MCP23017BindingProvider provider, String itemName) {
    GpioPin pin = gpioPins.remove(itemName);
    gpio.unprovisionPin(pin);
    logger.debug("Unbound item {}", itemName);
}
Also used : GpioPin(com.pi4j.io.gpio.GpioPin)

Example 3 with GpioPin

use of com.pi4j.io.gpio.GpioPin in project openhab1-addons by openhab.

the class MCP23017Binding method handleGpioPinDigitalStateChangeEvent.

/**
     * @{inheritDoc}
     */
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
    GpioPin pin = event.getPin();
    // Assume we are high...
    OpenClosedType state = OpenClosedType.CLOSED;
    if (event.getState() == PinState.LOW) {
        // To err is human...
        state = OpenClosedType.OPEN;
    }
    this.eventPublisher.postUpdate(pin.getName(), state);
    logger.debug("GPIO pin state change: {} = {}", pin, state);
}
Also used : GpioPin(com.pi4j.io.gpio.GpioPin) OpenClosedType(org.openhab.core.library.types.OpenClosedType)

Example 4 with GpioPin

use of com.pi4j.io.gpio.GpioPin in project openhab1-addons by openhab.

the class MCP3424Binding method handleGpioPinAnalogValueChangeEvent.

/**
     * Function will be called by Pi4J, if new conversion result is available.
     * On this time we can notify openhab, that something was changed.
     **/
@Override
public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event) {
    GpioPin pin = event.getPin();
    MCP3424GpioProvider provider = (MCP3424GpioProvider) pin.getProvider();
    if (pin.getTag() instanceof NumberItem) {
        double value = provider.getAnalogValue(pin.getPin());
        try {
            this.eventPublisher.postUpdate(pin.getName(), new DecimalType(value));
        } catch (NumberFormatException exception) {
            logger.warn("Unable to convert '{}' for item {} to number", String.valueOf(value), pin.getName());
        }
        logger.debug("GPIO channel change: {} = {}", pin, value);
    } else if (pin.getTag() instanceof DimmerItem) {
        double value = provider.getPercentValue(pin.getPin());
        try {
            this.eventPublisher.postUpdate(pin.getName(), new PercentType((int) value));
        } catch (NumberFormatException e) {
            logger.warn("Unable to convert '{}' for item {} to number", String.valueOf(value), pin.getName());
        }
        logger.debug("GPIO channel change: {} = {}", pin, value);
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) GpioPin(com.pi4j.io.gpio.GpioPin) MCP3424GpioProvider(com.pi4j.gpio.extension.mcp.MCP3424GpioProvider) DimmerItem(org.openhab.core.library.items.DimmerItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType)

Aggregations

GpioPin (com.pi4j.io.gpio.GpioPin)4 MCP3424GpioProvider (com.pi4j.gpio.extension.mcp.MCP3424GpioProvider)1 DimmerItem (org.openhab.core.library.items.DimmerItem)1 NumberItem (org.openhab.core.library.items.NumberItem)1 DecimalType (org.openhab.core.library.types.DecimalType)1 OpenClosedType (org.openhab.core.library.types.OpenClosedType)1 PercentType (org.openhab.core.library.types.PercentType)1