Merge pull request #4466 from ascillato/patch-1

Add Command CalcRes
This commit is contained in:
Theo Arends 2018-11-27 11:01:04 +01:00 committed by GitHub
commit 5d68409a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 11 deletions

View File

@ -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)
*

View File

@ -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)

View File

@ -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;

View File

@ -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;
@ -857,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);

View File

@ -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"

View File

@ -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 ((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);
}
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]);