1
0
mirror of https://github.com/s00500/ESPUI.git synced 2025-06-11 12:50:40 +00:00

#43 Sending Initial GUI as one big array

- Added new  INITIAL_GUI Type
- spliting GUI Blob to events in controls js
- formating the json in jsonDom into one big array
This commit is contained in:
2018-12-26 12:35:35 +01:00
parent 980e20818f
commit f31575b50c
5 changed files with 185 additions and 156 deletions

View File

@ -613,25 +613,39 @@ bool ESPUIClass::labelExists(String label) {
return false;
}
// Convert & Transfer Arduino elements to JSON elements
/*
Convert & Transfer Arduino elements to JSON elements
Initially this function used to send the control element data individually.
Due to a change in the ESPAsyncWebserver library this had top be changed to be
sent as one blob at the beginning. Therefore a new type is used as well
*/
void ESPUIClass::jsonDom(AsyncWebSocketClient *client) {
String json;
DynamicJsonBuffer jsonBuffer(2000);
JsonObject &root = jsonBuffer.createObject();
root["type"] = UI_INITIAL_GUI;
JsonArray &items = jsonBuffer.createArray();
for (int i = -1; i < cIndex; i++) {
String json;
StaticJsonBuffer<200> jsonBuffer;
JsonObject &root = jsonBuffer.createObject();
JsonObject &item = jsonBuffer.createObject();
if (i == -1) {
root["type"] = UI_TITEL;
root["label"] = String(ui_title);
item["type"] = UI_TITEL;
item["label"] = String(ui_title);
} else {
root["type"] = controls[i]->type;
root["label"] = String(controls[i]->label);
root["value"] = String(controls[i]->value);
root["color"] = String(controls[i]->color);
root["id"] = String(i);
item["type"] = controls[i]->type;
item["label"] = String(controls[i]->label);
item["value"] = String(controls[i]->value);
item["color"] = String(controls[i]->color);
item["id"] = String(i);
}
root.printTo(json);
client->text(json);
items.add(item);
}
// Send as one big bunch
root["controls"] = items;
root.printTo(json);
client->text(json);
}
void ESPUIClass::beginSPIFFS(const char *_title) {

View File

@ -40,6 +40,7 @@ typedef struct Control {
} Control;
// Message Types (and control types)
#define UI_INITIAL_GUI 100
#define UI_TITEL 0
#define UI_LABEL 1

File diff suppressed because one or more lines are too long