use of com.pi4j.io.gpio.event.GpioPinListenerDigital 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