kopia lustrzana https://github.com/Aircoookie/WLED
JSON ledDoc (does not work, crash on delete)
rodzic
8ed35652bc
commit
e44173ff09
|
@ -1265,7 +1265,7 @@ uint16_t WS2812FX::police_base(uint32_t color1, uint32_t color2, bool all)
|
|||
for (uint16_t i = idexB; i < idexR; i++) setPixelColor(i, color2);
|
||||
}
|
||||
} else { //regular dot-only mode
|
||||
uint8_t size = 1 + SEGMENT.intensity >> 3;
|
||||
uint8_t size = 1 + (SEGMENT.intensity >> 3);
|
||||
if (size > SEGLEN/2) size = 1+ SEGLEN/2;
|
||||
for (uint8_t i=0; i <= size; i++) {
|
||||
setPixelColor(idexR+i, color1);
|
||||
|
|
|
@ -12,6 +12,48 @@ void getStringFromJson(char* dest, const char* src, size_t len) {
|
|||
if (src != nullptr) strlcpy(dest, src, len);
|
||||
}
|
||||
|
||||
//populates bus objects from instance JsonArray, called by deserializeConfig() and by doInitStrip
|
||||
bool initBusInstances(JsonArray ins) {
|
||||
uint8_t s = 0;
|
||||
useRGBW = false;
|
||||
busses.removeAll();
|
||||
for (JsonObject elm : ins) {
|
||||
if (s >= WLED_MAX_BUSSES) break;
|
||||
uint8_t pins[5] = {255, 255, 255, 255, 255};
|
||||
JsonArray pinArr = elm[F("pin")];
|
||||
if (pinArr.size() == 0) continue;
|
||||
pins[0] = pinArr[0];
|
||||
uint8_t i = 0;
|
||||
for (int p : pinArr) {
|
||||
pins[i] = p;
|
||||
i++;
|
||||
if (i>4) break;
|
||||
}
|
||||
|
||||
uint16_t length = elm[F("len")];
|
||||
if (length==0) continue;
|
||||
uint8_t colorOrder = (int)elm[F("order")];
|
||||
//only use skip from the first strip (this shouldn't have been in ins obj. but remains here for compatibility)
|
||||
if (s==0) skipFirstLed = elm[F("skip")];
|
||||
uint16_t start = elm[F("start")] | 0;
|
||||
if (start >= ledCount) continue;
|
||||
//limit length of strip if it would exceed total configured LEDs
|
||||
if (start + length > ledCount) length = ledCount - start;
|
||||
uint8_t ledType = elm[F("type")] | TYPE_WS2812_RGB;
|
||||
bool reversed = elm[F("rev")];
|
||||
//RGBW mode is enabled if at least one of the strips is RGBW
|
||||
useRGBW = (useRGBW || BusManager::isRgbw(ledType));
|
||||
s++;
|
||||
busses.add(ledType, pins, start, ledCount, colorOrder, reversed);
|
||||
}
|
||||
//if no bus inited successfully (empty cfg or invalid), init default
|
||||
if (s==0) {
|
||||
uint8_t defPin[] = {LEDPIN};
|
||||
busses.add(TYPE_WS2812_RGB, defPin, 0, ledCount, COL_ORDER_GRB);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void deserializeConfig() {
|
||||
bool fromeep = false;
|
||||
bool success = deserializeConfigSec();
|
||||
|
@ -101,46 +143,7 @@ void deserializeConfig() {
|
|||
CJSON(strip.rgbwMode, hw_led[F("rgbwm")]);
|
||||
|
||||
JsonVariant strVar = hw_led["ins"];
|
||||
if (strVar.is<JsonObject>()) {
|
||||
// some safety measures here?
|
||||
} else {
|
||||
JsonArray elms = strVar.as<JsonArray>();
|
||||
uint8_t s = 0;
|
||||
useRGBW = false;
|
||||
busses.removeAll();
|
||||
for (JsonObject elm : elms) {
|
||||
if (s >= WLED_MAX_BUSSES) break;
|
||||
uint8_t pins[5] = {255, 255, 255, 255, 255};
|
||||
JsonArray pinArr = elm[F("pin")];
|
||||
if (pinArr.size() == 0) continue;
|
||||
pins[0] = pinArr[0];
|
||||
uint8_t i = 0;
|
||||
for (int p : pinArr) {
|
||||
pins[i] = p;
|
||||
i++;
|
||||
if (i>4) break;
|
||||
}
|
||||
|
||||
uint16_t length = elm[F("len")];
|
||||
if (length==0) continue;
|
||||
uint8_t colorOrder = (int)elm[F("order")];
|
||||
//only use skip from the first strip (this shouldn't have been in ins obj. but remains here for compatibility)
|
||||
if (s==0) skipFirstLed = elm[F("skip")];
|
||||
uint16_t start = elm[F("start")] | 0;
|
||||
if (start >= ledCount) continue;
|
||||
//limit length of strip if it would exceed total configured LEDs
|
||||
if (start + length > ledCount) length = ledCount - start;
|
||||
uint8_t ledType = elm[F("type")] | TYPE_WS2812_RGB;
|
||||
bool reversed = elm[F("rev")];
|
||||
//RGBW mode is enabled if at least one of the strips is RGBW
|
||||
useRGBW = (useRGBW || BusManager::isRgbw(ledType));
|
||||
busses.add(ledType, pins, start, ledCount, colorOrder, reversed);
|
||||
}
|
||||
//if no bus inited successfully (empty cfg or invalid), init default
|
||||
uint8_t defPin[] = {LEDPIN};
|
||||
busses.add(TYPE_WS2812_RGB, defPin, 0, ledCount, COL_ORDER_GRB);
|
||||
}
|
||||
if (ledCount > MAX_LEDS) ledCount = MAX_LEDS;
|
||||
initBusInstances(strVar.as<JsonArray>());
|
||||
|
||||
JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0];
|
||||
CJSON(buttonEnabled, hw_btn_ins_0[F("type")]);
|
||||
|
|
|
@ -144,12 +144,12 @@
|
|||
|
||||
d.getElementById('m0').innerHTML = memu;
|
||||
bquot = memu / bmax * 100;
|
||||
d.getElementById('dbar').style.background = `linear-gradient(90deg, ${bquot > 60 ? bquot > 90 ? "red":"orange":"#ccc"} 0 ${bquot}%, #444 ${bquot}% 100%)`;
|
||||
d.getElementById('dbar').style.background = `linear-gradient(90deg, ${bquot > 60 ? bquot > 90 ? "red":"orange":"#ccc"} 0 ${bquot}%%, #444 ${bquot}%% 100%%)`;
|
||||
d.getElementById('ledwarning').style.display = (maxLC > 800 || bquot > 80) ? 'inline':'none';
|
||||
//TODO add warning "Recommended pins on ESP8266 are 1 and 2 (3 only with low LED count)"
|
||||
//TODO add overmemory warning
|
||||
//TODO block disallowed pins 6-11
|
||||
d.getElementById('wreason').innerHTML = (bquot > 80) ? "than 60% of max. LED memory" : "800 LEDs per pin";
|
||||
d.getElementById('wreason').innerHTML = (bquot > 80) ? "than 60%% of max. LED memory" : "800 LEDs per pin";
|
||||
|
||||
//var val = Math.ceil((100 + d.Sf.LC.value * laprev)/500)/2;
|
||||
var val = Math.ceil((100 + sLC * laprev)/500)/2;
|
||||
|
|
|
@ -26,6 +26,7 @@ void handleButton();
|
|||
void handleIO();
|
||||
|
||||
//cfg.cpp
|
||||
bool initBusInstances(JsonArray ins);
|
||||
void deserializeConfig();
|
||||
bool deserializeConfigSec();
|
||||
void serializeConfig();
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -89,32 +89,50 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||
uint16_t length, start;
|
||||
uint8_t pins[2] = {255, 255};
|
||||
|
||||
for (uint8_t s = 0; s < WLED_MAX_BUSSES; s++) {
|
||||
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
|
||||
char lk[4] = "L1"; lk[2] = 48+s; lk[3] = 0; //strip clock pin. 255 for none
|
||||
char lc[4] = "LC"; lc[2] = 48+s; lc[3] = 0; //strip length
|
||||
char co[4] = "CO"; co[2] = 48+s; co[3] = 0; //strip color order
|
||||
char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0; //strip type
|
||||
char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0; //strip start LED
|
||||
char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0; //strip reverse
|
||||
if (!request->hasArg(lp)) {
|
||||
DEBUG_PRINTLN("No data."); break;
|
||||
if (ledDoc != nullptr) delete ledDoc;
|
||||
ledDoc = new DynamicJsonDocument(1024);
|
||||
|
||||
if (ledDoc) {
|
||||
JsonArray ledO = ledDoc->to<JsonArray>();
|
||||
//[{"en":true,"start":0,"len":120,"pin":[2],"order":0,"rev":false,"skip":0,"type":22}]
|
||||
for (uint8_t s = 0; s < WLED_MAX_BUSSES; s++) {
|
||||
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
|
||||
char lk[4] = "L1"; lk[2] = 48+s; lk[3] = 0; //strip clock pin. 255 for none
|
||||
char lc[4] = "LC"; lc[2] = 48+s; lc[3] = 0; //strip length
|
||||
char co[4] = "CO"; co[2] = 48+s; co[3] = 0; //strip color order
|
||||
char lt[4] = "LT"; lt[2] = 48+s; lt[3] = 0; //strip type
|
||||
char ls[4] = "LS"; ls[2] = 48+s; ls[3] = 0; //strip start LED
|
||||
char cv[4] = "CV"; cv[2] = 48+s; cv[3] = 0; //strip reverse
|
||||
if (!request->hasArg(lp)) {
|
||||
DEBUG_PRINTLN("No data."); break;
|
||||
}
|
||||
pins[0] = request->arg(lp).toInt();
|
||||
if (request->hasArg(lk)) {
|
||||
pins[1] = (request->arg(lk).length() > 0) ? request->arg(lk).toInt() : 255;
|
||||
}
|
||||
type = request->arg(lt).toInt();
|
||||
|
||||
if (request->hasArg(lc) && request->arg(lc).toInt() > 0) {
|
||||
length = request->arg(lc).toInt();
|
||||
} else {
|
||||
break; // no parameter
|
||||
}
|
||||
colorOrder = request->arg(co).toInt();
|
||||
start = (request->hasArg(ls)) ? request->arg(ls).toInt() : 0;
|
||||
|
||||
JsonObject ins = ledO.createNestedObject();
|
||||
ins[F("en")] = true;
|
||||
ins[F("start")] = start;
|
||||
ins[F("len")] = length;
|
||||
JsonArray ins_pin = ins.createNestedArray("pin");
|
||||
uint8_t nPins = pins[1] < 100 ? 2 : 1; //TODO 3,4,5 pin types
|
||||
for (uint8_t i = 0; i < nPins; i++) ins_pin.add(pins[i]);
|
||||
ins[F("order")] = colorOrder;
|
||||
ins[F("rev")] = request->hasArg(cv);
|
||||
ins[F("skip")] = (skipFirstLed && s == 0) ? 1 : 0;
|
||||
ins[F("type")] = type;
|
||||
//temporary: add this info to a JSON object and re-init the strips after network callback
|
||||
}
|
||||
pins[0] = request->arg(lp).toInt();
|
||||
if (request->hasArg(lk)) {
|
||||
pins[1] = (request->arg(lk).length() > 0) ? request->arg(lk).toInt() : 255;
|
||||
}
|
||||
type = request->arg(lt).toInt();
|
||||
|
||||
if (request->hasArg(lc) && request->arg(lc).toInt() > 0) {
|
||||
length = request->arg(lc).toInt();
|
||||
} else {
|
||||
type = TYPE_NONE;
|
||||
break; // no parameter
|
||||
}
|
||||
colorOrder = request->arg(co).toInt();
|
||||
start = (request->hasArg(ls)) ? request->arg(ls).toInt() : 0;
|
||||
//busses.add(type, pins, start, length, colorOrder, request->hasArg(cv));
|
||||
}
|
||||
|
||||
ledCount = request->arg(F("LC")).toInt();
|
||||
|
@ -402,7 +420,6 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
|||
#endif
|
||||
|
||||
if (subPage != 6 || !doReboot) serializeConfig(); //do not save if factory reset
|
||||
if (subPage == 2) doInitStrip = true;
|
||||
if (subPage == 4) alexaInit();
|
||||
}
|
||||
|
||||
|
|
|
@ -195,9 +195,9 @@ void WLED::loop()
|
|||
handleHue();
|
||||
handleBlynk();
|
||||
|
||||
if (doInitStrip) {
|
||||
strip.init(useRGBW, ledCount, skipFirstLed);
|
||||
doInitStrip = false;
|
||||
if (ledDoc != nullptr) {
|
||||
initBusInstances(ledDoc->as<JsonArray>());
|
||||
delete ledDoc; ledDoc = nullptr;
|
||||
}
|
||||
|
||||
yield();
|
||||
|
|
|
@ -552,7 +552,7 @@ WLED_GLOBAL bool e131NewData _INIT(false);
|
|||
// led fx library object
|
||||
WLED_GLOBAL BusManager busses _INIT(BusManager());
|
||||
WLED_GLOBAL WS2812FX strip _INIT(WS2812FX());
|
||||
WLED_GLOBAL bool doInitStrip _INIT(false);
|
||||
WLED_GLOBAL JsonDocument* ledDoc; //temporary, to remember values from network callback until after
|
||||
|
||||
// Usermod manager
|
||||
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
|
||||
|
|
Ładowanie…
Reference in New Issue