From 36e0ab5f3a196e509d186082f00aaa55498eb164 Mon Sep 17 00:00:00 2001 From: Pavel Brychta Date: Fri, 1 Apr 2022 08:06:56 +0200 Subject: [PATCH] Snaha o zprehledneni kodu. --- src/WiFiConfig.cpp | 103 ++++++++++++++++++++++----------------------- src/WiFiConfig.h | 9 ++-- 2 files changed, 55 insertions(+), 57 deletions(-) diff --git a/src/WiFiConfig.cpp b/src/WiFiConfig.cpp index c3bdd63..d40023e 100644 --- a/src/WiFiConfig.cpp +++ b/src/WiFiConfig.cpp @@ -5,8 +5,8 @@ #include #include "embHTML.h" #include -#include #include +#include #ifdef USE_WIFICONFIG_FSEDITOR # include # include @@ -49,7 +49,7 @@ static bool _doReconfig = false; // TODO: mozna nejak elegantneji? Ale zase setr String WifiConfigAPSSID(void) { - String ssid = SETUP_SSID; + String ssid = F(SETUP_SSID); return ssid; } @@ -100,15 +100,12 @@ uint8_t * getOurMAC(uint8_t *mac) WiFiConfigUsrParameter::WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, unsigned int length, storeparam_cb cb) { - _next = NULL; _cb = cb; _id = id; _label = label; _length = length; _value = new char[length + 1]; - for (unsigned int i = 0; i < length; i++) { - _value[i] = 0; - } + _value[0] = 0; if (defaultValue != NULL) { strncpy(_value, defaultValue, length); } @@ -303,69 +300,69 @@ String WiFiConfig::rootProcessor(const String &var) String content; if (var == "STATUS") { - switch (_status) { + switch (_status) { #if defined(ESP8266) - case STATION_IDLE: - content = F("Klid"); - break; + case STATION_IDLE: + content = F("Klid"); + break; - case STATION_CONNECTING: - content = F("Připojování"); - break; + case STATION_CONNECTING: + content = F("Připojování"); + break; - case STATION_WRONG_PASSWORD: - content = F("Špatné heslo"); - break; + case STATION_WRONG_PASSWORD: + content = F("Špatné heslo"); + break; - case STATION_NO_AP_FOUND: - content = F("AP nenalezen"); - break; + case STATION_NO_AP_FOUND: + content = F("AP nenalezen"); + break; - case STATION_CONNECT_FAIL: - content = F("Připojení selhalo"); - break; + case STATION_CONNECT_FAIL: + content = F("Připojení selhalo"); + break; - case STATION_GOT_IP: - content = F("Získaná ip"); - break; + case STATION_GOT_IP: + content = F("Získaná ip"); + break; - case 0xfe: - content = F("Špatná konfigurace"); - break; + case 0xfe: + content = F("Špatná konfigurace"); + break; - case 0xff: - content = F("Vynucená konfigurace"); - break; + case 0xff: + content = F("Vynucená konfigurace"); + break; - default: - content = F("Neznámý"); - break; + default: + content = F("Neznámý"); + break; #else - case WL_IDLE_STATUS: - content = F("Klid"); - break; + case WL_IDLE_STATUS: + content = F("Klid"); + break; - case WL_NO_SSID_AVAIL: - content = F("AP nenalezen"); - break; + case WL_NO_SSID_AVAIL: + content = F("AP nenalezen"); + break; - case WL_CONNECT_FAILED: - content = F("Připojení selhalo"); - break; + case WL_CONNECT_FAILED: + content = F("Připojení selhalo"); + break; - case 0xfe: - content = F("Špatná konfigurace"); - break; + case 0xfe: + content = F("Špatná konfigurace"); + break; - case 0xff: - content = F("Vynucená konfigurace"); - break; + case 0xff: + content = F("Vynucená konfigurace"); + break; - default: - content = F("Neznámý"); - break; + default: + content = F("Neznámý"); + break; #endif - } + } } else if (var == F("RESTORE")) { if (USEDFS.exists(F(WIFICFG_OLD_FILE))) { content = FPSTR(PAGE_RESTORE); diff --git a/src/WiFiConfig.h b/src/WiFiConfig.h index f8802ab..2db9698 100644 --- a/src/WiFiConfig.h +++ b/src/WiFiConfig.h @@ -134,15 +134,16 @@ private: int _length; storeparam_cb _cb; - WiFiConfigUsrParameter *_next; - - friend class WiFiConfig; + WiFiConfigUsrParameter *_next = nullptr; }; class WiFiConfig { public: - WiFiConfig(): _params(nullptr), _timeout(0) {} + WiFiConfig() + : _params(nullptr) + , _timeout(0) + {} wificonfigresult_t begin(int forceConfigure, wificonfig_cb cb); wificonfigresult_t begin(int forceConfigure, int timeout, wificonfig_cb cb); void addParameter(WiFiConfigUsrParameter *p);