From d5bd53b78addf3ce44d1ccdc60e0ca6fc1b87b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 9 Jul 2017 18:10:48 +0200 Subject: [PATCH] cleaning & linked boot button to new factory reset impl --- user/io.c | 14 ++++++++------ user/user_main.c | 2 +- user/wifimgr.c | 13 ++++++++++--- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/user/io.c b/user/io.c index e3ba069..4969e20 100644 --- a/user/io.c +++ b/user/io.c @@ -11,6 +11,8 @@ #include #include "ansi_parser_callbacks.h" +#include "wifimgr.h" +#include "persist.h" #define BTNGPIO 0 @@ -74,16 +76,16 @@ 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 + if (resetCnt>=10) { //5 secs pressed - FR (timer is at 500 ms) info("BOOT-button triggered FACTORY RESET!"); - apars_handle_OSC_FactoryReset(); + persist_restore_default(); } else if (resetCnt>=2) { //1 sec pressed - wifi_station_disconnect(); - wifi_set_opmode(STATIONAP_MODE); //reset to AP+STA mode - info("BOOT-button triggered reset to AP mode, restarting..."); + info("BOOT-button triggered reset to AP mode..."); - system_restart(); + wificonf->opmode = STATIONAP_MODE; + persist_store(); + wifimgr_apply_settings(); } resetCnt=0; } diff --git a/user/user_main.c b/user/user_main.c index 67c7762..8730ff9 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -91,7 +91,7 @@ void ICACHE_FLASH_ATTR user_init(void) // Prevent WiFi starting and connecting by default // let wifi manager handle it wifi_station_set_auto_connect(false); - wifi_set_opmode(NULL_MODE); + wifi_set_opmode(NULL_MODE); // save to flash if changed - this might avoid the current spike on startup? printf("\r\n"); banner("====== ESP8266 Remote Terminal ======"); diff --git a/user/wifimgr.c b/user/wifimgr.c index 5d120e4..02f170f 100644 --- a/user/wifimgr.c +++ b/user/wifimgr.c @@ -40,7 +40,7 @@ wifimgr_restore_defaults(void) strcpy((char *) wificonf->sta_hostname, (char *) wificonf->ap_ssid); // use the same value for sta_hostname as AP name wificonf->sta_dhcp_enable = true; - IP4_ADDR(&wificonf->sta_ip.ip, 192, 168, 0, (mac[5]==1?2:mac[5]));// avoid being the same as "default gw" + IP4_ADDR(&wificonf->sta_ip.ip, 192, 168, 0, (mac[5]==1?2:mac[5])); // avoid being the same as "default gw" IP4_ADDR(&wificonf->sta_ip.netmask, 255, 255, 255, 0); IP4_ADDR(&wificonf->sta_ip.gw, 192, 168, 0, 1); } @@ -159,8 +159,15 @@ wifimgr_apply_settings(void) info("[WiFi] Initializing..."); // Force wifi cycle - wifi_set_opmode(NULL_MODE); - wifi_set_opmode(wificonf->opmode); + // Disconnect - may not be needed? + WIFI_MODE opmode = wifi_get_opmode(); + if (opmode == STATIONAP_MODE || opmode == STATION_MODE) { + wifi_station_disconnect(); + } + + // This should hopefully deinit everything + wifi_set_opmode_current(NULL_MODE); + wifi_set_opmode_current(wificonf->opmode); // Configure the client if (wificonf->opmode == STATIONAP_MODE || wificonf->opmode == STATION_MODE) {