Add strict rule scale parameters

This commit is contained in:
Theo Arends 2021-01-31 16:54:28 +01:00
parent 9b91208bb7
commit 223d14e0fe
4 changed files with 30 additions and 28 deletions

View File

@ -76,48 +76,47 @@ const char kWifiConfig[] PROGMEM =
/********************************************************************************************/ /********************************************************************************************/
void ResponseCmndNumber(int value) void ResponseCmndNumber(int value) {
{
Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, value); Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, value);
} }
void ResponseCmndFloat(float value, uint32_t decimals) void ResponseCmndFloat(float value, uint32_t decimals) {
{
Response_P(PSTR("{\"%s\":%*_f}"), XdrvMailbox.command, decimals, &value); // Return float value without quotes Response_P(PSTR("{\"%s\":%*_f}"), XdrvMailbox.command, decimals, &value); // Return float value without quotes
} }
void ResponseCmndIdxNumber(int value) void ResponseCmndIdxNumber(int value) {
{
Response_P(S_JSON_COMMAND_INDEX_NVALUE, XdrvMailbox.command, XdrvMailbox.index, value); Response_P(S_JSON_COMMAND_INDEX_NVALUE, XdrvMailbox.command, XdrvMailbox.index, value);
} }
void ResponseCmndChar_P(const char* value) void ResponseCmndChar_P(const char* value) {
{
Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, value); Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, value);
} }
void ResponseCmndChar(const char* value) void ResponseCmndChar(const char* value) {
{
Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, EscapeJSONString(value).c_str()); Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, EscapeJSONString(value).c_str());
} }
void ResponseCmndStateText(uint32_t value) void ResponseCmndStateText(uint32_t value) {
{
ResponseCmndChar(GetStateText(value)); ResponseCmndChar(GetStateText(value));
} }
void ResponseCmndDone(void) void ResponseCmndDone(void) {
{ ResponseCmndChar_P(PSTR(D_JSON_DONE));
ResponseCmndChar(PSTR(D_JSON_DONE));
} }
void ResponseCmndIdxChar(const char* value) void ResponseCmndError(void) {
{ ResponseCmndChar_P(PSTR(D_JSON_ERROR));
}
void ResponseCmndIdxChar(const char* value) {
Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, EscapeJSONString(value).c_str()); Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, EscapeJSONString(value).c_str());
} }
void ResponseCmndAll(uint32_t text_index, uint32_t count) void ResponseCmndIdxError(void) {
{ ResponseCmndIdxChar(PSTR(D_JSON_ERROR));
}
void ResponseCmndAll(uint32_t text_index, uint32_t count) {
uint32_t real_index = text_index; uint32_t real_index = text_index;
ResponseClear(); ResponseClear();
for (uint32_t i = 0; i < count; i++) { for (uint32_t i = 0; i < count; i++) {

View File

@ -2297,7 +2297,7 @@ void CmndScale(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_VARS)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_VARS)) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (ArgC() > 1) { // Process parameter entry if (ArgC() == 5) { // Process parameter entry
char argument[XdrvMailbox.data_len]; char argument[XdrvMailbox.data_len];
float valueIN = CharToFloat(ArgV(argument, 1)); float valueIN = CharToFloat(ArgV(argument, 1));
@ -2308,6 +2308,9 @@ void CmndScale(void)
float value = map_double(valueIN, fromLow, fromHigh, toLow, toHigh); float value = map_double(valueIN, fromLow, fromHigh, toLow, toHigh);
dtostrfd(value, Settings.flag2.calc_resolution, rules_vars[XdrvMailbox.index -1]); dtostrfd(value, Settings.flag2.calc_resolution, rules_vars[XdrvMailbox.index -1]);
bitSet(Rules.vars_event, XdrvMailbox.index -1); bitSet(Rules.vars_event, XdrvMailbox.index -1);
} else {
ResponseCmndIdxError();
return;
} }
} }
ResponseCmndIdxChar(rules_vars[XdrvMailbox.index -1]); ResponseCmndIdxChar(rules_vars[XdrvMailbox.index -1]);

