Small improvements to segment names
This commit is contained in:
parent
4d89ed701d
commit
c8610b8ad2
@ -561,15 +561,6 @@ uint32_t WS2812FX::getLastShow(void) {
|
||||
return _lastShow;
|
||||
}
|
||||
|
||||
// there is no longer any need for these two
|
||||
//uint8_t WS2812FX::getColorOrder(void) {
|
||||
// return COL_ORDER_GRB;
|
||||
//}
|
||||
//
|
||||
//void WS2812FX::setColorOrder(uint8_t co) {
|
||||
// //bus->SetColorOrder(co);
|
||||
//}
|
||||
|
||||
void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, uint8_t spacing) {
|
||||
if (n >= MAX_NUM_SEGMENTS) return;
|
||||
Segment& seg = _segments[n];
|
||||
@ -1031,9 +1022,10 @@ uint32_t WS2812FX::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8
|
||||
|
||||
//load custom mapping table from JSON file
|
||||
void WS2812FX::deserializeMap(uint8_t n) {
|
||||
String fileName = String(F("/ledmap"));
|
||||
if (n) fileName += String(n);
|
||||
fileName += String(F(".json"));
|
||||
char fileName[32];
|
||||
strcpy_P(fileName, PSTR("/ledmap"));
|
||||
if (n) sprintf(fileName +7, "%d", n);
|
||||
strcat(fileName, ".json");
|
||||
bool isFile = WLED_FS.exists(fileName);
|
||||
|
||||
if (!isFile) {
|
||||
@ -1050,7 +1042,7 @@ void WS2812FX::deserializeMap(uint8_t n) {
|
||||
DEBUG_PRINT(F("Reading LED map from "));
|
||||
DEBUG_PRINTLN(fileName);
|
||||
|
||||
if (!readObjectFromFile(fileName.c_str(), nullptr, &doc)) return; //if file does not exist just exit
|
||||
if (!readObjectFromFile(fileName, nullptr, &doc)) return; //if file does not exist just exit
|
||||
|
||||
// erase old custom ledmap
|
||||
if (customMappingTable != nullptr) {
|
||||
|
@ -106,7 +106,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
||||
uint16_t length = elm[F("len")] | 1;
|
||||
uint8_t colorOrder = (int)elm[F("order")];
|
||||
uint8_t skipFirst = elm[F("skip")];
|
||||
uint16_t start = elm[F("start")] | 0;
|
||||
uint16_t start = elm["start"] | 0;
|
||||
uint8_t ledType = elm["type"] | TYPE_WS2812_RGB;
|
||||
bool reversed = elm["rev"];
|
||||
|
||||
@ -401,7 +401,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
|
||||
JsonObject dmx = doc["dmx"];
|
||||
CJSON(DMXChannels, dmx[F("chan")]);
|
||||
CJSON(DMXGap,dmx[F("gap")]);
|
||||
CJSON(DMXStart, dmx[F("start")]);
|
||||
CJSON(DMXStart, dmx["start"]);
|
||||
CJSON(DMXStartLED,dmx[F("start-led")]);
|
||||
|
||||
JsonArray dmx_fixmap = dmx[F("fixmap")];
|
||||
@ -519,7 +519,7 @@ void serializeConfig() {
|
||||
Bus *bus = busses.getBus(s);
|
||||
if (!bus || bus->getLength()==0) break;
|
||||
JsonObject ins = hw_led_ins.createNestedObject();
|
||||
ins[F("start")] = bus->getStart();
|
||||
ins["start"] = bus->getStart();
|
||||
ins[F("len")] = bus->getLength();
|
||||
JsonArray ins_pin = ins.createNestedArray("pin");
|
||||
uint8_t pins[5];
|
||||
@ -724,7 +724,7 @@ void serializeConfig() {
|
||||
JsonObject dmx = doc.createNestedObject("dmx");
|
||||
dmx[F("chan")] = DMXChannels;
|
||||
dmx[F("gap")] = DMXGap;
|
||||
dmx[F("start")] = DMXStart;
|
||||
dmx["start"] = DMXStart;
|
||||
dmx[F("start-led")] = DMXStartLED;
|
||||
|
||||
JsonArray dmx_fixmap = dmx.createNestedArray(F("fixmap"));
|
||||
|
@ -15,32 +15,34 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
//WS2812FX::Segment prev;
|
||||
//prev = seg; //make a backup so we can tell if something changed
|
||||
|
||||
uint16_t start = elem[F("start")] | seg.start;
|
||||
uint16_t start = elem["start"] | seg.start;
|
||||
int stop = elem["stop"] | -1;
|
||||
|
||||
if (elem["n"]) {
|
||||
// name field exists
|
||||
String name = elem["n"];
|
||||
if (name.length()) {
|
||||
if (seg.name) delete seg.name;
|
||||
seg.name = new char[name.length()+1];
|
||||
strcpy(seg.name, name.c_str());
|
||||
} else {
|
||||
// but is empty
|
||||
elem.remove("n");
|
||||
if (seg.name) {
|
||||
delete seg.name;
|
||||
seg.name = nullptr;
|
||||
}
|
||||
}
|
||||
} else if (elem[F("start")] || elem["stop"]) {
|
||||
// clearing or setting segment without name field
|
||||
if (seg.name) {
|
||||
delete seg.name;
|
||||
seg.name = nullptr;
|
||||
}
|
||||
if (elem["n"]) {
|
||||
// name field exists
|
||||
if (seg.name) { //clear old name
|
||||
delete[] seg.name;
|
||||
seg.name = nullptr;
|
||||
}
|
||||
|
||||
const char * name = elem["n"].as<const char*>();
|
||||
size_t len = 0;
|
||||
if (name != nullptr) len = strlen(name);
|
||||
if (len > 0 && len < 33) {
|
||||
seg.name = new char[len+1];
|
||||
if (seg.name) strlcpy(seg.name, name, 33);
|
||||
} else {
|
||||
// but is empty (already deleted above)
|
||||
elem.remove("n");
|
||||
}
|
||||
} else if (elem["start"] || elem["stop"]) {
|
||||
// clearing or setting segment without name field
|
||||
if (seg.name) {
|
||||
delete[] seg.name;
|
||||
seg.name = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (stop < 0) {
|
||||
uint16_t len = elem[F("len")];
|
||||
stop = (len > 0) ? start + len : seg.stop;
|
||||
@ -351,7 +353,7 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
|
||||
{
|
||||
root["id"] = id;
|
||||
if (segmentBounds) {
|
||||
root[F("start")] = seg.start;
|
||||
root["start"] = seg.start;
|
||||
root["stop"] = seg.stop;
|
||||
}
|
||||
if (!forPreset) root[F("len")] = seg.stop - seg.start;
|
||||
@ -362,7 +364,7 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
|
||||
byte segbri = seg.opacity;
|
||||
root["bri"] = (segbri) ? segbri : 255;
|
||||
|
||||
if (seg.name != nullptr) root["n"] = String(seg.name);
|
||||
if (seg.name != nullptr) root["n"] = seg.name;
|
||||
|
||||
char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user