mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
show message to restart after setting params
This commit is contained in:
@@ -877,9 +877,10 @@ char * MyESP::_telnet_readWord(bool allow_all_chars) {
|
|||||||
// wc is word count, number of parameters after the 'set' command
|
// wc is word count, number of parameters after the 'set' command
|
||||||
bool MyESP::_changeSetting(uint8_t wc, const char * setting, const char * value) {
|
bool MyESP::_changeSetting(uint8_t wc, const char * setting, const char * value) {
|
||||||
bool save_config = false;
|
bool save_config = false;
|
||||||
bool save_custom_config = false;
|
|
||||||
bool restart = false;
|
bool restart = false;
|
||||||
|
|
||||||
|
MYESP_FSACTION_t save_custom_config = MYESP_FSACTION_ERR; // default
|
||||||
|
|
||||||
// check for our internal commands first
|
// check for our internal commands first
|
||||||
if (strcmp(setting, "erase") == 0) {
|
if (strcmp(setting, "erase") == 0) {
|
||||||
_fs_eraseConfig();
|
_fs_eraseConfig();
|
||||||
@@ -941,13 +942,14 @@ bool MyESP::_changeSetting(uint8_t wc, const char * setting, const char * value)
|
|||||||
// finally check for any custom commands
|
// finally check for any custom commands
|
||||||
if (_fs_setlist_callback_f) {
|
if (_fs_setlist_callback_f) {
|
||||||
save_custom_config = (_fs_setlist_callback_f)(MYESP_FSACTION_SET, wc, setting, value);
|
save_custom_config = (_fs_setlist_callback_f)(MYESP_FSACTION_SET, wc, setting, value);
|
||||||
|
restart = (save_custom_config == MYESP_FSACTION_RESTART);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
// if we were able to recognize the set command, continue
|
// if we were able to recognize the set command, continue
|
||||||
if ((save_config || save_custom_config)) {
|
if ((save_config || save_custom_config != MYESP_FSACTION_ERR)) {
|
||||||
// check for 2 params
|
// check for 2 params
|
||||||
if (value == nullptr) {
|
if (value == nullptr) {
|
||||||
myDebug_P(PSTR("%s has been reset to its default value."), setting);
|
myDebug_P(PSTR("%s has been reset to its default value."), setting);
|
||||||
@@ -963,7 +965,7 @@ bool MyESP::_changeSetting(uint8_t wc, const char * setting, const char * value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// and see if we need to also save for custom config
|
// and see if we need to also save for custom config
|
||||||
if (save_custom_config) {
|
if (save_custom_config != MYESP_FSACTION_ERR) {
|
||||||
ok = _fs_createCustomConfig();
|
ok = _fs_createCustomConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/MyESP.h
12
src/MyESP.h
@@ -220,7 +220,15 @@ typedef struct {
|
|||||||
char description[110];
|
char description[110];
|
||||||
} command_t;
|
} command_t;
|
||||||
|
|
||||||
typedef enum { MYESP_FSACTION_SET, MYESP_FSACTION_LIST, MYESP_FSACTION_SAVE, MYESP_FSACTION_LOAD } MYESP_FSACTION_t;
|
typedef enum {
|
||||||
|
MYESP_FSACTION_SET,
|
||||||
|
MYESP_FSACTION_LIST,
|
||||||
|
MYESP_FSACTION_SAVE,
|
||||||
|
MYESP_FSACTION_LOAD,
|
||||||
|
MYESP_FSACTION_ERR,
|
||||||
|
MYESP_FSACTION_OK,
|
||||||
|
MYESP_FSACTION_RESTART
|
||||||
|
} MYESP_FSACTION_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MYESP_BOOTSTATUS_POWERON = 0,
|
MYESP_BOOTSTATUS_POWERON = 0,
|
||||||
@@ -245,7 +253,7 @@ typedef std::function<void()>
|
|||||||
typedef std::function<void(uint8_t, const char *)> telnetcommand_callback_f;
|
typedef std::function<void(uint8_t, const char *)> telnetcommand_callback_f;
|
||||||
typedef std::function<void(uint8_t)> telnet_callback_f;
|
typedef std::function<void(uint8_t)> telnet_callback_f;
|
||||||
typedef std::function<bool(MYESP_FSACTION_t, JsonObject json)> fs_loadsave_callback_f;
|
typedef std::function<bool(MYESP_FSACTION_t, JsonObject json)> fs_loadsave_callback_f;
|
||||||
typedef std::function<bool(MYESP_FSACTION_t, uint8_t, const char *, const char *)> fs_setlist_callback_f;
|
typedef std::function<MYESP_FSACTION_t(MYESP_FSACTION_t, uint8_t, const char *, const char *)> fs_setlist_callback_f;
|
||||||
typedef std::function<void(JsonObject root)> web_callback_f;
|
typedef std::function<void(JsonObject root)> web_callback_f;
|
||||||
|
|
||||||
// calculates size of an 2d array at compile time
|
// calculates size of an 2d array at compile time
|
||||||
|
|||||||
@@ -1095,18 +1095,18 @@ bool LoadSaveCallback(MYESP_FSACTION_t action, JsonObject settings) {
|
|||||||
// callback for custom settings when showing Stored Settings with the 'set' command
|
// callback for custom settings when showing Stored Settings with the 'set' command
|
||||||
// wc is number of arguments after the 'set' command
|
// wc is number of arguments after the 'set' command
|
||||||
// returns true if the setting was recognized and changed and should be saved back to SPIFFs
|
// returns true if the setting was recognized and changed and should be saved back to SPIFFs
|
||||||
bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting, const char * value) {
|
MYESP_FSACTION_t SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting, const char * value) {
|
||||||
bool ok = false;
|
MYESP_FSACTION_t ok = MYESP_FSACTION_ERR;
|
||||||
|
|
||||||
if (action == MYESP_FSACTION_SET) {
|
if (action == MYESP_FSACTION_SET) {
|
||||||
// led
|
// led
|
||||||
if ((strcmp(setting, "led") == 0) && (wc == 2)) {
|
if ((strcmp(setting, "led") == 0) && (wc == 2)) {
|
||||||
if (strcmp(value, "on") == 0) {
|
if (strcmp(value, "on") == 0) {
|
||||||
EMSESP_Settings.led = true;
|
EMSESP_Settings.led = true;
|
||||||
ok = true;
|
ok = MYESP_FSACTION_RESTART;
|
||||||
} else if (strcmp(value, "off") == 0) {
|
} else if (strcmp(value, "off") == 0) {
|
||||||
EMSESP_Settings.led = false;
|
EMSESP_Settings.led = false;
|
||||||
ok = true;
|
ok = MYESP_FSACTION_RESTART;
|
||||||
// let's make sure LED is really off - For onboard high=off
|
// let's make sure LED is really off - For onboard high=off
|
||||||
digitalWrite(EMSESP_Settings.led_gpio, (EMSESP_Settings.led_gpio == LED_BUILTIN) ? HIGH : LOW);
|
digitalWrite(EMSESP_Settings.led_gpio, (EMSESP_Settings.led_gpio == LED_BUILTIN) ? HIGH : LOW);
|
||||||
} else {
|
} else {
|
||||||
@@ -1118,12 +1118,12 @@ bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting,
|
|||||||
if ((strcmp(setting, "listen_mode") == 0) && (wc == 2)) {
|
if ((strcmp(setting, "listen_mode") == 0) && (wc == 2)) {
|
||||||
if (strcmp(value, "on") == 0) {
|
if (strcmp(value, "on") == 0) {
|
||||||
EMSESP_Settings.listen_mode = true;
|
EMSESP_Settings.listen_mode = true;
|
||||||
ok = true;
|
ok = MYESP_FSACTION_OK;
|
||||||
myDebug_P(PSTR("* in listen mode. All Tx is disabled."));
|
myDebug_P(PSTR("* in listen mode. All Tx is disabled."));
|
||||||
ems_setTxDisabled(true);
|
ems_setTxDisabled(true);
|
||||||
} else if (strcmp(value, "off") == 0) {
|
} else if (strcmp(value, "off") == 0) {
|
||||||
EMSESP_Settings.listen_mode = false;
|
EMSESP_Settings.listen_mode = false;
|
||||||
ok = true;
|
ok = MYESP_FSACTION_OK;
|
||||||
ems_setTxDisabled(false);
|
ems_setTxDisabled(false);
|
||||||
myDebug_P(PSTR("* out of listen mode. Tx is now enabled."));
|
myDebug_P(PSTR("* out of listen mode. Tx is now enabled."));
|
||||||
} else {
|
} else {
|
||||||
@@ -1137,23 +1137,23 @@ bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting,
|
|||||||
// reset pin
|
// reset pin
|
||||||
pinMode(EMSESP_Settings.led_gpio, OUTPUT);
|
pinMode(EMSESP_Settings.led_gpio, OUTPUT);
|
||||||
digitalWrite(EMSESP_Settings.led_gpio, (EMSESP_Settings.led_gpio == LED_BUILTIN) ? HIGH : LOW); // light off. For onboard high=off
|
digitalWrite(EMSESP_Settings.led_gpio, (EMSESP_Settings.led_gpio == LED_BUILTIN) ? HIGH : LOW); // light off. For onboard high=off
|
||||||
ok = true;
|
ok = MYESP_FSACTION_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dallas_gpio
|
// dallas_gpio
|
||||||
if ((strcmp(setting, "dallas_gpio") == 0) && (wc == 2)) {
|
if ((strcmp(setting, "dallas_gpio") == 0) && (wc == 2)) {
|
||||||
EMSESP_Settings.dallas_gpio = atoi(value);
|
EMSESP_Settings.dallas_gpio = atoi(value);
|
||||||
ok = true;
|
ok = MYESP_FSACTION_RESTART;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dallas_parasite
|
// dallas_parasite
|
||||||
if ((strcmp(setting, "dallas_parasite") == 0) && (wc == 2)) {
|
if ((strcmp(setting, "dallas_parasite") == 0) && (wc == 2)) {
|
||||||
if (strcmp(value, "on") == 0) {
|
if (strcmp(value, "on") == 0) {
|
||||||
EMSESP_Settings.dallas_parasite = true;
|
EMSESP_Settings.dallas_parasite = true;
|
||||||
ok = true;
|
ok = MYESP_FSACTION_RESTART;
|
||||||
} else if (strcmp(value, "off") == 0) {
|
} else if (strcmp(value, "off") == 0) {
|
||||||
EMSESP_Settings.dallas_parasite = false;
|
EMSESP_Settings.dallas_parasite = false;
|
||||||
ok = true;
|
ok = MYESP_FSACTION_RESTART;
|
||||||
} else {
|
} else {
|
||||||
myDebug_P(PSTR("Error. Usage: set dallas_parasite <on | off>"));
|
myDebug_P(PSTR("Error. Usage: set dallas_parasite <on | off>"));
|
||||||
}
|
}
|
||||||
@@ -1163,10 +1163,10 @@ bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting,
|
|||||||
if ((strcmp(setting, "shower_timer") == 0) && (wc == 2)) {
|
if ((strcmp(setting, "shower_timer") == 0) && (wc == 2)) {
|
||||||
if (strcmp(value, "on") == 0) {
|
if (strcmp(value, "on") == 0) {
|
||||||
EMSESP_Settings.shower_timer = true;
|
EMSESP_Settings.shower_timer = true;
|
||||||
ok = do_publishShowerData();
|
ok = do_publishShowerData() ? MYESP_FSACTION_OK : MYESP_FSACTION_ERR;
|
||||||
} else if (strcmp(value, "off") == 0) {
|
} else if (strcmp(value, "off") == 0) {
|
||||||
EMSESP_Settings.shower_timer = false;
|
EMSESP_Settings.shower_timer = false;
|
||||||
ok = do_publishShowerData();
|
ok = do_publishShowerData() ? MYESP_FSACTION_OK : MYESP_FSACTION_ERR;
|
||||||
} else {
|
} else {
|
||||||
myDebug_P(PSTR("Error. Usage: set shower_timer <on | off>"));
|
myDebug_P(PSTR("Error. Usage: set shower_timer <on | off>"));
|
||||||
}
|
}
|
||||||
@@ -1176,19 +1176,23 @@ bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting,
|
|||||||
if ((strcmp(setting, "shower_alert") == 0) && (wc == 2)) {
|
if ((strcmp(setting, "shower_alert") == 0) && (wc == 2)) {
|
||||||
if (strcmp(value, "on") == 0) {
|
if (strcmp(value, "on") == 0) {
|
||||||
EMSESP_Settings.shower_alert = true;
|
EMSESP_Settings.shower_alert = true;
|
||||||
ok = do_publishShowerData();
|
ok = do_publishShowerData() ? MYESP_FSACTION_OK : MYESP_FSACTION_ERR;
|
||||||
} else if (strcmp(value, "off") == 0) {
|
} else if (strcmp(value, "off") == 0) {
|
||||||
EMSESP_Settings.shower_alert = false;
|
EMSESP_Settings.shower_alert = false;
|
||||||
ok = do_publishShowerData();
|
ok = do_publishShowerData() ? MYESP_FSACTION_OK : MYESP_FSACTION_ERR;
|
||||||
} else {
|
} else {
|
||||||
myDebug_P(PSTR("Error. Usage: set shower_alert <on | off>"));
|
myDebug_P(PSTR("Error. Usage: set shower_alert <on | off>"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// publish_time
|
// publish_time
|
||||||
if ((strcmp(setting, "publish_time") == 0) && (wc == 2)) {
|
if (strcmp(setting, "publish_time") == 0) {
|
||||||
|
if (wc == 1) {
|
||||||
|
EMSESP_Settings.publish_time = 0;
|
||||||
|
} else {
|
||||||
EMSESP_Settings.publish_time = atoi(value);
|
EMSESP_Settings.publish_time = atoi(value);
|
||||||
ok = true;
|
}
|
||||||
|
ok = MYESP_FSACTION_RESTART;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tx_mode
|
// tx_mode
|
||||||
@@ -1197,7 +1201,7 @@ bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting,
|
|||||||
if ((mode >= 1) && (mode <= 3)) { // see ems.h for definitions
|
if ((mode >= 1) && (mode <= 3)) { // see ems.h for definitions
|
||||||
EMSESP_Settings.tx_mode = mode;
|
EMSESP_Settings.tx_mode = mode;
|
||||||
ems_setTxMode(mode);
|
ems_setTxMode(mode);
|
||||||
ok = true;
|
ok = MYESP_FSACTION_RESTART;
|
||||||
} else {
|
} else {
|
||||||
myDebug_P(PSTR("Error. Usage: set tx_mode <1 | 2 | 3>"));
|
myDebug_P(PSTR("Error. Usage: set tx_mode <1 | 2 | 3>"));
|
||||||
}
|
}
|
||||||
@@ -1209,7 +1213,7 @@ bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting,
|
|||||||
if ((id == 0x0B) || (id == 0x0D) || (id == 0x0A) || (id == 0x0F) || (id == 0x12)) {
|
if ((id == 0x0B) || (id == 0x0D) || (id == 0x0A) || (id == 0x0F) || (id == 0x12)) {
|
||||||
EMSESP_Settings.bus_id = id;
|
EMSESP_Settings.bus_id = id;
|
||||||
ems_setEMSbusid(id);
|
ems_setEMSbusid(id);
|
||||||
ok = true;
|
ok = MYESP_FSACTION_RESTART;
|
||||||
} else {
|
} else {
|
||||||
myDebug_P(PSTR("Error. Usage: set bus_id <ID>, with ID=0B, 0D, 0A, 0F or 12"));
|
myDebug_P(PSTR("Error. Usage: set bus_id <ID>, with ID=0B, 0D, 0A, 0F or 12"));
|
||||||
}
|
}
|
||||||
@@ -1231,15 +1235,15 @@ bool SetListCallback(MYESP_FSACTION_t action, uint8_t wc, const char * setting,
|
|||||||
myDebug_P(PSTR("Usage: set master_thermostat <product id>"));
|
myDebug_P(PSTR("Usage: set master_thermostat <product id>"));
|
||||||
ems_setMasterThermostat(0); // default value
|
ems_setMasterThermostat(0); // default value
|
||||||
EMSESP_Settings.master_thermostat = 0; // back to default
|
EMSESP_Settings.master_thermostat = 0; // back to default
|
||||||
ok = true;
|
ok = MYESP_FSACTION_OK;
|
||||||
} else if (wc == 2) {
|
} else if (wc == 2) {
|
||||||
uint8_t pid = atoi(value);
|
uint8_t pid = atoi(value);
|
||||||
EMSESP_Settings.master_thermostat = pid;
|
EMSESP_Settings.master_thermostat = pid;
|
||||||
ems_setMasterThermostat(pid);
|
ems_setMasterThermostat(pid);
|
||||||
// force a scan
|
// force a scan again to detect and set the thermostat
|
||||||
Devices.clear(); // init the device map
|
Devices.clear();
|
||||||
ems_doReadCommand(EMS_TYPE_UBADevices, EMS_Boiler.device_id);
|
ems_doReadCommand(EMS_TYPE_UBADevices, EMS_Boiler.device_id);
|
||||||
ok = true;
|
ok = MYESP_FSACTION_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user