1
0
mirror of https://github.com/s00500/ESPUI.git synced 2025-07-04 11:20:19 +00:00

6 Commits
1.4.5 ... 1.4.6

Author SHA1 Message Date
b421b84b11 version bump 2018-05-13 19:50:48 +02:00
f1012b2fe2 Closes #12 implementing all events for websockets 2018-05-13 19:44:56 +02:00
cc633a7c85 Closes #11 Bugfix for retrun values on error 2018-05-13 19:39:21 +02:00
40b13430cb #9 adding control id as return value 2018-04-17 19:54:07 +02:00
dda4e9e771 Merge pull request #8 from per1234/keywords-separa
Use correct separator in keywords.txt
2018-02-20 09:19:09 +01:00
1390b73218 Use correct separator in keywords.txt
The Arduino IDE currently requires the use of a tab separator between the name and identifier. Without this tab the keyword is not highlighted.

Reference:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keywords
2018-02-19 23:39:35 -08:00
5 changed files with 107 additions and 74 deletions

View File

@ -51,7 +51,7 @@ Download the [Repository](https://github.com/s00500/ESPUI/archive/master.zip), G
ESPUI **NEEDS** its files burnt on the SPIFFS filesystem on the ESP. **Without this ESPUI will NOT work at all** ESPUI **NEEDS** its files burnt on the SPIFFS filesystem on the ESP. **Without this ESPUI will NOT work at all**
There are now two ways to do this: you can either use the upload tool or you use the library function `ESPUI.prepareFileSystem()` There are now two ways to do this: you can either use the upload tool or you use the library function `ESPUI.prepareFileSystem()`
#### Simple filesystem preparation (recomended) #### Simple filesystem preparation (recomended, but currently not working well on esp32, see issues)
Just open the example sketch **prepareFileSystem** and run it on the ESP, (give it 5 - 10 seconds), Just open the example sketch **prepareFileSystem** and run it on the ESP, (give it 5 - 10 seconds),
The library will create all needed files. The library will create all needed files.
@ -81,10 +81,13 @@ Now you are set to go and use any code you want to with this library
- ~~Setup SPIFFS using values in program memory~~ - ~~Setup SPIFFS using values in program memory~~
- ~~ESP8266 support~~ - ~~ESP8266 support~~
- Document slider - Document slider
- New images in docu
- proper return value (as int and not as string) for slider - proper return value (as int and not as string) for slider
- Maybe a slider range setting, meanwhile please use map() - Maybe a slider range setting, meanwhile please use map()
- Improve slider stability - Improve slider stability
- Improve general stability - Improve general stability
- Multiline Labels
- PlattformIO Integration
## Documentation ## Documentation

View File

@ -1,5 +1,5 @@
name=ESPUI name=ESPUI
version=1.4.5 version=1.4.6
author=Lukas Bachschwell author=Lukas Bachschwell
maintainer=Lukas Bachschwell <lukas@lbsfilm.at> maintainer=Lukas Bachschwell <lukas@lbsfilm.at>
sentence=ESP32 and ESP8266 Web Interface Library sentence=ESP32 and ESP8266 Web Interface Library

View File

@ -108,11 +108,19 @@ void writeFile(const char *path, const char *data) {
Serial.println("Failed to open file for writing"); Serial.println("Failed to open file for writing");
return; return;
} }
#if defined(ESP32)
if (file.print(data)) {
Serial.println("File written");
} else {
Serial.println("Write failed");
}
#else
if (file.print(FPSTR(data))) { if (file.print(FPSTR(data))) {
Serial.println("File written"); Serial.println("File written");
} else { } else {
Serial.println("Write failed"); Serial.println("Write failed");
} }
#endif
file.close(); file.close();
} }
@ -175,10 +183,21 @@ void ESPUIClass::prepareFileSystem() {
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, 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)
Serial.printf("Disconnected!\n"); Serial.printf("Disconnected!\n");
break; break;
}
case WS_EVT_PONG: {
if (debug)
Serial.printf("Received PONG!\n");
break;
}
case WS_EVT_ERROR: {
if (debug)
Serial.printf("WebSocket Error!\n");
break;
}
case WS_EVT_CONNECT: { case WS_EVT_CONNECT: {
if (debug) { if (debug) {
Serial.print("Connected: "); Serial.print("Connected: ");
@ -190,19 +209,20 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
Serial.println("JSON Data Sent to Client!"); Serial.println("JSON Data Sent to Client!");
} }
} break; } break;
case WS_EVT_DATA: case WS_EVT_DATA: {
String msg = ""; String msg = "";
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
msg += (char)data[i]; msg += (char)data[i];
} }
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)
Serial.println("Maleformated id in websocket message"); Serial.println("Maleformated id in websocket message");
return; return;
} }
Control *c =
ESPUI.controls[msg.substring(msg.lastIndexOf(':') + 1).toInt()]; Control *c = ESPUI.controls[msg.substring(msg.lastIndexOf(':') + 1).toInt()];
if (msg.startsWith("bdown:")) { if (msg.startsWith("bdown:")) {
c->callback(*c, B_DOWN); c->callback(*c, B_DOWN);
@ -240,16 +260,19 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
ESPUI.updateSlider(c->id, value, client->id()); ESPUI.updateSlider(c->id, value, client->id());
c->callback(*c, SL_VALUE); c->callback(*c, SL_VALUE);
} }
}
break;
default:
break; break;
} }
} }
void 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) if (debug)
Serial.println("UI ERROR: Element " + String(label) + Serial.println("UI ERROR: Element " + String(label) +
" exists, skipping creating element!"); " exists, skipping creating element!");
return; return -1;
} }
Control *newL = new Control(); Control *newL = new Control();
@ -264,16 +287,17 @@ void ESPUIClass::label(const char *label, int color, String value) {
newL->id = cIndex; newL->id = cIndex;
controls[cIndex] = newL; controls[cIndex] = newL;
cIndex++; cIndex++;
return cIndex - 1;
} }
// TODO: this still needs a range setting // TODO: this still needs a range setting
void ESPUIClass::slider(const char *label, void (*callBack)(Control, int), int ESPUIClass::slider(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)
Serial.println("UI ERROR: Element " + String(label) + Serial.println("UI ERROR: Element " + String(label) +
" exists, skipping creating element!"); " exists, skipping creating element!");
return; return -1;
} }
Control *newSL = new Control(); Control *newSL = new Control();
@ -288,15 +312,16 @@ void ESPUIClass::slider(const char *label, void (*callBack)(Control, int),
newSL->id = cIndex; newSL->id = cIndex;
controls[cIndex] = newSL; controls[cIndex] = newSL;
cIndex++; cIndex++;
return cIndex - 1;
} }
void 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)
Serial.println("UI ERROR: Element " + String(label) + Serial.println("UI ERROR: Element " + String(label) +
" exists, skipping creating element!"); " exists, skipping creating element!");
return; return -1;
} }
Control *newB = new Control(); Control *newB = new Control();
@ -313,15 +338,16 @@ void ESPUIClass::button(const char *label, void (*callBack)(Control, int),
newB->id = cIndex; newB->id = cIndex;
controls[cIndex] = newB; controls[cIndex] = newB;
cIndex++; cIndex++;
return cIndex - 1;
} }
void ESPUIClass::switcher(const char *label, bool startState, int ESPUIClass::switcher(const char *label, bool startState,
void (*callBack)(Control, int), int color) { void (*callBack)(Control, int), int color) {
if (labelExists(label)) { if (labelExists(label)) {
if (debug) if (debug)
Serial.println("UI ERROR: Element " + String(label) + Serial.println("UI ERROR: Element " + String(label) +
" exists, skipping creating element!"); " exists, skipping creating element!");
return; return -1;
} }
Control *newS = new Control(); Control *newS = new Control();
@ -333,15 +359,16 @@ void ESPUIClass::switcher(const char *label, bool startState,
newS->id = cIndex; newS->id = cIndex;
controls[cIndex] = newS; controls[cIndex] = newS;
cIndex++; cIndex++;
return cIndex - 1;
} }
void 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)
Serial.println("UI ERROR: Element " + String(label) + Serial.println("UI ERROR: Element " + String(label) +
" exists, skipping creating element!"); " exists, skipping creating element!");
return; return -1;
} }
Control *newP = new Control(); Control *newP = new Control();
@ -355,6 +382,7 @@ void ESPUIClass::pad(const char *label, bool center,
newP->id = cIndex; newP->id = cIndex;
controls[cIndex] = newP; controls[cIndex] = newP;
cIndex++; cIndex++;
return cIndex - 1;
} }
void ESPUIClass::print(int id, String value) { void ESPUIClass::print(int id, String value) {
@ -510,7 +538,9 @@ void ESPUIClass::begin(const char *_title) {
}); });
server->onNotFound( server->onNotFound(
[](AsyncWebServerRequest *request) { request->send(404); }); [](AsyncWebServerRequest *request) {
request->send(404);
});
server->begin(); server->begin();
if (debug) if (debug)

