use of com.pi4j.gpio.extension.mcp.MCP3424GpioProvider in project openhab1-addons by openhab.
the class MCP3424Binding method bindGpioPin.
private void bindGpioPin(MCP3424BindingProvider provider, String itemName) {
try {
int address = provider.getBusAddress(itemName);
MCP3424GpioProvider mcp = mcpProviders.get(address);
if (mcp == null) {
try {
int gain = provider.getGain(itemName);
int resolution = provider.getResolution(itemName);
mcp = new MCP3424GpioProvider(I2CBus.BUS_1, address, resolution, gain);
mcp.setMonitorInterval(pollingInterval);
} catch (UnsupportedBusNumberException ex) {
throw new IllegalArgumentException("Tried to access not available I2C bus");
}
mcpProviders.put(address, mcp);
}
mcp.setMonitorEnabled(false);
Pin pin = provider.getPin(itemName);
GpioPinAnalogInput input = gpio.provisionAnalogInputPin(mcp, pin, itemName);
input.addListener(this);
input.setTag(provider.getItem(itemName));
gpioPins.put(itemName, input);
mcp.setEventThreshold(0, input);
mcp.setMonitorEnabled(true);
logger.debug("Provisioned analog input for {}", itemName);
} catch (IOException exception) {
logger.error("I/O error {}", exception.getMessage());
}
}
use of com.pi4j.gpio.extension.mcp.MCP3424GpioProvider 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);
}
}
Aggregations