diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index f9a055d5..5c5e4fc8 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -2658,10 +2658,11 @@ #define HLW8012_POWER_RATIO 2533110 #define HLW8012_INTERRUPT_ON FALLING - #define ALEXA_SUPPORT 0 - #define DOMOTICZ_SUPPORT 0 - #define HOMEASSISTANT_SUPPORT 0 - #define THINGSPEAK_SUPPORT 0 + //#define HLW8012_WAIT_FOR_WIFI 1 + //#define ALEXA_SUPPORT 0 + //#define DOMOTICZ_SUPPORT 0 + //#define HOMEASSISTANT_SUPPORT 0 + //#define THINGSPEAK_SUPPORT 0 // ---------------------------------------------------------------------------------------- // Homecube 16A is similar but some pins differ and it also has RGB LEDs diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index ad725601..33aef324 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -441,8 +441,8 @@ #endif #ifndef HLW8012_WAIT_FOR_WIFI -#define HLW8012_WAIT_FOR_WIFI 1 // Enable interrupts only after wifi connection - // has been established +#define HLW8012_WAIT_FOR_WIFI 0 // Weather to enable interrupts only after + // wifi connection has been stablished #endif #ifndef HLW8012_INTERRUPT_ON diff --git a/code/espurna/sensors/HLW8012Sensor.h b/code/espurna/sensors/HLW8012Sensor.h index 1f7d24a7..bd5393f8 100644 --- a/code/espurna/sensors/HLW8012Sensor.h +++ b/code/espurna/sensors/HLW8012Sensor.h @@ -9,8 +9,6 @@ #include "Arduino.h" #include "BaseSensor.h" - -#include #include class HLW8012Sensor : public BaseSensor { @@ -233,29 +231,34 @@ class HLW8012Sensor : public BaseSensor { void _enableInterrupts(bool value) { - static bool state = false; static unsigned char _interrupt_cf = GPIO_NONE; static unsigned char _interrupt_cf1 = GPIO_NONE; - if (value == state) return; - state = value; - if (value) { - if (_interrupt_cf != GPIO_NONE) _detach(_interrupt_cf); - _attach(this, _cf, HLW8012_INTERRUPT_ON); - _interrupt_cf = _cf; + if (_interrupt_cf != _cf) { + if (_interrupt_cf != GPIO_NONE) _detach(_interrupt_cf); + _attach(this, _cf, HLW8012_INTERRUPT_ON); + _interrupt_cf = _cf; + } - if (_interrupt_cf1 != GPIO_NONE) _detach(_interrupt_cf1); - _attach(this, _cf1, HLW8012_INTERRUPT_ON); - _interrupt_cf1 = _cf1; + if (_interrupt_cf1 != _cf1) { + if (_interrupt_cf1 != GPIO_NONE) _detach(_interrupt_cf1); + _attach(this, _cf1, HLW8012_INTERRUPT_ON); + _interrupt_cf1 = _cf1; + } } else { - _detach(_cf); - _detach(_cf1); - _interrupt_cf = GPIO_NONE; - _interrupt_cf1 = GPIO_NONE; + if (GPIO_NONE != _interrupt_cf) { + _detach(_interrupt_cf); + _interrupt_cf = GPIO_NONE; + } + + if (GPIO_NONE != _interrupt_cf1) { + _detach(_interrupt_cf1); + _interrupt_cf1 = GPIO_NONE; + } }