From d8107907fe39ec5014fb840d3e147fae96d8d593 Mon Sep 17 00:00:00 2001 From: bogdan Date: Fri, 1 Sep 2023 19:39:30 +0200 Subject: [PATCH] added callback registration for user configuration save --- include/UserCallbacks.h | 2 ++ src/SysComm.c | 11 +++++++++-- src/SysConfiguration.c | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/UserCallbacks.h b/include/UserCallbacks.h index d370233..c3998c4 100644 --- a/include/UserCallbacks.h +++ b/include/UserCallbacks.h @@ -41,5 +41,7 @@ void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req, //User handler for various payload types void regCustomPayloadTypeHandler(sys_error_code (*payload_handler)(data_message_t *MSG)); +//User handler for save App configuration +void regCustomSaveConf(esp_err_t (custom_saveconf)(void)); #endif /* COMPONENTS_WEBGUIAPP_INCLUDE_USERCALLBACKS_H_ */ diff --git a/src/SysComm.c b/src/SysComm.c index fb977b7..4c9237e 100644 --- a/src/SysComm.c +++ b/src/SysComm.c @@ -48,13 +48,16 @@ #define MAX_JSON_DATA_SIZE 1024 sys_error_code (*CustomPayloadTypeHandler)(data_message_t *MSG); +esp_err_t (*CustomSaveConf)(void); void regCustomPayloadTypeHandler(sys_error_code (*payload_handler)(data_message_t *MSG)) { CustomPayloadTypeHandler = payload_handler; } - - +void regCustomSaveConf(esp_err_t (custom_saveconf)(void)) +{ + CustomSaveConf = custom_saveconf; +} static sys_error_code PayloadType_1_Handler(data_message_t *MSG) { @@ -163,9 +166,13 @@ static sys_error_code PayloadType_1_Handler(data_message_t *MSG) break; case 1: WriteNVSSysConfig(GetSysConf()); + if (CustomSaveConf != NULL) + CustomSaveConf(); break; case 2: WriteNVSSysConfig(GetSysConf()); + if (CustomSaveConf != NULL) + CustomSaveConf(); DelayedRestart(); break; default: diff --git a/src/SysConfiguration.c b/src/SysConfiguration.c index c35e96e..6461a2f 100644 --- a/src/SysConfiguration.c +++ b/src/SysConfiguration.c @@ -306,7 +306,10 @@ static void ResetSysConfig(SYS_CONFIG *Conf) #endif #if CONFIG_WEBGUIAPP_ETHERNET_ENABLE -Conf->ethSettings.Flags1.bIsETHEnabled = CONFIG_WEBGUIAPP_ETHERNET_ON; +Conf->ethSettings.Flags1.bIsETHEnabled = false; +#if CONFIG_WEBGUIAPP_ETHERNET_ON +Conf->ethSettings.Flags1.bIsETHEnabled = true; +#endif esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_ETH_IP_DEFAULT, (esp_ip4_addr_t*) &Conf->ethSettings.IPAddr); esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_ETH_MASK_DEFAULT, (esp_ip4_addr_t*) &Conf->ethSettings.Mask); esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_ETH_GATEWAY_DEFAULT, (esp_ip4_addr_t*) &Conf->ethSettings.Gateway);