74
74
#define D_CMND_SUB " Sub"
75
75
#define D_CMND_MULT " Mult"
76
76
#define D_CMND_SCALE " Scale"
77
+ #define D_CMND_CALC_RESOLUTION " CalcRes"
77
78
78
79
#define D_JSON_INITIATED " Initiated"
79
80
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 ;
82
83
83
84
String rules_event_value;
84
85
unsigned long rules_timer[MAX_RULE_TIMERS] = { 0 };
@@ -593,24 +594,30 @@ boolean RulesCommand(void)
593
594
}
594
595
snprintf_P (mqtt_data, sizeof (mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index , Settings.mems [index -1 ]);
595
596
}
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
+ }
596
603
else if ((CMND_ADD == command_code) && (index > 0 ) && (index <= MAX_RULE_VARS)) {
597
604
if (XdrvMailbox.data_len > 0 ) {
598
605
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 ]);
600
607
}
601
608
snprintf_P (mqtt_data, sizeof (mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index , vars[index -1 ]);
602
609
}
603
610
else if ((CMND_SUB == command_code) && (index > 0 ) && (index <= MAX_RULE_VARS)) {
604
611
if (XdrvMailbox.data_len > 0 ) {
605
612
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 ]);
607
614
}
608
615
snprintf_P (mqtt_data, sizeof (mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index , vars[index -1 ]);
609
616
}
610
617
else if ((CMND_MULT == command_code) && (index > 0 ) && (index <= MAX_RULE_VARS)) {
611
618
if (XdrvMailbox.data_len > 0 ) {
612
619
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 ]);
614
621
}
615
622
snprintf_P (mqtt_data, sizeof (mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index , vars[index -1 ]);
616
623
}
@@ -625,7 +632,7 @@ boolean RulesCommand(void)
625
632
double toLow = CharToDouble (subStr (sub_string, XdrvMailbox.data , " ," , 4 ));
626
633
double toHigh = CharToDouble (subStr (sub_string, XdrvMailbox.data , " ," , 5 ));
627
634
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 ]);
629
636
}
630
637
}
631
638
snprintf_P (mqtt_data, sizeof (mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, index , vars[index -1 ]);
0 commit comments