1
0
mirror of https://github.com/s00500/ESPUI.git synced 2025-06-14 02:30:41 +00:00

#10 Graph points working

- timestap still not great
This commit is contained in:
2019-04-15 15:32:14 +02:00
parent bff259008f
commit 79f509da74
4 changed files with 296 additions and 65 deletions

View File

@ -570,7 +570,50 @@ void ESPUIClass::updateSelect(uint16_t id, String text, int clientId) { updateCo
void ESPUIClass::updateGauge(uint16_t id, int number, int clientId) { updateControlValue(id, String(number), 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) {
Control *control = getControl(id);
if (!control) {
return;
}
String json;
DynamicJsonDocument document(2000);
JsonObject root = document.to<JsonObject>();
root["type"] = (int)ControlType::GraphPoint;
root["value"] = nValue;
root["id"] = control->id;
serializeJson(document, json);
if (this->verbosity >= Verbosity::VerboseJSON) {
Serial.println(json);
}
if (clientId < 0) {
this->ws->textAll(json);
return;
}
// This is a hacky workaround because ESPAsyncWebServer does not have a
// function like this and it's clients array is private
int tryId = 0;
for (int count = 0; count < this->ws->count();) {
if (this->ws->hasClient(tryId)) {
if (clientId != tryId) {
this->ws->client(tryId)->text(json);
if (this->verbosity >= Verbosity::VerboseJSON) {
Serial.println(json);
}
}
count++;
}
tryId++;
}
}
/*
Convert & Transfer Arduino elements to JSON elements
Initially this function used to send the control element data individually.

File diff suppressed because one or more lines are too long