View File

@ -91,15 +91,15 @@ public:
void prepareFileSystem(); // Initially preps the filesystem and loads a lot of stuff into SPIFFS void prepareFileSystem(); // Initially preps the filesystem and loads a lot of stuff into SPIFFS
void list(); void list();
// Creating Elements // Creating Elements
void label(const char *label, int color, String value = ""); // Create Label int label(const char *label, int color, String value = ""); // Create Label
void button(const char *label, void (*callBack)(Control, int), int color, int button(const char *label, void (*callBack)(Control, int), int color,
String value = ""); // Create Event Button String value = ""); // Create Event Button
void switcher(const char *label, bool startState, int switcher(const char *label, bool startState,
void (*callBack)(Control, int), void (*callBack)(Control, int),
int color); // Create Toggle Button int color); // Create Toggle Button
void pad(const char *label, bool centerButton, void (*callBack)(Control, int), int pad(const char *label, bool centerButton, void (*callBack)(Control, int),
int color); // Create Pad Control int color); // Create Pad Control
void slider(const char *label, void (*callBack)(Control, int), int color, String value); // Create Slider Control int slider(const char *label, void (*callBack)(Control, int), int color, String value); // Create Slider Control
// Update Elements // Update Elements
void print(int id, String value); void print(int id, String value);