Refactor GUI save parameters (Prt1)

This commit is contained in:
Theo Arends 2021-04-07 18:10:34 +02:00
parent ad423d199d
commit d08f9bc315
1 changed files with 45 additions and 39 deletions

View File

@ -403,13 +403,16 @@ void ShowWebSource(uint32_t source)
}
}
void ExecuteWebCommand(char* svalue, uint32_t source)
{
void ExecuteWebCommand(char* svalue, uint32_t source) {
ShowWebSource(source);
TasmotaGlobal.last_source = source;
ExecuteCommand(svalue, SRC_IGNORE);
}
void ExecuteWebCommand(char* svalue) {
ExecuteWebCommand(svalue, SRC_WEBGUI);
}
// replace the series of `Webserver->on()` with a table in PROGMEM
typedef struct WebServerDispatch_t {
char uri[3]; // the prefix "/" is added automatically
@ -1168,7 +1171,7 @@ bool HandleRootStatusRefresh(void)
int32_t ShutterWebButton;
if (ShutterWebButton = IsShutterWebButton(device)) {
snprintf_P(svalue, sizeof(svalue), PSTR("ShutterPosition%d %s"), abs(ShutterWebButton), (ShutterWebButton>0) ? PSTR(D_CMND_SHUTTER_STOPOPEN) : PSTR(D_CMND_SHUTTER_STOPCLOSE));
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
} else {
#endif // USE_SHUTTER
ExecuteCommandPower(device, POWER_TOGGLE, SRC_IGNORE);
@ -1186,12 +1189,12 @@ bool HandleRootStatusRefresh(void)
WebGetArg(PSTR("d0"), tmp, sizeof(tmp)); // 0 - 100 Dimmer value
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_DIMMER " %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
WebGetArg(PSTR("w0"), tmp, sizeof(tmp)); // 0 - 100 White value
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_WHITE " %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
uint32_t light_device = LightDevice(); // Channel number offset
uint32_t pwm_channels = (TasmotaGlobal.light_type & 7) > LST_MAX ? LST_MAX : (TasmotaGlobal.light_type & 7);
@ -1200,23 +1203,23 @@ bool HandleRootStatusRefresh(void)
WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_CHANNEL "%d %s"), j +light_device, tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
}
WebGetArg(PSTR("t0"), tmp, sizeof(tmp)); // 153 - 500 Color temperature
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_COLORTEMPERATURE " %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
WebGetArg(PSTR("h0"), tmp, sizeof(tmp)); // 0 - 359 Hue value
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "1 %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
WebGetArg(PSTR("n0"), tmp, sizeof(tmp)); // 0 - 99 Saturation value
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "2 %s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
#endif // USE_LIGHT
#ifdef USE_SHUTTER
@ -1225,7 +1228,7 @@ bool HandleRootStatusRefresh(void)
WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR("ShutterPosition%d %s"), j, tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
}
#endif // USE_SHUTTER
@ -1233,19 +1236,19 @@ bool HandleRootStatusRefresh(void)
WebGetArg(PSTR("k"), tmp, sizeof(tmp)); // 1 - 16 Pre defined RF keys
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_RFKEY "%s"), tmp);
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
#endif // USE_SONOFF_RF
#ifdef USE_ZIGBEE
WebGetArg(PSTR("zbj"), tmp, sizeof(tmp));
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR("ZbPermitJoin"));
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
WebGetArg(PSTR("zbr"), tmp, sizeof(tmp));
if (strlen(tmp)) {
snprintf_P(svalue, sizeof(svalue), PSTR("ZbMap"));
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
#endif // USE_ZIGBEE
@ -1528,7 +1531,7 @@ void TemplateSaveSettings(void)
uint32_t base = atoi(tmp) +1;
snprintf_P(svalue, sizeof(svalue), PSTR("%s],\"" D_JSON_FLAG "\":%d,\"" D_JSON_BASE "\":%d}"), svalue, flag, base);
ExecuteWebCommand(svalue, SRC_WEBGUI);
ExecuteWebCommand(svalue);
}
/*-------------------------------------------------------------------------------------------*/
@ -1868,27 +1871,30 @@ void HandleLoggingConfiguration(void)
void LoggingSaveSettings(void)
{
char tmp[TOPSZ]; // Max length is currently 33
WebGetArg(PSTR("l0"), tmp, sizeof(tmp));
SetSeriallog((!strlen(tmp)) ? SERIAL_LOG_LEVEL : atoi(tmp));
WebGetArg(PSTR("l1"), tmp, sizeof(tmp));
Settings.weblog_level = (!strlen(tmp)) ? WEB_LOG_LEVEL : atoi(tmp);
WebGetArg(PSTR("l2"), tmp, sizeof(tmp));
Settings.mqttlog_level = (!strlen(tmp)) ? MQTT_LOG_LEVEL : atoi(tmp);
WebGetArg(PSTR("l3"), tmp, sizeof(tmp));
SetSyslog((!strlen(tmp)) ? SYS_LOG_LEVEL : atoi(tmp));
WebGetArg(PSTR("lh"), tmp, sizeof(tmp));
SettingsUpdateText(SET_SYSLOG_HOST, (!strlen(tmp)) ? SYS_LOG_HOST : tmp);
WebGetArg(PSTR("lp"), tmp, sizeof(tmp));
Settings.syslog_port = (!strlen(tmp)) ? SYS_LOG_PORT : atoi(tmp);
WebGetArg(PSTR("lt"), tmp, sizeof(tmp));
Settings.tele_period = (!strlen(tmp)) ? TELE_PERIOD : atoi(tmp);
if ((Settings.tele_period > 0) && (Settings.tele_period < 10)) {
Settings.tele_period = 10; // Do not allow periods < 10 seconds
}
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_LOG D_CMND_SERIALLOG " %d, " D_CMND_WEBLOG " %d, " D_CMND_MQTTLOG " %d, " D_CMND_SYSLOG " %d, " D_CMND_LOGHOST " %s, " D_CMND_LOGPORT " %d, " D_CMND_TELEPERIOD " %d"),
Settings.seriallog_level, Settings.weblog_level, Settings.mqttlog_level, Settings.syslog_level, SettingsText(SET_SYSLOG_HOST), Settings.syslog_port, Settings.tele_period);
char tmp1[CMDSZ];
WebGetArg(PSTR("l0"), tmp1, sizeof(tmp1));
char tmp2[CMDSZ];
WebGetArg(PSTR("l1"), tmp2, sizeof(tmp2));
char tmp3[CMDSZ];
WebGetArg(PSTR("l2"), tmp3, sizeof(tmp3));
char tmp4[CMDSZ];
WebGetArg(PSTR("l3"), tmp4, sizeof(tmp4));
char tmp5[CMDSZ];
WebGetArg(PSTR("lh"), tmp5, sizeof(tmp5));
char tmp6[CMDSZ];
WebGetArg(PSTR("lp"), tmp6, sizeof(tmp6));
char tmp7[CMDSZ];
WebGetArg(PSTR("lt"), tmp7, sizeof(tmp7));
char command[200];
snprintf_P(command, sizeof(command),PSTR(D_CMND_BACKLOG " 1;" D_CMND_SERIALLOG " %s;" D_CMND_WEBLOG " %s;" D_CMND_MQTTLOG " %s;" D_CMND_SYSLOG " %s;" D_CMND_LOGHOST " %s;" D_CMND_LOGPORT " %s;" D_CMND_TELEPERIOD " %s"),
(!strlen(tmp1)) ? STR(SERIAL_LOG_LEVEL) : tmp1,
(!strlen(tmp2)) ? STR(WEB_LOG_LEVEL) : tmp2,
(!strlen(tmp3)) ? STR(MQTT_LOG_LEVEL) : tmp3,
(!strlen(tmp4)) ? STR(SYS_LOG_LEVEL) : tmp4,
(!strlen(tmp5)) ? SYS_LOG_HOST : tmp5,
(!strlen(tmp6)) ? STR(SYS_LOG_PORT) : tmp6,
(!strlen(tmp7)) ? STR(TELE_PERIOD) : tmp7);
ExecuteWebCommand(command);
}
/*-------------------------------------------------------------------------------------------*/
@ -1990,7 +1996,7 @@ void OtherSaveSettings(void)
WebGetArg(PSTR("t1"), tmp, sizeof(tmp));
if (strlen(tmp)) { // {"NAME":"12345678901234","GPIO":[255,255,255,255,255,255,255,255,255,255,255,255,255],"FLAG":255,"BASE":255}
snprintf_P(message, sizeof(message), PSTR(D_CMND_BACKLOG " " D_CMND_TEMPLATE " %s%s"), tmp, (Webserver->hasArg(F("t2"))) ? PSTR("; " D_CMND_MODULE " 0") : "");
ExecuteWebCommand(message, SRC_WEBGUI);
ExecuteWebCommand(message);
}
}
@ -2053,7 +2059,7 @@ void HandleResetConfiguration(void)
char command[CMDSZ];
snprintf_P(command, sizeof(command), PSTR(D_CMND_RESET " 1"));
ExecuteWebCommand(command, SRC_WEBGUI);
ExecuteWebCommand(command);
}
void HandleRestoreConfiguration(void)
@ -2298,7 +2304,7 @@ void HandleUpgradeFirmwareStart(void) {
WebGetArg(PSTR("o"), otaurl, sizeof(otaurl));
if (strlen(otaurl)) {
snprintf_P(command, sizeof(command), PSTR(D_CMND_OTAURL " %s"), otaurl);
ExecuteWebCommand(command, SRC_WEBGUI);
ExecuteWebCommand(command);
}
WSContentStart_P(PSTR(D_INFORMATION));
@ -2310,7 +2316,7 @@ void HandleUpgradeFirmwareStart(void) {
WSContentStop();
snprintf_P(command, sizeof(command), PSTR(D_CMND_UPGRADE " 1"));
ExecuteWebCommand(command, SRC_WEBGUI);
ExecuteWebCommand(command);
}
void HandleUploadDone(void) {