Fixing rebase errors with littlefs/debug refactor

Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
This commit is contained in:
Lukas Bachschwell 2020-10-18 11:06:38 +02:00
parent a6ddd48abb
commit b71bc81c0d
Signed by: lbsadmin
GPG Key ID: CCC6AA87CC8DF425
1 changed files with 62 additions and 92 deletions

View File

@ -22,11 +22,16 @@ void listDir(const char* dirname, uint8_t levels)
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
Serial.printf_P(F("Listing directory: %s\n"), dirname); Serial.printf_P(PSTR("Listing directory: %s\n"), dirname);
} }
#endif #endif
File root = SPIFFS.open(dirname); #if defined(ESP32)
File root = SPIFFS.open(dirname);
#else
File root = LittleFS.open(dirname);
#endif
if (!root) if (!root)
{ {
@ -127,10 +132,11 @@ if (!LittleFS.begin())
listDir("/", 1); listDir("/", 1);
#if defined(ESP32) #if defined(ESP32)
Serial.println(SPIFFS.totalBytes()); Serial.println(SPIFFS.totalBytes());
Serial.println(SPIFFS.usedBytes()); Serial.println(SPIFFS.usedBytes());
#else FSInfo fs_info; #else
FSInfo fs_info;
LittleFS.info(fs_info); LittleFS.info(fs_info);
Serial.println(fs_info.totalBytes); Serial.println(fs_info.totalBytes);
@ -146,23 +152,8 @@ void deleteFile(const char* path)
#else #else
bool exists = LittleFS.exists(path); bool exists = LittleFS.exists(path);
#endif #endif
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.print(exists);
}
#endif
if (!exists) if (!exists)
{
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.print(LittleFS.exists(path));
}
#endif
if (!LittleFS.exists(path))
{ {
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
@ -174,6 +165,13 @@ void deleteFile(const char* path)
return; return;
} }
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.printf_P(PSTR("Deleting file: %s\n"), path);
}
#endif
#if defined(ESP32) #if defined(ESP32)
bool didRemove = SPIFFS.remove(path); bool didRemove = SPIFFS.remove(path);
#else #else
@ -181,15 +179,6 @@ void deleteFile(const char* path)
#endif #endif
if (didRemove) if (didRemove)
{ {
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.printf_P(PSTR("Deleting file: %s\n"), path);
}
#endif
if (LittleFS.remove(path))
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -210,6 +199,12 @@ void deleteFile(const char* path)
void writeFile(const char* path, const char* data) void writeFile(const char* path, const char* data)
{ {
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.printf_P(PSTR("Writing file: %s\n"), path);
}
#endif
#if defined(ESP32) #if defined(ESP32)
File file = SPIFFS.open(path, FILE_WRITE); File file = SPIFFS.open(path, FILE_WRITE);
@ -219,17 +214,6 @@ void writeFile(const char* path, const char* data)
if (!file) if (!file)
{ {
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.printf_P(PSTR("Writing file: %s\n"), path);
}
#endif
File file = LittleFS.open(path, FILE_WRITE);
if (!file)
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -385,9 +369,9 @@ void ESPUIClass::prepareFileSystem()
#endif #endif
#if defined(ESP32) #if defined(ESP32)
SPIFFS.end(); SPIFFS.end();
#else #else
LittleFS.end(); LittleFS.end();
#endif #endif
} }
@ -397,7 +381,8 @@ void onWsEvent(
{ {
switch (type) switch (type)
{ {
case WS_EVT_DISCONNECT: { case WS_EVT_DISCONNECT:
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -408,7 +393,8 @@ void onWsEvent(
break; break;
} }
case WS_EVT_PONG: { case WS_EVT_PONG:
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -419,7 +405,8 @@ void onWsEvent(
break; break;
} }
case WS_EVT_ERROR: { case WS_EVT_ERROR:
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -430,7 +417,8 @@ void onWsEvent(
break; break;
} }
case WS_EVT_CONNECT: { case WS_EVT_CONNECT:
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -450,7 +438,8 @@ void onWsEvent(
} }
break; break;
case WS_EVT_DATA: { case WS_EVT_DATA:
{
String msg = ""; String msg = "";
msg.reserve(len + 1); msg.reserve(len + 1);
@ -580,7 +569,7 @@ void onWsEvent(
else if (msg.startsWith("tabvalue:")) else if (msg.startsWith("tabvalue:"))
{ {
c->callback(c, client->id()); c->callback(c, client->id());
} }
else if (msg.startsWith(F("svalue:"))) else if (msg.startsWith(F("svalue:")))
{ {
c->value = msg.substring(msg.indexOf(':') + 1, msg.lastIndexOf(':')); c->value = msg.substring(msg.indexOf(':') + 1, msg.lastIndexOf(':'));
@ -900,7 +889,7 @@ void ESPUIClass::updateGauge(uint16_t id, int number, int clientId)
updateControlValue(id, String(number), clientId); updateControlValue(id, String(number), clientId);
} }
void ESPUIClass::clearGraph(uint16_t id, int clientId) { } void ESPUIClass::clearGraph(uint16_t id, int clientId) {}
void ESPUIClass::addGraphPoint(uint16_t id, int nValue, int clientId) void ESPUIClass::addGraphPoint(uint16_t id, int nValue, int clientId)
{ {
@ -1050,21 +1039,21 @@ void ESPUIClass::jsonReload()
void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const char* password) void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const char* password)
{ {
ui_title = _title; ui_title = _title;
this->basicAuthUsername = username; this->basicAuthUsername = username;
this->basicAuthPassword = password; this->basicAuthPassword = password;
if (username == nullptr && password == nullptr) if (username == nullptr && password == nullptr)
{ {
basicAuth = false; basicAuth = false;
} }
else else
{ {
basicAuth = true; basicAuth = true;
} }
server = new AsyncWebServer(80); server = new AsyncWebServer(80);
ws = new AsyncWebSocket("/ws"); ws = new AsyncWebSocket("/ws");
#if defined(ESP32) #if defined(ESP32)
bool fsBegin = SPIFFS.begin(); bool fsBegin = SPIFFS.begin();
@ -1073,17 +1062,6 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
#endif #endif
if (!fsBegin) if (!fsBegin)
{ {
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.println(F("FS Mount Failed, PLEASE CHECK THE README ON HOW TO PREPARE YOUR ESP!!!!!!!"));
}
#endif
server = new AsyncWebServer(80);
ws = new AsyncWebSocket("/ws");
if (!LittleFS.begin())
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -1092,6 +1070,16 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
} }
#endif #endif
return;
}
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
listDir("/", 1);
}
#endif
#if defined(ESP32) #if defined(ESP32)
bool indexExists = SPIFFS.exists("/index.htm"); bool indexExists = SPIFFS.exists("/index.htm");
#else #else
@ -1099,15 +1087,6 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
#endif #endif
if (!indexExists) if (!indexExists)
{ {
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
listDir("/", 1);
}
#endif
if (!LittleFS.exists("/index.htm"))
{
#if defined(DEBUG_ESPUI) #if defined(DEBUG_ESPUI)
if (ESPUI.verbosity) if (ESPUI.verbosity)
{ {
@ -1128,8 +1107,6 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
{ {
ws->setAuthentication(ESPUI.basicAuthUsername, ESPUI.basicAuthPassword); ws->setAuthentication(ESPUI.basicAuthUsername, ESPUI.basicAuthPassword);
} }
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
}
#if defined(ESP32) #if defined(ESP32)
server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); server->serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm").setAuthentication(username, password);
#else #else
@ -1143,13 +1120,6 @@ void ESPUIClass::beginSPIFFS(const char* _title, const char* username, const cha
#else #else
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm"); server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm");
#endif #endif
}
// Heap for general Servertest
server->on("/heap", HTTP_GET, [](AsyncWebServerRequest *request) {
if (ESPUI.basicAuth && !request->authenticate(ESPUI.basicAuthUsername, ESPUI.basicAuthPassword))
{
server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm");
} }
// Heap for general Servertest // Heap for general Servertest