mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-22 09:10:54 +00:00
Merge pull request #20 from wvdv2002/master
Refactored debug define into DEBUG_ESPUI
This commit is contained in:
commit
30a91bdb85
@ -85,7 +85,7 @@ void ESPUIClass::list() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void deleteFile(const char *path) {
|
void deleteFile(const char *path) {
|
||||||
if (debug) Serial.print(SPIFFS.exists(path));
|
if (DEBUG_ESPUI) Serial.print(SPIFFS.exists(path));
|
||||||
if (!SPIFFS.exists(path)) {
|
if (!SPIFFS.exists(path)) {
|
||||||
Serial.printf("File: %s does not exist, not deleting\n", path);
|
Serial.printf("File: %s does not exist, not deleting\n", path);
|
||||||
return;
|
return;
|
||||||
@ -169,7 +169,7 @@ void ESPUIClass::prepareFileSystem() {
|
|||||||
Serial.println("Done Initializing filesystem :-)");
|
Serial.println("Done Initializing filesystem :-)");
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
if(debug) listDir("/", 1);
|
if(DEBUG_ESPUI) listDir("/", 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SPIFFS.end();
|
SPIFFS.end();
|
||||||
@ -180,28 +180,28 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
|
|||||||
AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WS_EVT_DISCONNECT: {
|
case WS_EVT_DISCONNECT: {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.printf("Disconnected!\n");
|
Serial.printf("Disconnected!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WS_EVT_PONG: {
|
case WS_EVT_PONG: {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.printf("Received PONG!\n");
|
Serial.printf("Received PONG!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WS_EVT_ERROR: {
|
case WS_EVT_ERROR: {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.printf("WebSocket Error!\n");
|
Serial.printf("WebSocket Error!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WS_EVT_CONNECT: {
|
case WS_EVT_CONNECT: {
|
||||||
if (debug) {
|
if (DEBUG_ESPUI) {
|
||||||
Serial.print("Connected: ");
|
Serial.print("Connected: ");
|
||||||
Serial.println(client->id());
|
Serial.println(client->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
ESPUI.jsonDom(client);
|
ESPUI.jsonDom(client);
|
||||||
if (debug) {
|
if (DEBUG_ESPUI) {
|
||||||
Serial.println("JSON Data Sent to Client!");
|
Serial.println("JSON Data Sent to Client!");
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@ -213,7 +213,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
|
|||||||
|
|
||||||
int id = msg.substring(msg.lastIndexOf(':') + 1).toInt();
|
int id = msg.substring(msg.lastIndexOf(':') + 1).toInt();
|
||||||
if (id >= ESPUI.cIndex) {
|
if (id >= ESPUI.cIndex) {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("Maleformated id in websocket message");
|
Serial.println("Maleformated id in websocket message");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -268,7 +268,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
|
|||||||
|
|
||||||
int ESPUIClass::label(const char *label, int color, String value) {
|
int ESPUIClass::label(const char *label, int color, String value) {
|
||||||
if (labelExists(label)) {
|
if (labelExists(label)) {
|
||||||
if (debug) Serial.println("UI ERROR: Element " + String(label) + " exists, skipping creating element!");
|
if (DEBUG_ESPUI) Serial.println("UI ERROR: Element " + String(label) + " exists, skipping creating element!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ int ESPUIClass::label(const char *label, int color, String value) {
|
|||||||
|
|
||||||
int ESPUIClass::graph(const char *label, int color) {
|
int ESPUIClass::graph(const char *label, int color) {
|
||||||
if (labelExists(label)) {
|
if (labelExists(label)) {
|
||||||
if (debug) Serial.println("UI ERROR: Element " + String(label) + " exists, skipping creating element!");
|
if (DEBUG_ESPUI) Serial.println("UI ERROR: Element " + String(label) + " exists, skipping creating element!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ int ESPUIClass::graph(const char *label, int color) {
|
|||||||
// TODO: this still needs a range setting
|
// TODO: this still needs a range setting
|
||||||
int ESPUIClass::slider(const char *label, void (*callBack)(Control, int), int color, String value) {
|
int ESPUIClass::slider(const char *label, void (*callBack)(Control, int), int color, String value) {
|
||||||
if (labelExists(label)) {
|
if (labelExists(label)) {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("UI ERROR: Element " + String(label) +
|
Serial.println("UI ERROR: Element " + String(label) +
|
||||||
" exists, skipping creating element!");
|
" exists, skipping creating element!");
|
||||||
return -1;
|
return -1;
|
||||||
@ -330,7 +330,7 @@ int ESPUIClass::slider(const char *label, void (*callBack)(Control, int), int co
|
|||||||
int ESPUIClass::button(const char *label, void (*callBack)(Control, int),
|
int ESPUIClass::button(const char *label, void (*callBack)(Control, int),
|
||||||
int color, String value) {
|
int color, String value) {
|
||||||
if (labelExists(label)) {
|
if (labelExists(label)) {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("UI ERROR: Element " + String(label) +
|
Serial.println("UI ERROR: Element " + String(label) +
|
||||||
" exists, skipping creating element!");
|
" exists, skipping creating element!");
|
||||||
return -1;
|
return -1;
|
||||||
@ -355,7 +355,7 @@ int ESPUIClass::button(const char *label, void (*callBack)(Control, int),
|
|||||||
|
|
||||||
int ESPUIClass::switcher(const char *label, bool startState, void (*callBack)(Control, int), int color) {
|
int ESPUIClass::switcher(const char *label, bool startState, void (*callBack)(Control, int), int color) {
|
||||||
if (labelExists(label)) {
|
if (labelExists(label)) {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("UI ERROR: Element " + String(label) +
|
Serial.println("UI ERROR: Element " + String(label) +
|
||||||
" exists, skipping creating element!");
|
" exists, skipping creating element!");
|
||||||
return -1;
|
return -1;
|
||||||
@ -376,7 +376,7 @@ int ESPUIClass::switcher(const char *label, bool startState, void (*callBack)(Co
|
|||||||
int ESPUIClass::pad(const char *label, bool center,
|
int ESPUIClass::pad(const char *label, bool center,
|
||||||
void (*callBack)(Control, int), int color) {
|
void (*callBack)(Control, int), int color) {
|
||||||
if (labelExists(label)) {
|
if (labelExists(label)) {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("UI ERROR: Element " + String(label) +
|
Serial.println("UI ERROR: Element " + String(label) +
|
||||||
" exists, skipping creating element!");
|
" exists, skipping creating element!");
|
||||||
return -1;
|
return -1;
|
||||||
@ -399,7 +399,7 @@ int ESPUIClass::pad(const char *label, bool center,
|
|||||||
// TODO: min and max need to be saved, they also need to be sent to the frontend
|
// TODO: min and max need to be saved, they also need to be sent to the frontend
|
||||||
int ESPUIClass::number(const char *label, void (*callBack)(Control, int), int color, int number, int min, int max) {
|
int ESPUIClass::number(const char *label, void (*callBack)(Control, int), int color, int number, int min, int max) {
|
||||||
if (labelExists(label)) {
|
if (labelExists(label)) {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("UI ERROR: Element " + String(label) + " exists, skipping creating element!");
|
Serial.println("UI ERROR: Element " + String(label) + " exists, skipping creating element!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -428,14 +428,14 @@ void ESPUIClass::print(int id, String value) {
|
|||||||
root.printTo(json);
|
root.printTo(json);
|
||||||
this->ws->textAll(json);
|
this->ws->textAll(json);
|
||||||
} else {
|
} else {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println(String("Error: ") + String(id) + String(" is no label"));
|
Serial.println(String("Error: ") + String(id) + String(" is no label"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::print(String label, String value) {
|
void ESPUIClass::print(String label, String value) {
|
||||||
if (!labelExists(label)) {
|
if (!labelExists(label)) {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("UI ERROR: Element does not " + String(label) +
|
Serial.println("UI ERROR: Element does not " + String(label) +
|
||||||
" exist, cannot update!");
|
" exist, cannot update!");
|
||||||
return;
|
return;
|
||||||
@ -455,7 +455,7 @@ void ESPUIClass::updateSlider(int id, int nValue, int clientId) {
|
|||||||
root.printTo(json);
|
root.printTo(json);
|
||||||
textThem(json, clientId);
|
textThem(json, clientId);
|
||||||
} else {
|
} else {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println(String("Error: ") + String(id) + String(" is no slider"));
|
Serial.println(String("Error: ") + String(id) + String(" is no slider"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -472,13 +472,13 @@ void ESPUIClass::updateSwitcher(int id, bool nValue, int clientId) {
|
|||||||
root.printTo(json);
|
root.printTo(json);
|
||||||
textThem(json, clientId);
|
textThem(json, clientId);
|
||||||
} else {
|
} else {
|
||||||
if (debug) Serial.println(String("Error: ") + String(id) + String(" is no switcher"));
|
if (DEBUG_ESPUI) Serial.println(String("Error: ") + String(id) + String(" is no switcher"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::updateSwitcher(String label, bool nValue, int clientId) {
|
void ESPUIClass::updateSwitcher(String label, bool nValue, int clientId) {
|
||||||
if (!labelExists(label)) {
|
if (!labelExists(label)) {
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("UI ERROR: Element does not " + String(label) + " exist, cannot update!");
|
Serial.println("UI ERROR: Element does not " + String(label) + " exist, cannot update!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -497,13 +497,13 @@ void ESPUIClass::updateNumber(int id, int number, int clientId) {
|
|||||||
root.printTo(json);
|
root.printTo(json);
|
||||||
textThem(json, clientId);
|
textThem(json, clientId);
|
||||||
} else {
|
} else {
|
||||||
if (debug) Serial.println(String("Error: ") + String(id) + String(" is no number"));
|
if (DEBUG_ESPUI) Serial.println(String("Error: ") + String(id) + String(" is no number"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPUIClass::updateNumber(String label, int number, int clientId) {
|
void ESPUIClass::updateNumber(String label, int number, int clientId) {
|
||||||
if (!labelExists(label)) {
|
if (!labelExists(label)) {
|
||||||
if (debug) Serial.println("UI ERROR: Element does not " + String(label) + " exist, cannot update!");
|
if (DEBUG_ESPUI) Serial.println("UI ERROR: Element does not " + String(label) + " exist, cannot update!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateNumber(getIdByLabel(label), number, clientId);
|
updateNumber(getIdByLabel(label), number, clientId);
|
||||||
@ -601,7 +601,7 @@ void ESPUIClass::beginSPIFFS(const char *_title) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server->begin();
|
server->begin();
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("UI Initialized");
|
Serial.println("UI Initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -664,7 +664,7 @@ void ESPUIClass::begin(const char *_title) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server->begin();
|
server->begin();
|
||||||
if (debug)
|
if (DEBUG_ESPUI)
|
||||||
Serial.println("UI Initialized");
|
Serial.println("UI Initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef ESPUI_h
|
#ifndef ESPUI_h
|
||||||
#define ESPUI_h
|
#define ESPUI_h
|
||||||
|
|
||||||
#define debug true
|
#define DEBUG_ESPUI true
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user