Browse Source

hlw8012: set ratios in begin(), after resistors are configured

mcspr-patch-1
Maxim Prokhorov 4 years ago
committed by Max Prokhorov
parent
commit
96347b7244
2 changed files with 5 additions and 3 deletions
  1. +0
    -3
      code/espurna/sensor.cpp
  2. +5
    -0
      code/espurna/sensors/HLW8012Sensor.h

+ 0
- 3
code/espurna/sensor.cpp View File

@ -1491,9 +1491,6 @@ void _sensorLoad() {
sensor->setSEL(getSetting("snsHlw8012SelGPIO", HLW8012_SEL_PIN));
sensor->setCF(getSetting("snsHlw8012CfGPIO", HLW8012_CF_PIN));
sensor->setCF1(getSetting("snsHlw8012Cf1GPIO", HLW8012_CF1_PIN));
sensor->setCurrentRatio(HLW8012_CURRENT_RATIO);
sensor->setVoltageRatio(HLW8012_VOLTAGE_RATIO);
sensor->setPowerRatio(HLW8012_POWER_RATIO);
sensor->setSELCurrent(HLW8012_SEL_CURRENT);
_sensors.push_back(sensor);
}


+ 5
- 0
code/espurna/sensors/HLW8012Sensor.h View File

@ -142,6 +142,11 @@ class HLW8012Sensor : public BaseEmonSensor {
// * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012
_hlw8012->setResistors(HLW8012_CURRENT_R, HLW8012_VOLTAGE_R_UP, HLW8012_VOLTAGE_R_DOWN);
// Also, adjust with ratio values that could be set in hardware profile
if (HLW8012_CURRENT_RATIO > 0.0) _hlw8012->setCurrentMultiplier(HLW8012_CURRENT_RATIO);
if (HLW8012_VOLTAGE_RATIO > 0.0) _hlw8012->setVoltageMultiplier(HLW8012_VOLTAGE_RATIO);
if (HLW8012_POWER_RATIO > 0.0) _hlw8012->setPowerMultiplier(HLW8012_POWER_RATIO);
// Handle interrupts
#if HLW8012_USE_INTERRUPTS && (!HLW8012_WAIT_FOR_WIFI)
_enableInterrupts(false);


Loading…
Cancel
Save