Search in sources :

Example 1 with GpioPinDigitalStateChangeEvent

use of com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent 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);
    }
}
Also used : GpioPinDigitalInput(com.pi4j.io.gpio.GpioPinDigitalInput) GpioPinDigitalStateChangeEvent(com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent) GpioPinListenerDigital(com.pi4j.io.gpio.event.GpioPinListenerDigital)

Aggregations

GpioPinDigitalInput (com.pi4j.io.gpio.GpioPinDigitalInput)1 GpioPinDigitalStateChangeEvent (com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent)1 GpioPinListenerDigital (com.pi4j.io.gpio.event.GpioPinListenerDigital)1