Browse Source

Fix read call in EmonAnalog and EmonADC121

fastled
Xose Pérez 7 years ago
parent
commit
65831b95e4
3 changed files with 13 additions and 13 deletions
  1. +1
    -1
      code/espurna/config/sensors.h
  2. +6
    -6
      code/espurna/sensors/EmonADC121Sensor.h
  3. +6
    -6
      code/espurna/sensors/EmonAnalogSensor.h

+ 1
- 1
code/espurna/config/sensors.h View File

@ -156,7 +156,7 @@
//--------------------------------------------------------------------------------
#ifndef EMON_ANALOG_SUPPORT
#define EMON_ANALOG_SUPPORT 0 // Do not build support by default
#define EMON_ANALOG_SUPPORT 1 // Do not build support by default
#endif
#define EMON_ANALOG_CURRENT_RATIO 30 // Current ratio in the clamp (30V/1A)


+ 6
- 6
code/espurna/sensors/EmonADC121Sensor.h View File

@ -50,7 +50,7 @@ class EmonADC121Sensor : public EmonSensor {
#endif
// warmup
read(_address);
read(_address, _pivot);
}
@ -90,11 +90,10 @@ class EmonADC121Sensor : public EmonSensor {
// Cache the value
static unsigned long last = 0;
static double current = 0;
if ((last == 0) || (millis() - last > 1000)) {
current = read(0, _pivot);
_current = read(0, _pivot);
#if EMON_REPORT_ENERGY
_energy += (current * _voltage * (millis() - last) / 1000);
_energy += (_current * _voltage * (millis() - last) / 1000);
#endif
last = millis();
}
@ -102,10 +101,10 @@ class EmonADC121Sensor : public EmonSensor {
// Report
unsigned char i = 0;
#if EMON_REPORT_CURRENT
if (index == i++) return current;
if (index == i++) return _current;
#endif
#if EMON_REPORT_POWER
if (index == i++) return current * _voltage;
if (index == i++) return _current * _voltage;
#endif
#if EMON_REPORT_ENERGY
if (index == i) return _energy;
@ -146,6 +145,7 @@ class EmonADC121Sensor : public EmonSensor {
unsigned char _address;
double _pivot = 0;
double _current = 0;
#if EMON_REPORT_ENERGY
unsigned long _energy = 0;
#endif


+ 6
- 6
code/espurna/sensors/EmonAnalogSensor.h View File

@ -22,7 +22,7 @@ class EmonAnalogSensor : public EmonSensor {
pinMode(gpio, INPUT);
// warmup
read(_gpio);
read(_gpio, _pivot);
}
@ -62,11 +62,10 @@ class EmonAnalogSensor : public EmonSensor {
// Cache the value
static unsigned long last = 0;
static double current = 0;
if ((last == 0) || (millis() - last > 1000)) {
current = read(0, _pivot);
_current = read(0, _pivot);
#if EMON_REPORT_ENERGY
_energy += (current * _voltage * (millis() - last) / 1000);
_energy += (_current * _voltage * (millis() - last) / 1000);
#endif
last = millis();
}
@ -74,10 +73,10 @@ class EmonAnalogSensor : public EmonSensor {
// Report
unsigned char i=0;
#if EMON_REPORT_CURRENT
if (index == i++) return current;
if (index == i++) return _current;
#endif
#if EMON_REPORT_POWER
if (index == i++) return current * _voltage;
if (index == i++) return _current * _voltage;
#endif
#if EMON_REPORT_ENERGY
if (index == i) return _energy;
@ -96,6 +95,7 @@ class EmonAnalogSensor : public EmonSensor {
unsigned char _gpio;
double _pivot = 0;
double _current;
#if EMON_REPORT_ENERGY
unsigned long _energy = 0;
#endif


Loading…
Cancel
Save