From 09082826e1f7c7fe387e4fd94683b8a78b6e370f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 4 Sep 2017 15:44:21 +0200 Subject: [PATCH] Issue #194. Fix HLW8012 calibration --- code/espurna/espurna.ino | 3 +++ code/espurna/hlw8012.ino | 7 ++++--- code/espurna/settings.ino | 8 -------- code/espurna/web.ino | 10 ++++++---- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 53c88cca..5b6fa25e 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -158,6 +158,9 @@ void welcome() { #if EMON_SUPPORT DEBUG_MSG_P(PSTR(" EMON")); #endif + #if HLW8012_SUPPORT + DEBUG_MSG_P(PSTR(" HLW8012")); + #endif #if HOMEASSISTANT_SUPPORT DEBUG_MSG_P(PSTR(" HOMEASSISTANT")); #endif diff --git a/code/espurna/hlw8012.ino b/code/espurna/hlw8012.ino index 348f626d..928311bf 100644 --- a/code/espurna/hlw8012.ino +++ b/code/espurna/hlw8012.ino @@ -57,16 +57,17 @@ void hlw8012SaveCalibration() { setSetting("powPowerMult", hlw8012.getPowerMultiplier()); setSetting("powCurrentMult", hlw8012.getCurrentMultiplier()); setSetting("powVoltageMult", hlw8012.getVoltageMultiplier()); + saveSettings(); } void hlw8012RetrieveCalibration() { double value; value = getSetting("powPowerMult", 0).toFloat(); - if (value > 0) hlw8012.setPowerMultiplier((int) value); + if (value > 0) hlw8012.setPowerMultiplier(value); value = getSetting("powCurrentMult", 0).toFloat(); - if (value > 0) hlw8012.setCurrentMultiplier((int) value); + if (value > 0) hlw8012.setCurrentMultiplier(value); value = getSetting("powVoltageMult", 0).toFloat(); - if (value > 0) hlw8012.setVoltageMultiplier((int) value); + if (value > 0) hlw8012.setVoltageMultiplier(value); } void hlw8012SetExpectedActivePower(unsigned int power) { diff --git a/code/espurna/settings.ino b/code/espurna/settings.ino index b676fc6a..1dbb68cb 100644 --- a/code/espurna/settings.ino +++ b/code/espurna/settings.ino @@ -314,14 +314,6 @@ String getSetting(const String& key) { return getSetting(key, ""); } -bool setBoolSetting(const String& key, bool value, bool defaultValue) { - if (value == defaultValue) { - return delSetting(key); - } else { - return setSetting(key, value ? 1 : 0); - } -} - template bool setSetting(const String& key, T value) { return Embedis::set(key, String(value)); } diff --git a/code/espurna/web.ino b/code/espurna/web.ino index 2f28bee8..dd5639dd 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -246,13 +246,15 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { } if (key == "powExpectedReset") { - hlw8012Reset(); - changed = true; + if (value.toInt() == 1) { + hlw8012Reset(); + changed = true; + } } - #endif + if (key.startsWith("pow")) continue; - if (key.startsWith("pow")) continue; + #endif #if DOMOTICZ_SUPPORT