From 97d4ff12da954c6d2eb447ab8ed336e1b37d40e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 24 Jul 2017 01:07:09 +0200 Subject: [PATCH] persist tweaks --- user/cgi_persist.c | 1 + user/io.c | 7 ++++--- user/persist.c | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/user/cgi_persist.c b/user/cgi_persist.c index 667baaa..3a18c5d 100644 --- a/user/cgi_persist.c +++ b/user/cgi_persist.c @@ -55,6 +55,7 @@ cgiPersistRestoreDefaults(HttpdConnData *connData) } persist_restore_default(); + httpdRedirect(connData, SET_REDIR_SUC); return HTTPD_CGI_DONE; } diff --git a/user/io.c b/user/io.c index 4969e20..8b03eec 100644 --- a/user/io.c +++ b/user/io.c @@ -76,16 +76,17 @@ static void ICACHE_FLASH_ATTR resetBtnTimerCb(void *arg) { PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK); - if (resetCnt>=10) { //5 secs pressed - FR (timer is at 500 ms) - info("BOOT-button triggered FACTORY RESET!"); + if (resetCnt>=12) { //6 secs pressed - FR (timer is at 500 ms) + info("Restoring to default settings via BOOT button!"); persist_restore_default(); } else if (resetCnt>=2) { //1 sec pressed info("BOOT-button triggered reset to AP mode..."); + // Enter "rescue mode". wificonf->opmode = STATIONAP_MODE; - persist_store(); wifimgr_apply_settings(); + persist_store(); } resetCnt=0; } diff --git a/user/persist.c b/user/persist.c index c521ee9..857188b 100644 --- a/user/persist.c +++ b/user/persist.c @@ -144,14 +144,17 @@ persist_load_hard_default(void) } /** - * Restore default settings & apply + * Restore default settings & apply. also persists. */ void ICACHE_FLASH_ATTR persist_restore_default(void) { info("[Persist] Restoring live settings to stored defaults..."); + memcpy(&persist.current, &persist.defaults, sizeof(AppConfigBundle)); apply_live_settings(); + persist_store(); + info("[Persist] Settings restored to stored defaults."); }