Minor optimisations.

Removed all traces of v2 JSON API.
This commit is contained in:
Blaz Kristan 2021-06-19 23:16:40 +02:00
parent 75bf758042
commit 14ac66ff4e
6 changed files with 739 additions and 766 deletions

View File

@ -52,7 +52,7 @@ var cpick = new iro.ColorPicker("#picker", {
]
});
function handleVisibilityChange() {if (!d.hidden && new Date () - lastUpdate > 3000) requestJson({'v':true,'rev':2},false);}
function handleVisibilityChange() {if (!d.hidden && new Date () - lastUpdate > 3000) requestJson({'v':true},false);}
function sCol(na, col) {d.documentElement.style.setProperty(na, col);}
function gId(c) {return d.getElementById(c);}
@ -175,7 +175,7 @@ function loadBg(iUrl)
function loadSkinCSS(cId)
{
if (!gId(cId)) // chack if element exists
if (!gId(cId)) // check if element exists
{
var h = document.getElementsByTagName('head')[0];
var l = document.createElement('link');
@ -223,7 +223,7 @@ function onLoad()
loadFX(function() {
loadPresets(function() {
loadInfo(function() {
requestJson({'v':true,'rev':2}, false, true);
requestJson({'v':true}, false, true);
});
});
});
@ -245,7 +245,7 @@ function onLoad()
// Create UI update WS handler
myWS = new WebSocket('ws://'+(loc?locip:window.location.hostname)+'/ws');
myWS.onopen = function () {
myWS.send("{'v':true,'rev':2}");
myWS.send("{'v':true}");
}
myWS.onmessage = function(event) {
var json = JSON.parse(event.data);
@ -1104,7 +1104,6 @@ function requestJson(command, rinfo = true, verbose = true, callback = null)
if (command)
{
command.v = verbose;
command.rev = 2;
command.time = Math.floor(Date.now() / 1000);
req = JSON.stringify(command);
}

View File

@ -105,7 +105,7 @@ bool deserializeState(JsonObject root, byte presetId = 0);
void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset = false, bool segmentBounds = true);
void serializeState(JsonObject root, bool forPreset = false, bool includeBri = true, bool segmentBounds = true);
void serializeInfo(JsonObject root);
void serveJson(AsyncWebServerRequest* request, uint8_t versionAPI = 1);
void serveJson(AsyncWebServerRequest* request);
bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient = 0);
//led.cpp

File diff suppressed because it is too large Load Diff

View File

@ -353,8 +353,6 @@ bool deserializeState(JsonObject root, byte presetId)
void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset, bool segmentBounds)
{
uint8_t versionAPI = root["ver"] | 1;
root["id"] = id;
if (segmentBounds) {
root[F("start")] = seg.start;
@ -369,43 +367,27 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
if (seg.name != nullptr) root["n"] = String(seg.name);
JsonArray colarr = root.createNestedArray("col");
/*
if (versionAPI>1) {
// if we want to sqeeze a few more segments on 8266 we need to use v2 experimental API
for (uint8_t i = 0; i < 3; i++)
{
if (id==strip.getMainSegmentId() && i < 2) //temporary, to make transition work on main segment
if (i==0) colarr.add((unsigned long)((col[0]<<16) | (col[1]<<8) | col[2] | (strip.isRgbw?col[3]<<24:0)));
else colarr.add((unsigned long)((colSec[0]<<16) | (colSec[1]<<8) | colSec[2] | (strip.isRgbw?colSec[3]<<24:0)));
else
colarr.add((unsigned long)seg.colors[i]);
}
} else {
*/
// to conserve RAM we will serialize the col array manually
// this will reduce RAM footprint from ~300 bytes to 84 bytes per segment
char colstr[70] = "["; //max len 68 (5 chan, all 255)
char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255)
const char *format = strip.isRgbw ? PSTR("[%u,%u,%u,%u]") : PSTR("[%u,%u,%u]");
for (uint8_t i = 0; i < 3; i++)
{
char tmpcol[22];
byte segcol[4]; byte* c = segcol;
if (id == strip.getMainSegmentId() && i < 2) //temporary, to make transition work on main segment
{
byte* c = (i == 0)? col:colSec;
if (strip.isRgbw) sprintf_P(tmpcol, PSTR("[%d,%d,%d,%d]"), c[0], c[1], c[2], c[3]);
else sprintf_P(tmpcol, PSTR("[%d,%d,%d]"), c[0], c[1], c[2]);
c = (i == 0)? col:colSec;
} else {
uint32_t c = seg.colors[i];
if (strip.isRgbw) sprintf_P(tmpcol, PSTR("[%d,%d,%d,%d]"), (c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF, (c >> 24) & 0xFF);
else sprintf_P(tmpcol, PSTR("[%d,%d,%d]"), (c >> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF);
segcol[0] = (byte)(seg.colors[i] >> 16); segcol[1] = (byte)(seg.colors[i] >> 8);
segcol[2] = (byte)(seg.colors[i]); segcol[3] = (byte)(seg.colors[i] >> 24);
}
char tmpcol[22];
sprintf_P(tmpcol, format, (unsigned)c[0], (unsigned)c[1], (unsigned)c[2], (unsigned)c[3]);
strcat(colstr, i<2 ? strcat_P(tmpcol, PSTR(",")) : tmpcol);
}
strcat_P(colstr, PSTR("]"));
root["col"] = serialized(colstr);
/*
}
*/
root["fx"] = seg.mode;
root[F("sx")] = seg.speed;
root[F("ix")] = seg.intensity;
@ -816,7 +798,7 @@ void serializeNodes(JsonObject root)
}
}
void serveJson(AsyncWebServerRequest* request, uint8_t versionAPI)
void serveJson(AsyncWebServerRequest* request)
{
byte subJson = 0;
const String& url = request->url();
@ -851,7 +833,6 @@ void serveJson(AsyncWebServerRequest* request, uint8_t versionAPI)
switch (subJson)
{
case 1: //state
if (versionAPI>1) doc["rev"] = (int)versionAPI;
serializeState(doc); break;
case 2: //info
serializeInfo(doc); break;
@ -861,7 +842,6 @@ void serveJson(AsyncWebServerRequest* request, uint8_t versionAPI)
serializePalettes(doc, request); break;
default: //all
JsonObject state = doc.createNestedObject("state");
if (versionAPI>1) state["rev"] = (int)versionAPI;
serializeState(state);
JsonObject info = doc.createNestedObject("info");
serializeInfo(info);
@ -872,7 +852,7 @@ void serveJson(AsyncWebServerRequest* request, uint8_t versionAPI)
}
}
DEBUG_PRINTF("JSON buffer size: %ld for request: %d\n", doc.memoryUsage(), subJson);
DEBUG_PRINTF("JSON buffer size: %u for request: %d\n", doc.memoryUsage(), subJson);
response->setLength();
request->send(response);

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2106191
#define VERSION 2106192
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG

View File

@ -97,7 +97,6 @@ void initServer()
AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/json", [](AsyncWebServerRequest *request) {
bool verboseResponse = false;
uint8_t vAPI = 1;
bool isConfig = false;
{ //scope JsonDocument so it releases its buffer
DynamicJsonDocument jsonBuffer(JSON_BUFFER_SIZE);
@ -109,10 +108,6 @@ void initServer()
const String& url = request->url();
isConfig = url.indexOf("cfg") > -1;
if (!isConfig) {
if (root.containsKey("rev"))
{
vAPI = root["rev"] | 1;
}
fileDoc = &jsonBuffer; // used for applying presets (presets.cpp)
verboseResponse = deserializeState(root);
fileDoc = nullptr;
@ -122,7 +117,7 @@ void initServer()
}
if (verboseResponse) {
if (!isConfig) {
serveJson(request,vAPI); return; //if JSON contains "v"
serveJson(request); return; //if JSON contains "v"
} else {
serializeConfig(); //Save new settings to FS
}