diff --git a/code/espurna/sensors/EmonADC121Sensor.h b/code/espurna/sensors/EmonADC121Sensor.h index f06656c0..9e2f9a72 100644 --- a/code/espurna/sensors/EmonADC121Sensor.h +++ b/code/espurna/sensors/EmonADC121Sensor.h @@ -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; } // --------------------------------------------------------------------- diff --git a/code/espurna/sensors/EmonADS1X15Sensor.h b/code/espurna/sensors/EmonADS1X15Sensor.h index c4056bc9..9c00a604 100644 --- a/code/espurna/sensors/EmonADS1X15Sensor.h +++ b/code/espurna/sensors/EmonADS1X15Sensor.h @@ -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; } // --------------------------------------------------------------------- diff --git a/code/espurna/sensors/EmonSensor.h b/code/espurna/sensors/EmonSensor.h index 17d5e1ba..2fa6b180 100644 --- a/code/espurna/sensors/EmonSensor.h +++ b/code/espurna/sensors/EmonSensor.h @@ -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; } // ---------------------------------------------------------------------