|
@ -7,7 +7,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com> |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#if ENABLE_POW
|
|
|
|
|
|
|
|
|
#if ENABLE_HLW8012
|
|
|
|
|
|
|
|
|
#include <HLW8012.h>
|
|
|
#include <HLW8012.h>
|
|
|
#include <Hash.h>
|
|
|
#include <Hash.h>
|
|
@ -15,7 +15,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com> |
|
|
#include <EEPROM.h>
|
|
|
#include <EEPROM.h>
|
|
|
|
|
|
|
|
|
HLW8012 hlw8012; |
|
|
HLW8012 hlw8012; |
|
|
bool _powEnabled = false; |
|
|
|
|
|
|
|
|
bool _hlw8012Enabled = false; |
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// POW
|
|
|
// POW
|
|
@ -31,18 +31,18 @@ void ICACHE_RAM_ATTR hlw8012_cf_interrupt() { |
|
|
hlw8012.cf_interrupt(); |
|
|
hlw8012.cf_interrupt(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void powEnable(bool status) { |
|
|
|
|
|
_powEnabled = status; |
|
|
|
|
|
if (_powEnabled) { |
|
|
|
|
|
#if POW_USE_INTERRUPTS == 1
|
|
|
|
|
|
attachInterrupt(POW_CF1_PIN, hlw8012_cf1_interrupt, CHANGE); |
|
|
|
|
|
attachInterrupt(POW_CF_PIN, hlw8012_cf_interrupt, CHANGE); |
|
|
|
|
|
|
|
|
void hlw8012Enable(bool status) { |
|
|
|
|
|
_hlw8012Enabled = status; |
|
|
|
|
|
if (_hlw8012Enabled) { |
|
|
|
|
|
#if HLW8012_USE_INTERRUPTS == 1
|
|
|
|
|
|
attachInterrupt(HLW8012_CF1_PIN, hlw8012_cf1_interrupt, CHANGE); |
|
|
|
|
|
attachInterrupt(HLW8012_CF_PIN, hlw8012_cf_interrupt, CHANGE); |
|
|
#endif
|
|
|
#endif
|
|
|
DEBUG_MSG_P(PSTR("[POW] Enabled\n")); |
|
|
DEBUG_MSG_P(PSTR("[POW] Enabled\n")); |
|
|
} else { |
|
|
} else { |
|
|
#if POW_USE_INTERRUPTS == 1
|
|
|
|
|
|
detachInterrupt(POW_CF1_PIN); |
|
|
|
|
|
detachInterrupt(POW_CF_PIN); |
|
|
|
|
|
|
|
|
#if HLW8012_USE_INTERRUPTS == 1
|
|
|
|
|
|
detachInterrupt(HLW8012_CF1_PIN); |
|
|
|
|
|
detachInterrupt(HLW8012_CF_PIN); |
|
|
#endif
|
|
|
#endif
|
|
|
DEBUG_MSG_P(PSTR("[POW] Disabled\n")); |
|
|
DEBUG_MSG_P(PSTR("[POW] Disabled\n")); |
|
|
} |
|
|
} |
|
@ -50,13 +50,13 @@ void powEnable(bool status) { |
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
void powSaveCalibration() { |
|
|
|
|
|
|
|
|
void hlw8012SaveCalibration() { |
|
|
setSetting("powPowerMult", hlw8012.getPowerMultiplier()); |
|
|
setSetting("powPowerMult", hlw8012.getPowerMultiplier()); |
|
|
setSetting("powCurrentMult", hlw8012.getCurrentMultiplier()); |
|
|
setSetting("powCurrentMult", hlw8012.getCurrentMultiplier()); |
|
|
setSetting("powVoltageMult", hlw8012.getVoltageMultiplier()); |
|
|
setSetting("powVoltageMult", hlw8012.getVoltageMultiplier()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void powRetrieveCalibration() { |
|
|
|
|
|
|
|
|
void hlw8012RetrieveCalibration() { |
|
|
double value; |
|
|
double value; |
|
|
value = getSetting("powPowerMult", 0).toFloat(); |
|
|
value = getSetting("powPowerMult", 0).toFloat(); |
|
|
if (value > 0) hlw8012.setPowerMultiplier((int) value); |
|
|
if (value > 0) hlw8012.setPowerMultiplier((int) value); |
|
@ -66,55 +66,55 @@ void powRetrieveCalibration() { |
|
|
if (value > 0) hlw8012.setVoltageMultiplier((int) value); |
|
|
if (value > 0) hlw8012.setVoltageMultiplier((int) value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void powSetExpectedActivePower(unsigned int power) { |
|
|
|
|
|
|
|
|
void hlw8012SetExpectedActivePower(unsigned int power) { |
|
|
if (power > 0) { |
|
|
if (power > 0) { |
|
|
hlw8012.expectedActivePower(power); |
|
|
hlw8012.expectedActivePower(power); |
|
|
powSaveCalibration(); |
|
|
|
|
|
|
|
|
hlw8012SaveCalibration(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void powSetExpectedCurrent(double current) { |
|
|
|
|
|
|
|
|
void hlw8012SetExpectedCurrent(double current) { |
|
|
if (current > 0) { |
|
|
if (current > 0) { |
|
|
hlw8012.expectedCurrent(current); |
|
|
hlw8012.expectedCurrent(current); |
|
|
powSaveCalibration(); |
|
|
|
|
|
|
|
|
hlw8012SaveCalibration(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void powSetExpectedVoltage(unsigned int voltage) { |
|
|
|
|
|
|
|
|
void hlw8012SetExpectedVoltage(unsigned int voltage) { |
|
|
if (voltage > 0) { |
|
|
if (voltage > 0) { |
|
|
hlw8012.expectedVoltage(voltage); |
|
|
hlw8012.expectedVoltage(voltage); |
|
|
powSaveCalibration(); |
|
|
|
|
|
|
|
|
hlw8012SaveCalibration(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void powReset() { |
|
|
|
|
|
|
|
|
void hlw8012Reset() { |
|
|
hlw8012.resetMultipliers(); |
|
|
hlw8012.resetMultipliers(); |
|
|
powSaveCalibration(); |
|
|
|
|
|
|
|
|
hlw8012SaveCalibration(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
unsigned int getActivePower() { |
|
|
unsigned int getActivePower() { |
|
|
unsigned int power = hlw8012.getActivePower(); |
|
|
unsigned int power = hlw8012.getActivePower(); |
|
|
if (POW_MIN_POWER > power || power > POW_MAX_POWER) power = 0; |
|
|
|
|
|
|
|
|
if (HLW8012_MIN_POWER > power || power > HLW8012_MAX_POWER) power = 0; |
|
|
return power; |
|
|
return power; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
unsigned int getApparentPower() { |
|
|
unsigned int getApparentPower() { |
|
|
unsigned int power = hlw8012.getApparentPower(); |
|
|
unsigned int power = hlw8012.getApparentPower(); |
|
|
if (POW_MIN_POWER > power || power > POW_MAX_POWER) power = 0; |
|
|
|
|
|
|
|
|
if (HLW8012_MIN_POWER > power || power > HLW8012_MAX_POWER) power = 0; |
|
|
return power; |
|
|
return power; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
unsigned int getReactivePower() { |
|
|
unsigned int getReactivePower() { |
|
|
unsigned int power = hlw8012.getReactivePower(); |
|
|
unsigned int power = hlw8012.getReactivePower(); |
|
|
if (POW_MIN_POWER > power || power > POW_MAX_POWER) power = 0; |
|
|
|
|
|
|
|
|
if (HLW8012_MIN_POWER > power || power > HLW8012_MAX_POWER) power = 0; |
|
|
return power; |
|
|
return power; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
double getCurrent() { |
|
|
double getCurrent() { |
|
|
double current = hlw8012.getCurrent(); |
|
|
double current = hlw8012.getCurrent(); |
|
|
if (POW_MIN_CURRENT > current || current > POW_MAX_CURRENT) current = 0; |
|
|
|
|
|
|
|
|
if (HLW8012_MIN_CURRENT > current || current > HLW8012_MAX_CURRENT) current = 0; |
|
|
return current; |
|
|
return current; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -128,7 +128,7 @@ double getPowerFactor() { |
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
void powSetup() { |
|
|
|
|
|
|
|
|
void hlw8012Setup() { |
|
|
|
|
|
|
|
|
// Initialize HLW8012
|
|
|
// Initialize HLW8012
|
|
|
// void begin(unsigned char cf_pin, unsigned char cf1_pin, unsigned char sel_pin, unsigned char currentWhen = HIGH, bool use_interrupts = false, unsigned long pulse_timeout = PULSE_TIMEOUT);
|
|
|
// void begin(unsigned char cf_pin, unsigned char cf1_pin, unsigned char sel_pin, unsigned char currentWhen = HIGH, bool use_interrupts = false, unsigned long pulse_timeout = PULSE_TIMEOUT);
|
|
@ -136,10 +136,10 @@ void powSetup() { |
|
|
// * currentWhen is the value in sel_pin to select current sampling
|
|
|
// * currentWhen is the value in sel_pin to select current sampling
|
|
|
// * set use_interrupts to true to use interrupts to monitor pulse widths
|
|
|
// * set use_interrupts to true to use interrupts to monitor pulse widths
|
|
|
// * leave pulse_timeout to the default value, recommended when using interrupts
|
|
|
// * leave pulse_timeout to the default value, recommended when using interrupts
|
|
|
#if POW_USE_INTERRUPTS
|
|
|
|
|
|
hlw8012.begin(POW_CF_PIN, POW_CF1_PIN, POW_SEL_PIN, POW_SEL_CURRENT, true); |
|
|
|
|
|
|
|
|
#if HLW8012_USE_INTERRUPTS
|
|
|
|
|
|
hlw8012.begin(HLW8012_CF_PIN, HLW8012_CF1_PIN, HLW8012_SEL_PIN, HLW8012_SEL_CURRENT, true); |
|
|
#else
|
|
|
#else
|
|
|
hlw8012.begin(POW_CF_PIN, POW_CF1_PIN, POW_SEL_PIN, POW_SEL_CURRENT, false, 1000000); |
|
|
|
|
|
|
|
|
hlw8012.begin(HLW8012_CF_PIN, HLW8012_CF1_PIN, HLW8012_SEL_PIN, HLW8012_SEL_CURRENT, false, 1000000); |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
// These values are used to calculate current, voltage and power factors as per datasheet formula
|
|
|
// These values are used to calculate current, voltage and power factors as per datasheet formula
|
|
@ -147,28 +147,28 @@ void powSetup() { |
|
|
// * The CURRENT_RESISTOR is the 1milliOhm copper-manganese resistor in series with the main line
|
|
|
// * The CURRENT_RESISTOR is the 1milliOhm copper-manganese resistor in series with the main line
|
|
|
// * The VOLTAGE_RESISTOR_UPSTREAM are the 5 470kOhm resistors in the voltage divider that feeds the V2P pin in the HLW8012
|
|
|
// * The VOLTAGE_RESISTOR_UPSTREAM are the 5 470kOhm resistors in the voltage divider that feeds the V2P pin in the HLW8012
|
|
|
// * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012
|
|
|
// * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012
|
|
|
hlw8012.setResistors(POW_CURRENT_R, POW_VOLTAGE_R_UP, POW_VOLTAGE_R_DOWN); |
|
|
|
|
|
|
|
|
hlw8012.setResistors(HLW8012_CURRENT_R, HLW8012_VOLTAGE_R_UP, HLW8012_VOLTAGE_R_DOWN); |
|
|
|
|
|
|
|
|
// Retrieve calibration values
|
|
|
// Retrieve calibration values
|
|
|
powRetrieveCalibration(); |
|
|
|
|
|
|
|
|
hlw8012RetrieveCalibration(); |
|
|
|
|
|
|
|
|
// API definitions
|
|
|
// API definitions
|
|
|
apiRegister(POW_POWER_TOPIC, POW_POWER_TOPIC, [](char * buffer, size_t len) { |
|
|
|
|
|
|
|
|
apiRegister(HLW8012_POWER_TOPIC, HLW8012_POWER_TOPIC, [](char * buffer, size_t len) { |
|
|
snprintf(buffer, len, "%d", getActivePower()); |
|
|
snprintf(buffer, len, "%d", getActivePower()); |
|
|
}); |
|
|
}); |
|
|
apiRegister(POW_CURRENT_TOPIC, POW_CURRENT_TOPIC, [](char * buffer, size_t len) { |
|
|
|
|
|
|
|
|
apiRegister(HLW8012_CURRENT_TOPIC, HLW8012_CURRENT_TOPIC, [](char * buffer, size_t len) { |
|
|
dtostrf(getCurrent(), len-1, 3, buffer); |
|
|
dtostrf(getCurrent(), len-1, 3, buffer); |
|
|
}); |
|
|
}); |
|
|
apiRegister(POW_VOLTAGE_TOPIC, POW_VOLTAGE_TOPIC, [](char * buffer, size_t len) { |
|
|
|
|
|
|
|
|
apiRegister(HLW8012_VOLTAGE_TOPIC, HLW8012_VOLTAGE_TOPIC, [](char * buffer, size_t len) { |
|
|
snprintf(buffer, len, "%d", getVoltage()); |
|
|
snprintf(buffer, len, "%d", getVoltage()); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void powLoop() { |
|
|
|
|
|
|
|
|
void hlw8012Loop() { |
|
|
|
|
|
|
|
|
static unsigned long last_update = 0; |
|
|
static unsigned long last_update = 0; |
|
|
static unsigned char report_count = POW_REPORT_EVERY; |
|
|
|
|
|
|
|
|
static unsigned char report_count = HLW8012_REPORT_EVERY; |
|
|
|
|
|
|
|
|
static bool power_spike = false; |
|
|
static bool power_spike = false; |
|
|
static unsigned long power_sum = 0; |
|
|
static unsigned long power_sum = 0; |
|
@ -186,7 +186,7 @@ void powLoop() { |
|
|
|
|
|
|
|
|
// POW is disabled while there is no internet connection
|
|
|
// POW is disabled while there is no internet connection
|
|
|
// When the HLW8012 measurements are enabled back we reset the timer
|
|
|
// When the HLW8012 measurements are enabled back we reset the timer
|
|
|
if (!_powEnabled) { |
|
|
|
|
|
|
|
|
if (!_hlw8012Enabled) { |
|
|
powWasEnabled = false; |
|
|
powWasEnabled = false; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -195,7 +195,7 @@ void powLoop() { |
|
|
powWasEnabled = true; |
|
|
powWasEnabled = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (millis() - last_update > POW_UPDATE_INTERVAL) { |
|
|
|
|
|
|
|
|
if (millis() - last_update > HLW8012_UPDATE_INTERVAL) { |
|
|
|
|
|
|
|
|
last_update = millis(); |
|
|
last_update = millis(); |
|
|
|
|
|
|
|
@ -247,29 +247,29 @@ void powLoop() { |
|
|
|
|
|
|
|
|
if (--report_count == 0) { |
|
|
if (--report_count == 0) { |
|
|
|
|
|
|
|
|
power = power_sum / POW_REPORT_EVERY; |
|
|
|
|
|
current = current_sum / POW_REPORT_EVERY; |
|
|
|
|
|
voltage = voltage_sum / POW_REPORT_EVERY; |
|
|
|
|
|
|
|
|
power = power_sum / HLW8012_REPORT_EVERY; |
|
|
|
|
|
current = current_sum / HLW8012_REPORT_EVERY; |
|
|
|
|
|
voltage = voltage_sum / HLW8012_REPORT_EVERY; |
|
|
apparent = current * voltage; |
|
|
apparent = current * voltage; |
|
|
reactive = (apparent > power) ? sqrt(apparent * apparent - power * power) : 0; |
|
|
reactive = (apparent > power) ? sqrt(apparent * apparent - power * power) : 0; |
|
|
factor = (apparent > 0) ? (double) power / apparent : 1; |
|
|
factor = (apparent > 0) ? (double) power / apparent : 1; |
|
|
if (factor > 1) factor = 1; |
|
|
if (factor > 1) factor = 1; |
|
|
|
|
|
|
|
|
// Calculate energy increment (ppower times time) and create C-string
|
|
|
// Calculate energy increment (ppower times time) and create C-string
|
|
|
double energy_inc = (double) power * POW_REPORT_EVERY * POW_UPDATE_INTERVAL / 1000.0 / 3600.0; |
|
|
|
|
|
|
|
|
double energy_inc = (double) power * HLW8012_REPORT_EVERY * HLW8012_UPDATE_INTERVAL / 1000.0 / 3600.0; |
|
|
char energy_buf[11]; |
|
|
char energy_buf[11]; |
|
|
dtostrf(energy_inc, 11, 3, energy_buf); |
|
|
dtostrf(energy_inc, 11, 3, energy_buf); |
|
|
char *e = energy_buf; |
|
|
char *e = energy_buf; |
|
|
while ((unsigned char) *e == ' ') ++e; |
|
|
while ((unsigned char) *e == ' ') ++e; |
|
|
|
|
|
|
|
|
// Report values to MQTT broker
|
|
|
// Report values to MQTT broker
|
|
|
mqttSend(getSetting("powPowerTopic", POW_POWER_TOPIC).c_str(), String(power).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powEnergyTopic", POW_ENERGY_TOPIC).c_str(), e); |
|
|
|
|
|
mqttSend(getSetting("powCurrentTopic", POW_CURRENT_TOPIC).c_str(), String(current, 3).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powVoltageTopic", POW_VOLTAGE_TOPIC).c_str(), String(voltage).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powAPowerTopic", POW_APOWER_TOPIC).c_str(), String(apparent).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powRPowerTopic", POW_RPOWER_TOPIC).c_str(), String(reactive).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powPFactorTopic", POW_PFACTOR_TOPIC).c_str(), String(factor, 2).c_str()); |
|
|
|
|
|
|
|
|
mqttSend(getSetting("powPowerTopic", HLW8012_POWER_TOPIC).c_str(), String(power).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powEnergyTopic", HLW8012_ENERGY_TOPIC).c_str(), e); |
|
|
|
|
|
mqttSend(getSetting("powCurrentTopic", HLW8012_CURRENT_TOPIC).c_str(), String(current, 3).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powVoltageTopic", HLW8012_VOLTAGE_TOPIC).c_str(), String(voltage).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powAPowerTopic", HLW8012_APOWER_TOPIC).c_str(), String(apparent).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powRPowerTopic", HLW8012_RPOWER_TOPIC).c_str(), String(reactive).c_str()); |
|
|
|
|
|
mqttSend(getSetting("powPFactorTopic", HLW8012_PFACTOR_TOPIC).c_str(), String(factor, 2).c_str()); |
|
|
|
|
|
|
|
|
// Report values to Domoticz
|
|
|
// Report values to Domoticz
|
|
|
#if ENABLE_DOMOTICZ
|
|
|
#if ENABLE_DOMOTICZ
|
|
@ -287,18 +287,18 @@ void powLoop() { |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
#if ENABLE_INFLUXDB
|
|
|
#if ENABLE_INFLUXDB
|
|
|
influxDBSend(getSetting("powPowerTopic", POW_POWER_TOPIC).c_str(), String(power).c_str()); |
|
|
|
|
|
//influxDBSend(getSetting("powEnergyTopic", POW_ENERGY_TOPIC).c_str(), e);
|
|
|
|
|
|
//influxDBSend(getSetting("powCurrentTopic", POW_CURRENT_TOPIC).c_str(), String(current, 3).c_str());
|
|
|
|
|
|
//influxDBSend(getSetting("powVoltageTopic", POW_VOLTAGE_TOPIC).c_str(), String(voltage).c_str());
|
|
|
|
|
|
//influxDBSend(getSetting("powAPowerTopic", POW_APOWER_TOPIC).c_str(), String(apparent).c_str());
|
|
|
|
|
|
//influxDBSend(getSetting("powRPowerTopic", POW_RPOWER_TOPIC).c_str(), String(reactive).c_str());
|
|
|
|
|
|
//influxDBSend(getSetting("powPFactorTopic", POW_PFACTOR_TOPIC).c_str(), String(factor, 2).c_str());
|
|
|
|
|
|
|
|
|
influxDBSend(getSetting("powPowerTopic", HLW8012_POWER_TOPIC).c_str(), String(power).c_str()); |
|
|
|
|
|
//influxDBSend(getSetting("powEnergyTopic", HLW8012_ENERGY_TOPIC).c_str(), e);
|
|
|
|
|
|
//influxDBSend(getSetting("powCurrentTopic", HLW8012_CURRENT_TOPIC).c_str(), String(current, 3).c_str());
|
|
|
|
|
|
//influxDBSend(getSetting("powVoltageTopic", HLW8012_VOLTAGE_TOPIC).c_str(), String(voltage).c_str());
|
|
|
|
|
|
//influxDBSend(getSetting("powAPowerTopic", HLW8012_APOWER_TOPIC).c_str(), String(apparent).c_str());
|
|
|
|
|
|
//influxDBSend(getSetting("powRPowerTopic", HLW8012_RPOWER_TOPIC).c_str(), String(reactive).c_str());
|
|
|
|
|
|
//influxDBSend(getSetting("powPFactorTopic", HLW8012_PFACTOR_TOPIC).c_str(), String(factor, 2).c_str());
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
// Reset counters
|
|
|
// Reset counters
|
|
|
power_sum = current_sum = voltage_sum = 0; |
|
|
power_sum = current_sum = voltage_sum = 0; |
|
|
report_count = POW_REPORT_EVERY; |
|
|
|
|
|
|
|
|
report_count = HLW8012_REPORT_EVERY; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -308,7 +308,7 @@ void powLoop() { |
|
|
voltage_sum += voltage_previous; |
|
|
voltage_sum += voltage_previous; |
|
|
|
|
|
|
|
|
// Toggle between current and voltage monitoring
|
|
|
// Toggle between current and voltage monitoring
|
|
|
#if POW_USE_INTERRUPTS == 0
|
|
|
|
|
|
|
|
|
#if HLW8012_USE_INTERRUPTS == 0
|
|
|
hlw8012.toggleMode(); |
|
|
hlw8012.toggleMode(); |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|