Snaha o zprehledneni kodu.

This commit is contained in:
Pavel Brychta 2022-04-01 08:06:56 +02:00
parent 1ebcab01e7
commit 36e0ab5f3a
2 changed files with 55 additions and 57 deletions

View File

@ -5,8 +5,8 @@
#include <sysvars.hpp> #include <sysvars.hpp>
#include "embHTML.h" #include "embHTML.h"
#include <encString.hpp> #include <encString.hpp>
#include <FS.h>
#include <definefs.hpp> #include <definefs.hpp>
#include <FS.h>
#ifdef USE_WIFICONFIG_FSEDITOR #ifdef USE_WIFICONFIG_FSEDITOR
# include <SPIFFSEditor.h> # include <SPIFFSEditor.h>
# include <FSWebEditor.h> # include <FSWebEditor.h>
@ -49,7 +49,7 @@ static bool _doReconfig = false; // TODO: mozna nejak elegantneji? Ale zase setr
String WifiConfigAPSSID(void) String WifiConfigAPSSID(void)
{ {
String ssid = SETUP_SSID; String ssid = F(SETUP_SSID);
return 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) WiFiConfigUsrParameter::WiFiConfigUsrParameter(const char *id, const char *label, const char *defaultValue, unsigned int length, storeparam_cb cb)
{ {
_next = NULL;
_cb = cb; _cb = cb;
_id = id; _id = id;
_label = label; _label = label;
_length = length; _length = length;
_value = new char[length + 1]; _value = new char[length + 1];
for (unsigned int i = 0; i < length; i++) { _value[0] = 0;
_value[i] = 0;
}
if (defaultValue != NULL) { if (defaultValue != NULL) {
strncpy(_value, defaultValue, length); strncpy(_value, defaultValue, length);
} }
@ -303,69 +300,69 @@ String WiFiConfig::rootProcessor(const String &var)
String content; String content;
if (var == "STATUS") { if (var == "STATUS") {
switch (_status) { switch (_status) {
#if defined(ESP8266) #if defined(ESP8266)
case STATION_IDLE: case STATION_IDLE:
content = F("Klid"); content = F("Klid");
break; break;
case STATION_CONNECTING: case STATION_CONNECTING:
content = F("Připojování"); content = F("Připojování");
break; break;
case STATION_WRONG_PASSWORD: case STATION_WRONG_PASSWORD:
content = F("Špatné heslo"); content = F("Špatné heslo");
break; break;
case STATION_NO_AP_FOUND: case STATION_NO_AP_FOUND:
content = F("AP nenalezen"); content = F("AP nenalezen");
break; break;
case STATION_CONNECT_FAIL: case STATION_CONNECT_FAIL:
content = F("Připojení selhalo"); content = F("Připojení selhalo");
break; break;
case STATION_GOT_IP: case STATION_GOT_IP:
content = F("Získaná ip"); content = F("Získaná ip");
break; break;
case 0xfe: case 0xfe:
content = F("Špatná konfigurace"); content = F("Špatná konfigurace");
break; break;
case 0xff: case 0xff:
content = F("Vynucená konfigurace"); content = F("Vynucená konfigurace");
break; break;
default: default:
content = F("Neznámý"); content = F("Neznámý");
break; break;
#else #else
case WL_IDLE_STATUS: case WL_IDLE_STATUS:
content = F("Klid"); content = F("Klid");
break; break;
case WL_NO_SSID_AVAIL: case WL_NO_SSID_AVAIL:
content = F("AP nenalezen"); content = F("AP nenalezen");
break; break;
case WL_CONNECT_FAILED: case WL_CONNECT_FAILED:
content = F("Připojení selhalo"); content = F("Připojení selhalo");
break; break;
case 0xfe: case 0xfe:
content = F("Špatná konfigurace"); content = F("Špatná konfigurace");
break; break;
case 0xff: case 0xff:
content = F("Vynucená konfigurace"); content = F("Vynucená konfigurace");
break; break;
default: default:
content = F("Neznámý"); content = F("Neznámý");
break; break;
#endif #endif
} }
} else if (var == F("RESTORE")) { } else if (var == F("RESTORE")) {
if (USEDFS.exists(F(WIFICFG_OLD_FILE))) { if (USEDFS.exists(F(WIFICFG_OLD_FILE))) {
content = FPSTR(PAGE_RESTORE); content = FPSTR(PAGE_RESTORE);

View File

@ -134,15 +134,16 @@ private:
int _length; int _length;
storeparam_cb _cb; storeparam_cb _cb;
WiFiConfigUsrParameter *_next; WiFiConfigUsrParameter *_next = nullptr;
friend class WiFiConfig;
}; };
class WiFiConfig class WiFiConfig
{ {
public: public:
WiFiConfig(): _params(nullptr), _timeout(0) {} WiFiConfig()
: _params(nullptr)
, _timeout(0)
{}
wificonfigresult_t begin(int forceConfigure, wificonfig_cb cb); wificonfigresult_t begin(int forceConfigure, wificonfig_cb cb);
wificonfigresult_t begin(int forceConfigure, int timeout, wificonfig_cb cb); wificonfigresult_t begin(int forceConfigure, int timeout, wificonfig_cb cb);
void addParameter(WiFiConfigUsrParameter *p); void addParameter(WiFiConfigUsrParameter *p);