View File

@ -1189,7 +1189,7 @@ void CmndKnxPa(void)
if ( ((pa_area == 0) && (pa_line == 0) && (pa_member == 0)) if ( ((pa_area == 0) && (pa_line == 0) && (pa_member == 0))
|| (pa_area > 15) || (pa_line > 15) || (pa_member > 255) ) { || (pa_area > 15) || (pa_line > 15) || (pa_member > 255) ) {
Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); ResponseCmndError();
return; return;
} // Invalid command } // Invalid command
@ -1220,7 +1220,7 @@ void CmndKnxGa(void)
|| (ga_area > 31) || (ga_line > 7) || (ga_member > 255) || (ga_area > 31) || (ga_line > 7) || (ga_member > 255)
|| (ga_option < 0) || ((ga_option > KNX_MAX_device_param ) && (ga_option != KNX_Empty)) || (ga_option < 0) || ((ga_option > KNX_MAX_device_param ) && (ga_option != KNX_Empty))
|| (!device_param[ga_option-1].show) ) { || (!device_param[ga_option-1].show) ) {
Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); ResponseCmndIdxError();
return; return;
} // Invalid command } // Invalid command
@ -1239,7 +1239,7 @@ void CmndKnxGa(void)
if ( (XdrvMailbox.payload <= Settings.knx_GA_registered) && (XdrvMailbox.payload > 0) ) { if ( (XdrvMailbox.payload <= Settings.knx_GA_registered) && (XdrvMailbox.payload > 0) ) {
XdrvMailbox.index = XdrvMailbox.payload; XdrvMailbox.index = XdrvMailbox.payload;
} else { } else {
Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); ResponseCmndIdxError();
return; return;
} }
} }
@ -1250,7 +1250,7 @@ void CmndKnxGa(void)
KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member ); KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member );
} }
} else { } else {
ResponseCmndNumber (Settings.knx_GA_registered ); ResponseCmndIdxNumber (Settings.knx_GA_registered );
} }
} }
} }
@ -1271,7 +1271,7 @@ void CmndKnxCb(void)
|| (cb_area > 31) || (cb_line > 7) || (cb_member > 255) || (cb_area > 31) || (cb_line > 7) || (cb_member > 255)
|| (cb_option < 0) || ((cb_option > KNX_MAX_device_param ) && (cb_option != KNX_Empty)) || (cb_option < 0) || ((cb_option > KNX_MAX_device_param ) && (cb_option != KNX_Empty))
|| (!device_param[cb_option-1].show) ) { || (!device_param[cb_option-1].show) ) {
Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); ResponseCmndIdxError();
return; return;
} // Invalid command } // Invalid command
@ -1290,7 +1290,7 @@ void CmndKnxCb(void)
if ( (XdrvMailbox.payload <= Settings.knx_CB_registered) && (XdrvMailbox.payload > 0) ) { if ( (XdrvMailbox.payload <= Settings.knx_CB_registered) && (XdrvMailbox.payload > 0) ) {
XdrvMailbox.index = XdrvMailbox.payload; XdrvMailbox.index = XdrvMailbox.payload;
} else { } else {
Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); ResponseCmndIdxError();
return; return;
} }
} }
@ -1301,7 +1301,7 @@ void CmndKnxCb(void)
KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member ); KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member );
} }
} else { } else {
ResponseCmndNumber (Settings.knx_CB_registered ); ResponseCmndIdxNumber (Settings.knx_CB_registered );
} }
} }
} }

View File

@ -188,7 +188,7 @@ void CmndDeepsleepTime(void)
} }
} }
} }
Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.deepsleep); ResponseCmndNumber(Settings.deepsleep);
} }
/*********************************************************************************************\ /*********************************************************************************************\