Browse Source

ExpectedPower method for EMON sensors

fastled
Xose Pérez 7 years ago
parent
commit
3ca68576f5
3 changed files with 25 additions and 8 deletions
  1. +2
    -1
      code/espurna/sensors/EmonADC121Sensor.h
  2. +8
    -4
      code/espurna/sensors/EmonADS1X15Sensor.h
  3. +15
    -3
      code/espurna/sensors/EmonSensor.h

+ 2
- 1
code/espurna/sensors/EmonADC121Sensor.h View File

@ -43,8 +43,9 @@ class EmonADC121Sensor : public EmonAnalogSensor {
}
void setAddress(unsigned char address) {
if (_address != address) _dirty = true;
if (_address == address) return;
_address = address;
_dirty = true;
}
// ---------------------------------------------------------------------


+ 8
- 4
code/espurna/sensors/EmonADS1X15Sensor.h View File

@ -111,23 +111,27 @@ class EmonADS1X15Sensor : public EmonSensor {
}
void setAddress(unsigned char address) {
if (_address != address) _dirty = true;
if (_address == address) return;
_address = address;
_dirty = true;
}
void setType(unsigned char type) {
if (_type != type) _dirty = true;
if (_type == type) return;
_type = type;
_dirty = true;
}
void setMask(unsigned char mask) {
if (_mask != mask) _dirty = true;
if (_mask == mask) return;
_mask = mask;
_dirty = true;
}
void setGain(unsigned int gain) {
if (_gain != gain) _dirty = true;
if (_gain == gain) return;
_gain = gain;
_dirty = true;
}
// ---------------------------------------------------------------------


+ 15
- 3
code/espurna/sensors/EmonSensor.h View File

@ -32,19 +32,31 @@ class EmonSensor : public BaseSensor {
}
void setVoltage(double voltage) {
if (_voltage != voltage) _dirty = true;
if (_voltage == voltage) return;
_voltage = voltage;
_dirty = true;
}
void setReference(double reference) {
if (_reference != reference) _dirty = true;
if (_reference == reference) return;
_reference = reference;
_dirty = true;
}
void setCurrentRatio(unsigned char channel, double current_ratio) {
if (channel >= _channels) return;
if (_current_ratio[channel] != current_ratio) _dirty = true;
if (_current_ratio[channel] == current_ratio) return;
_current_ratio[channel] = current_ratio;
_dirty = true;
}
void expectedPower(unsigned char channel, unsigned int expected) {
if (channel >= _channels) return;
unsigned int actual = _current[channel] * _voltage;
if (actual == 0) return;
if (expected == actual) return;
_current_ratio[channel] = _current_ratio[channel] * (expected / actual);
_dirty = true;
}
// ---------------------------------------------------------------------


Loading…
Cancel
Save