From 0b988c561bdf0c539c46d0bb17ed95fb8436fe8e Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 26 Nov 2018 21:14:12 -0300 Subject: [PATCH 01/10] Added command CalcRes --- sonoff/my_user_config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 91b764688..ae5707c40 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -174,6 +174,7 @@ #define SWITCH_DEBOUNCE_TIME 50 // [SwitchDebounce] Number of mSeconds switch press debounce time #define SWITCH_MODE TOGGLE // [SwitchMode] TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE (the wall switch state) #define WS2812_LEDS 30 // [Pixels] Number of WS2812 LEDs to start with (max is 512) +#define CALC_RESOLUTION 3 // [CalcRes] Maximum number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE #define TEMP_CONVERSION 0 // [SetOption8] Return temperature in (0 = Celsius or 1 = Fahrenheit) #define PRESSURE_CONVERSION 0 // [SetOption24] Return pressure in (0 = hPa or 1 = mmHg) From c51e657ed98c4110094e6a99b7c6e9ed94c63e8c Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 26 Nov 2018 21:16:09 -0300 Subject: [PATCH 02/10] Added command CalcRes --- sonoff/settings.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sonoff/settings.h b/sonoff/settings.h index 9eb95a64c..033071668 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -107,9 +107,7 @@ typedef union { uint32_t spare03 : 1; uint32_t spare04 : 1; uint32_t spare05 : 1; - uint32_t spare06 : 1; - uint32_t spare07 : 1; - uint32_t spare08 : 1; + uint32_t calc_resolution : 3; uint32_t weight_resolution : 2; uint32_t frequency_resolution : 2; uint32_t axis_resolution : 2; From 5d11a4f444d06517acf92eb3caadfcbeefc14a65 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 26 Nov 2018 21:16:47 -0300 Subject: [PATCH 03/10] Added command CalcRes --- sonoff/settings.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 2a346feb7..6d3263f41 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -576,6 +576,7 @@ void SettingsDefaultSet2(void) // Settings.rule_enabled = 0; // Settings.rule_once = 0; // for (byte i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; } + Settings.flag2.calc_resolution = CALC_RESOLUTION; // Home Assistant Settings.flag.hass_discovery = HOME_ASSISTANT_DISCOVERY_ENABLE; From f7a8f39f8975ba5a34cda18b917f7ab6fd4330c6 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 26 Nov 2018 21:22:44 -0300 Subject: [PATCH 04/10] Added command CalcRes --- sonoff/xdrv_10_rules.ino | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index f13d5afd2..160c4e305 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -74,11 +74,12 @@ #define D_CMND_SUB "Sub" #define D_CMND_MULT "Mult" #define D_CMND_SCALE "Scale" +#define D_CMND_CALC_RESOLUTION "CalcRes" #define D_JSON_INITIATED "Initiated" -enum RulesCommands { CMND_RULE, CMND_RULETIMER, CMND_EVENT, CMND_VAR, CMND_MEM, CMND_ADD, CMND_SUB, CMND_MULT, CMND_SCALE }; -const char kRulesCommands[] PROGMEM = D_CMND_RULE "|" D_CMND_RULETIMER "|" D_CMND_EVENT "|" D_CMND_VAR "|" D_CMND_MEM "|" D_CMND_ADD "|" D_CMND_SUB "|" D_CMND_MULT "|" D_CMND_SCALE ; +enum RulesCommands { CMND_RULE, CMND_RULETIMER, CMND_EVENT, CMND_VAR, CMND_MEM, CMND_ADD, CMND_SUB, CMND_MULT, CMND_SCALE, CMND_CALC_RESOLUTION }; +const char kRulesCommands[] PROGMEM = D_CMND_RULE "|" D_CMND_RULETIMER "|" D_CMND_EVENT "|" D_CMND_VAR "|" D_CMND_MEM "|" D_CMND_ADD "|" D_CMND_SUB "|" D_CMND_MULT "|" D_CMND_SCALE "|" D_CMND_CALC_RESOLUTION ; String rules_event_value; unsigned long rules_timer[MAX_RULE_TIMERS] = { 0 }; @@ -593,24 +594,30 @@ boolean RulesCommand(void) } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.mems[index -1]); } + else if (CMND_CALC_RESOLUTION == command_code) { + if ((payload >= 0) && (payload <= 7)) { + Settings.flag2.calc_resolution = payload; + } + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.flag2.calc_resolution); + } else if ((CMND_ADD == command_code) && (index > 0) && (index <= MAX_RULE_VARS)) { if (XdrvMailbox.data_len > 0) { double tempvar = CharToDouble(vars[index -1]) + CharToDouble(XdrvMailbox.data); - dtostrfd(tempvar, 2, vars[index -1]); + dtostrfd(tempvar, Settings.flag2.calc_resolution, vars[index -1]); } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]); } else if ((CMND_SUB == command_code) && (index > 0) && (index <= MAX_RULE_VARS)) { if (XdrvMailbox.data_len > 0) { double tempvar = CharToDouble(vars[index -1]) - CharToDouble(XdrvMailbox.data); - dtostrfd(tempvar, 2, vars[index -1]); + dtostrfd(tempvar, Settings.flag2.calc_resolution, vars[index -1]); } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]); } else if ((CMND_MULT == command_code) && (index > 0) && (index <= MAX_RULE_VARS)) { if (XdrvMailbox.data_len > 0) { double tempvar = CharToDouble(vars[index -1]) * CharToDouble(XdrvMailbox.data); - dtostrfd(tempvar, 2, vars[index -1]); + dtostrfd(tempvar, Settings.flag2.calc_resolution, vars[index -1]); } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]); } @@ -625,7 +632,7 @@ boolean RulesCommand(void) double toLow = CharToDouble(subStr(sub_string, XdrvMailbox.data, ",", 4)); double toHigh = CharToDouble(subStr(sub_string, XdrvMailbox.data, ",", 5)); double value = map_double(valueIN, fromLow, fromHigh, toLow, toHigh); - dtostrfd(value, 2, vars[index -1]); + dtostrfd(value, Settings.flag2.calc_resolution, vars[index -1]); } } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]); From 2ce7862594ad61c6097134b6db7dc7f271a28452 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 26 Nov 2018 21:25:57 -0300 Subject: [PATCH 05/10] 6.3.0.14 Added Calc Resolution --- tools/decode-config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/decode-config.py b/tools/decode-config.py index 22d6262ea..71e46f152 100755 --- a/tools/decode-config.py +++ b/tools/decode-config.py @@ -534,6 +534,7 @@ Setting_5_10_0 = { 'energy_kWhtotal': (' Date: Mon, 26 Nov 2018 21:27:07 -0300 Subject: [PATCH 06/10] 6.3.0.14 Added Calc Resolution --- sonoff/sonoff_version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index cd5a77a08..d3df8d797 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x0603000D +#define VERSION 0x0603000E #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" From e46a81c193953c3b78c43b064e39f97354e8b5d9 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 26 Nov 2018 21:29:06 -0300 Subject: [PATCH 07/10] 6.3.0.14 Added command CalcRes --- sonoff/_changelog.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 2351beb8c..3de9daa3c 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,7 @@ -/* 6.3.0.13 20181126 +/* 6.3.0.14 20181127 + * Add Command CalcRes to set number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE (#4420) + * + * 6.3.0.13 20181126 * Add command SetOption59 0/1 to change state topic from tele/STATE to stat/RESULT (#4450) * Fix WifiManager functionality on initial installation (#4433) * From e3d1971e5138574b192e0bba0f0b00170e0353c5 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 26 Nov 2018 23:08:23 -0300 Subject: [PATCH 08/10] Add Command CalcRes --- sonoff/xdrv_10_rules.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 160c4e305..1fde3dff7 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -595,8 +595,8 @@ boolean RulesCommand(void) snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.mems[index -1]); } else if (CMND_CALC_RESOLUTION == command_code) { - if ((payload >= 0) && (payload <= 7)) { - Settings.flag2.calc_resolution = payload; + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 7)) { + Settings.flag2.calc_resolution = XdrvMailbox.payload; } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.flag2.calc_resolution); } From 101cf83d7d235a7ccc11003e447d06d485b5fc4e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 27 Nov 2018 10:54:34 +0100 Subject: [PATCH 09/10] Update settings.ino --- sonoff/settings.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 6d3263f41..99e81230d 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -858,6 +858,9 @@ void SettingsDelta(void) if (Settings.version < 0x0603000A) { Settings.param[P_LOOP_SLEEP_DELAY] = LOOP_SLEEP_DELAY; } + if (Settings.version < 0x0603000E) { + Settings.flag2.calc_resolution = CALC_RESOLUTION; + } Settings.version = VERSION; SettingsSave(1); From 6a46354880dd8c2f5673a9b581110274a5aeb3e4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 27 Nov 2018 11:00:15 +0100 Subject: [PATCH 10/10] Update decode-config.py --- tools/decode-config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/decode-config.py b/tools/decode-config.py index 71e46f152..22d6262ea 100755 --- a/tools/decode-config.py +++ b/tools/decode-config.py @@ -534,7 +534,6 @@ Setting_5_10_0 = { 'energy_kWhtotal': ('