use of com.pi4j.io.gpio.GpioPinDigitalInput in project openhab1-addons by openhab.
the class MCP23017Binding method bindGpioPin.
private void bindGpioPin(MCP23017BindingProvider provider, String itemName) {
try {
int address = provider.getBusAddress(itemName);
MCP23017GpioProvider mcp = mcpProviders.get(address);
if (mcp == null) {
try {
mcp = new MCP23017GpioProvider(I2CBus.BUS_1, address);
mcp.setPollingTime(pollingInterval);
} catch (UnsupportedBusNumberException ex) {
throw new IllegalArgumentException("Tried to access not available I2C bus");
}
mcpProviders.put(address, mcp);
}
Pin pin = provider.getPin(itemName);
PinMode mode = provider.getPinMode(itemName);
if (mode.equals(PinMode.DIGITAL_OUTPUT)) {
GpioPinDigitalOutput output = gpio.provisionDigitalOutputPin(mcp, pin, itemName, provider.getDefaultState(itemName));
gpioPins.put(itemName, output);
logger.debug("Provisioned digital output for {}", itemName);
} else if (mode.equals(PinMode.DIGITAL_INPUT)) {
GpioPinDigitalInput input = gpio.provisionDigitalInputPin(mcp, pin, itemName, PinPullResistance.OFF);
input.setDebounce(20);
input.addListener(this);
gpioPins.put(itemName, input);
logger.debug("Provisioned digital input for {}", itemName);
} else {
throw new IllegalArgumentException("Invalid Pin Mode in config " + mode.name());
}
} catch (IOException exception) {
logger.error("I/O error {}", exception.getMessage());
}
}
use of com.pi4j.io.gpio.GpioPinDigitalInput in project SmartApplianceEnabler by camueller.
the class S0ElectricityMeter method start.
public void start() {
pulseElectricityMeter.setImpulsesPerKwh(impulsesPerKwh);
pulseElectricityMeter.setMeasurementInterval(measurementInterval);
pulseElectricityMeter.setPowerOnAlways(powerOnAlways);
if (getGpioController() != null) {
final GpioPinDigitalInput input = getGpioController().provisionDigitalInputPin(getGpio(), getPinPullResistance());
input.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
logger.debug("GPIO " + event.getPin() + " changed to " + event.getState());
if (event.getState() == PinState.HIGH) {
pulseElectricityMeter.addTimestampAndMaintain(System.currentTimeMillis());
}
}
});
logger.info("Start metering using " + getGpio());
} else {
logGpioAccessDisabled(logger);
}
}
Aggregations