Skip to content

Commit 5d68409

Browse files
authored
Merge pull request #4466 from ascillato/patch-1
Add Command CalcRes
2 parents c3f07f0 + 6a46354 commit 5d68409

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

Diff for: sonoff/_changelog.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/* 6.3.0.13 20181126
1+
/* 6.3.0.14 20181127
2+
* Add Command CalcRes to set number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE (#4420)
3+
*
4+
* 6.3.0.13 20181126
25
* Add command SetOption59 0/1 to change state topic from tele/STATE to stat/RESULT (#4450)
36
* Fix WifiManager functionality on initial installation (#4433)
47
*

Diff for: sonoff/my_user_config.h

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
#define SWITCH_DEBOUNCE_TIME 50 // [SwitchDebounce] Number of mSeconds switch press debounce time
175175
#define SWITCH_MODE TOGGLE // [SwitchMode] TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE (the wall switch state)
176176
#define WS2812_LEDS 30 // [Pixels] Number of WS2812 LEDs to start with (max is 512)
177+
#define CALC_RESOLUTION 3 // [CalcRes] Maximum number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE
177178

178179
#define TEMP_CONVERSION 0 // [SetOption8] Return temperature in (0 = Celsius or 1 = Fahrenheit)
179180
#define PRESSURE_CONVERSION 0 // [SetOption24] Return pressure in (0 = hPa or 1 = mmHg)

Diff for: sonoff/settings.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ typedef union {
107107
uint32_t spare03 : 1;
108108
uint32_t spare04 : 1;
109109
uint32_t spare05 : 1;
110-
uint32_t spare06 : 1;
111-
uint32_t spare07 : 1;
112-
uint32_t spare08 : 1;
110+
uint32_t calc_resolution : 3;
113111
uint32_t weight_resolution : 2;
114112
uint32_t frequency_resolution : 2;
115113
uint32_t axis_resolution : 2;

Diff for: sonoff/settings.ino

+4
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ void SettingsDefaultSet2(void)
576576
// Settings.rule_enabled = 0;
577577
// Settings.rule_once = 0;
578578
// for (byte i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
579+
Settings.flag2.calc_resolution = CALC_RESOLUTION;
579580

580581
// Home Assistant
581582
Settings.flag.hass_discovery = HOME_ASSISTANT_DISCOVERY_ENABLE;
@@ -857,6 +858,9 @@ void SettingsDelta(void)
857858
if (Settings.version < 0x0603000A) {
858859
Settings.param[P_LOOP_SLEEP_DELAY] = LOOP_SLEEP_DELAY;
859860
}
861+
if (Settings.version < 0x0603000E) {
862+
Settings.flag2.calc_resolution = CALC_RESOLUTION;
863+
}
860864

861865
Settings.version = VERSION;
862866
SettingsSave(1);

Diff for: sonoff/sonoff_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef _SONOFF_VERSION_H_
2121
#define _SONOFF_VERSION_H_
2222

23-
#define VERSION 0x0603000D
23+
#define VERSION 0x0603000E
2424

2525
#define D_PROGRAMNAME "Sonoff-Tasmota"
2626
#define D_AUTHOR "Theo Arends"

Diff for: sonoff/xdrv_10_rules.ino

+13-6
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@
7474
#define D_CMND_SUB "Sub"
7575
#define D_CMND_MULT "Mult"
7676
#define D_CMND_SCALE "Scale"
77+
#define D_CMND_CALC_RESOLUTION "CalcRes"
7778

7879
#define D_JSON_INITIATED "Initiated"
7980

80-
enum RulesCommands { CMND_RULE, CMND_RULETIMER, CMND_EVENT, CMND_VAR, CMND_MEM, CMND_ADD, CMND_SUB, CMND_MULT, CMND_SCALE };
81-
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 ;
81+
enum RulesCommands { CMND_RULE, CMND_RULETIMER, CMND_EVENT, CMND_VAR, CMND_MEM, CMND_ADD, CMND_SUB, CMND_MULT, CMND_SCALE, CMND_CALC_RESOLUTION };
82+
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 ;
8283

8384
String rules_event_value;
8485
unsigned long rules_timer[MAX_RULE_TIMERS] = { 0 };
@@ -593,24 +594,30 @@ boolean RulesCommand(void)
593594
}
594595
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, Settings.mems[index -1]);
595596
}
597+
else if (CMND_CALC_RESOLUTION == command_code) {
598+
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 7)) {
599+
Settings.flag2.calc_resolution = XdrvMailbox.payload;
600+
}
601+
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE, command, Settings.flag2.calc_resolution);
602+
}
596603
else if ((CMND_ADD == command_code) && (index > 0) && (index <= MAX_RULE_VARS)) {
597604
if (XdrvMailbox.data_len > 0) {
598605
double tempvar = CharToDouble(vars[index -1]) + CharToDouble(XdrvMailbox.data);
599-
dtostrfd(tempvar, 2, vars[index -1]);
606+
dtostrfd(tempvar, Settings.flag2.calc_resolution, vars[index -1]);
600607
}
601608
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]);
602609
}
603610
else if ((CMND_SUB == command_code) && (index > 0) && (index <= MAX_RULE_VARS)) {
604611
if (XdrvMailbox.data_len > 0) {
605612
double tempvar = CharToDouble(vars[index -1]) - CharToDouble(XdrvMailbox.data);
606-
dtostrfd(tempvar, 2, vars[index -1]);
613+
dtostrfd(tempvar, Settings.flag2.calc_resolution, vars[index -1]);
607614
}
608615
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]);
609616
}
610617
else if ((CMND_MULT == command_code) && (index > 0) && (index <= MAX_RULE_VARS)) {
611618
if (XdrvMailbox.data_len > 0) {
612619
double tempvar = CharToDouble(vars[index -1]) * CharToDouble(XdrvMailbox.data);
613-
dtostrfd(tempvar, 2, vars[index -1]);
620+
dtostrfd(tempvar, Settings.flag2.calc_resolution, vars[index -1]);
614621
}
615622
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]);
616623
}
@@ -625,7 +632,7 @@ boolean RulesCommand(void)
625632
double toLow = CharToDouble(subStr(sub_string, XdrvMailbox.data, ",", 4));
626633
double toHigh = CharToDouble(subStr(sub_string, XdrvMailbox.data, ",", 5));
627634
double value = map_double(valueIN, fromLow, fromHigh, toLow, toHigh);
628-
dtostrfd(value, 2, vars[index -1]);
635+
dtostrfd(value, Settings.flag2.calc_resolution, vars[index -1]);
629636
}
630637
}
631638
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index, vars[index -1]);

0 commit comments

Comments
 (0)