diff --git a/lib/HLW8012_1.1.1/src/HLW8012.cpp b/lib/HLW8012_1.1.1/src/HLW8012.cpp index b6786eb875..d52d1a0a25 100644 --- a/lib/HLW8012_1.1.1/src/HLW8012.cpp +++ b/lib/HLW8012_1.1.1/src/HLW8012.cpp @@ -205,27 +205,47 @@ void HLW8012::resetEnergy() { _cf_pulse_count_total = 0; } -void HLW8012::expectedCurrent(float value) { +void HLW8012::expectedCurrent(float expected) { bool valid = false; if (static_cast(_current) == 0) getCurrent(valid); const float current = _current; // Copy volatile - if (valid && static_cast(current) > 0) _current_multiplier *= (value / current); + if (valid && static_cast(current) > 0) _current_multiplier *= (expected / current); } -void HLW8012::expectedVoltage(float value) { +void HLW8012::expectedVoltage(float expected) { bool valid = false; if (static_cast(_voltage) == 0) getVoltage(valid); const float voltage = _voltage; - if (valid && static_cast(voltage) > 0) _voltage_multiplier *= (value / voltage); + if (valid && static_cast(voltage) > 0) _voltage_multiplier *= (expected / voltage); } -void HLW8012::expectedActivePower(float value) { +void HLW8012::expectedActivePower(float expected) { bool valid = false; if (static_cast(_power) == 0) getActivePower(valid); const float power = _power; - if (valid && static_cast(power) > 0) _power_multiplier *= (value / power); + if (valid && static_cast(power) > 0) _power_multiplier *= (expected / power); } +void HLW8012::expectedCurrent(float expected, float measured) { + if (static_cast(expected) == 0 || static_cast(measured) == 0) + return; + _current_multiplier *= (expected / measured); +} + +void HLW8012::expectedVoltage(float expected, float measured) { + if (static_cast(expected) == 0 || static_cast(measured) == 0) + return; + _voltage_multiplier *= (expected / measured); +} + +void HLW8012::expectedActivePower(float expected, float measured) { + if (static_cast(expected) == 0 || static_cast(measured) == 0) + return; + _power_multiplier *= (expected / measured); +} + + + void HLW8012::resetMultipliers() { _calculateDefaultMultipliers(); } diff --git a/lib/HLW8012_1.1.1/src/HLW8012.h b/lib/HLW8012_1.1.1/src/HLW8012.h index 2c3d2def82..f256da7393 100644 --- a/lib/HLW8012_1.1.1/src/HLW8012.h +++ b/lib/HLW8012_1.1.1/src/HLW8012.h @@ -104,9 +104,14 @@ class HLW8012 { void setResistors(float current, float voltage_upstream, float voltage_downstream); - void expectedCurrent(float current); - void expectedVoltage(float current); - void expectedActivePower(float power); + void expectedCurrent(float expected); + void expectedVoltage(float expected); + void expectedActivePower(float expected); + + void expectedCurrent(float expected, float measured); + void expectedVoltage(float expected, float measured); + void expectedActivePower(float expected, float measured); + float getCurrentMultiplier() { return _current_multiplier; }; float getVoltageMultiplier() { return _voltage_multiplier; };