added callback registration for user configuration save

This commit is contained in:
Bogdan Pilyugin 2023-09-01 19:39:30 +02:00
parent c32465cf14
commit d8107907fe
3 changed files with 15 additions and 3 deletions

View File

@ -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_ */

View File

@ -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:

View File

@ -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);