|
@ -43,6 +43,10 @@ class PulseMeterSensor : public BaseSensor { |
|
|
if (ratio > 0) _ratio = ratio; |
|
|
if (ratio > 0) _ratio = ratio; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void setDebounceTime(unsigned long debounce) { |
|
|
|
|
|
_debounce = debounce; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------- |
|
|
// --------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
unsigned char getGPIO() { |
|
|
unsigned char getGPIO() { |
|
@ -53,6 +57,10 @@ class PulseMeterSensor : public BaseSensor { |
|
|
return _ratio; |
|
|
return _ratio; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned long getDebounceTime() { |
|
|
|
|
|
return _debounce; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------- |
|
|
// --------------------------------------------------------------------- |
|
|
// Sensors API |
|
|
// Sensors API |
|
|
// --------------------------------------------------------------------- |
|
|
// --------------------------------------------------------------------- |
|
@ -113,7 +121,10 @@ class PulseMeterSensor : public BaseSensor { |
|
|
|
|
|
|
|
|
// Handle interrupt calls |
|
|
// Handle interrupt calls |
|
|
void ICACHE_RAM_ATTR handleInterrupt(unsigned char gpio) { |
|
|
void ICACHE_RAM_ATTR handleInterrupt(unsigned char gpio) { |
|
|
if (gpio == _gpio) { |
|
|
|
|
|
|
|
|
static unsigned long last = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (millis() - last > _debounce) { |
|
|
|
|
|
last = millis(); |
|
|
_pulses++; |
|
|
_pulses++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -151,6 +162,7 @@ class PulseMeterSensor : public BaseSensor { |
|
|
unsigned char _previous = GPIO_NONE; |
|
|
unsigned char _previous = GPIO_NONE; |
|
|
unsigned char _gpio = GPIO_NONE; |
|
|
unsigned char _gpio = GPIO_NONE; |
|
|
unsigned long _ratio = PULSEMETER_ENERGY_RATIO; |
|
|
unsigned long _ratio = PULSEMETER_ENERGY_RATIO; |
|
|
|
|
|
unsigned long _debounce = PULSEMETER_DEBOUNCE; |
|
|
|
|
|
|
|
|
double _active = 0; |
|
|
double _active = 0; |
|
|
double _energy = 0; |
|
|
double _energy = 0; |
|
|