From 6f1488a9f5c62ba1e0d9e6a46c269c096183761a Mon Sep 17 00:00:00 2001 From: Scott Hanson Date: Thu, 22 Aug 2024 10:13:13 -0400 Subject: [PATCH] fix ESPixelStick v4 DMX upload, it shares Pixel/Serial ports, Serial will override Pixel Ports --- xLights/controllers/ESPixelStick.cpp | 238 ++++++++++++++------------- xLights/controllers/Experience.cpp | 2 +- 2 files changed, 122 insertions(+), 118 deletions(-) diff --git a/xLights/controllers/ESPixelStick.cpp b/xLights/controllers/ESPixelStick.cpp index a10eadf2a9..b5b31e02b7 100644 --- a/xLights/controllers/ESPixelStick.cpp +++ b/xLights/controllers/ESPixelStick.cpp @@ -465,145 +465,149 @@ bool ESPixelStick::SetOutputsV4(ModelManager* allmodels, OutputManager* outputMa GetOutputConfig(outputConfig); for (int x = 0; x < cud.GetMaxPixelPort(); x++) { - UDControllerPort* port = cud.GetControllerPixelPort(x + 1); - std::string const proto = MapV4Type(port->GetProtocol()); - std::string const pixels = std::to_string(port->Pixels()); - int brightness{ -1 }; - float gamma{ -1.0F }; - std::string colorOrder; - int groupCount{ -1 }; - int startNulls{ -1 }; - int endNulls{ -1 }; - auto s = port->GetModels().front(); - if (s) { - brightness = s->GetBrightness(-1); - colorOrder = MapV4ColorOrder(s->GetColourOrder("")); - gamma = s->GetGamma(-1.0F); - int gc = s->GetGroupCount(-1); - if (gc == 0) { - gc = 1; + if (cud.HasPixelPort(x + 1)) { + UDControllerPort* port = cud.GetControllerPixelPort(x + 1); + std::string const proto = MapV4Type(port->GetProtocol()); + std::string const pixels = std::to_string(port->Pixels()); + int brightness{ -1 }; + float gamma{ -1.0F }; + std::string colorOrder; + int groupCount{ -1 }; + int startNulls{ -1 }; + int endNulls{ -1 }; + auto s = port->GetModels().front(); + if (s) { + brightness = s->GetBrightness(-1); + colorOrder = MapV4ColorOrder(s->GetColourOrder("")); + gamma = s->GetGamma(-1.0F); + int gc = s->GetGroupCount(-1); + if (gc == 0) { + gc = 1; + } + groupCount = gc; + startNulls = s->GetStartNullPixels(-1); + endNulls = s->GetEndNullPixels(-1); } - groupCount = gc; - startNulls = s->GetStartNullPixels(-1); - endNulls = s->GetEndNullPixels(-1); - } - std::string outidx = std::to_string(x); - std::string curIdx = std::to_string(outputConfig["channels"][outidx]["type"].AsInt()); - if (outputConfig["channels"][outidx][curIdx]["type"].AsString() != proto) { - changed = true; - for (int i = 0; i < 20; i++) { - std::string idx = std::to_string(i); - if (!outputConfig["channels"][outidx].HasMember(idx)) { - return false; - } - if (outputConfig["channels"][outidx][idx]["type"].AsString() == proto) { - //found the new element, flip over to using that protocol - outputConfig["channels"][outidx]["type"] = i; - curIdx = idx; - break; + std::string outidx = std::to_string(x); + std::string curIdx = std::to_string(outputConfig["channels"][outidx]["type"].AsInt()); + if (outputConfig["channels"][outidx][curIdx]["type"].AsString() != proto) { + changed = true; + for (int i = 0; i < 20; i++) { + std::string idx = std::to_string(i); + if (!outputConfig["channels"][outidx].HasMember(idx)) { + return false; + } + if (outputConfig["channels"][outidx][idx]["type"].AsString() == proto) { + // found the new element, flip over to using that protocol + outputConfig["channels"][outidx]["type"] = i; + curIdx = idx; + break; + } } } - } - if (proto == "WS2811" || proto == "TM1814") { - if (gamma > -1.0F) { - if (gamma < 1.0F) { - gamma = 1.0F; + if (proto == "WS2811" || proto == "TM1814") { + if (gamma > -1.0F) { + if (gamma < 1.0F) { + gamma = 1.0F; + } + if (gamma > 5.0F) { + gamma = 5.0F; + } + std::string const s_gamma = std::to_string(gamma); + if (s_gamma != outputConfig["channels"][outidx][curIdx]["gamma"].AsString()) { + changed = true; + outputConfig["channels"][outidx][curIdx]["gamma"] = s_gamma; + } } - if (gamma > 5.0F) { - gamma = 5.0F; + if (brightness != -1) { + int b = brightness; + if (b > 100) { + b = 100; + } + + std::string const b2 = std::to_string(b); + if (b2 != outputConfig["channels"][outidx][curIdx]["brightness"].AsString()) { + changed = true; + outputConfig["channels"][outidx][curIdx]["brightness"] = b2; + } } - std::string const s_gamma = std::to_string(gamma); - if (s_gamma != outputConfig["channels"][outidx][curIdx]["gamma"].AsString()) { + if (!colorOrder.empty() && colorOrder != outputConfig["channels"][outidx][curIdx]["color_order"].AsString()) { changed = true; - outputConfig["channels"][outidx][curIdx]["gamma"] = s_gamma; + outputConfig["channels"][outidx][curIdx]["color_order"] = colorOrder; } - } - if (brightness != -1) { - int b = brightness; - if (b > 100) { - b = 100; + if (groupCount != -1) { + std::string const s_groupCount = std::to_string(groupCount); + if (s_groupCount != outputConfig["channels"][outidx][curIdx]["group_size"].AsString()) { + changed = true; + outputConfig["channels"][outidx][curIdx]["group_size"] = s_groupCount; + } } - - std::string const b2 = std::to_string(b); - if (b2 != outputConfig["channels"][outidx][curIdx]["brightness"].AsString()) { - changed = true; - outputConfig["channels"][outidx][curIdx]["brightness"] = b2; + if (startNulls != -1) { + std::string const s_startNulls = std::to_string(startNulls); + if (s_startNulls != outputConfig["channels"][outidx][curIdx]["prependnullcount"].AsString()) { + changed = true; + outputConfig["channels"][outidx][curIdx]["prependnullcount"] = s_startNulls; + } } - } - if (!colorOrder.empty() && colorOrder != outputConfig["channels"][outidx][curIdx]["color_order"].AsString()) { - changed = true; - outputConfig["channels"][outidx][curIdx]["color_order"] = colorOrder; - } - if (groupCount != -1) { - std::string const s_groupCount = std::to_string(groupCount); - if (s_groupCount != outputConfig["channels"][outidx][curIdx]["group_size"].AsString()) { - changed = true; - outputConfig["channels"][outidx][curIdx]["group_size"] = s_groupCount; + if (endNulls != -1) { + std::string const s_endNulls = std::to_string(endNulls); + if (s_endNulls != outputConfig["channels"][outidx][curIdx]["appendnullcount"].AsString()) { + changed = true; + outputConfig["channels"][outidx][curIdx]["appendnullcount"] = s_endNulls; + } } - } - if (startNulls != -1) { - std::string const s_startNulls = std::to_string(startNulls); - if (s_startNulls != outputConfig["channels"][outidx][curIdx]["prependnullcount"].AsString()) { + if (pixels != outputConfig["channels"][outidx][curIdx]["pixel_count"].AsString()) { changed = true; - outputConfig["channels"][outidx][curIdx]["prependnullcount"] = s_startNulls; + outputConfig["channels"][outidx][curIdx]["pixel_count"] = pixels; } - } - if (endNulls != -1) { - std::string const s_endNulls = std::to_string(endNulls); - if (s_endNulls != outputConfig["channels"][outidx][curIdx]["appendnullcount"].AsString()) { - changed = true; - outputConfig["channels"][outidx][curIdx]["appendnullcount"] = s_endNulls; + } else if (proto == "GECE") { + if (brightness != -1) { + int b = brightness; + if (b > 100) { + b = 100; + } + std::string const b2 = std::to_string(b); + if (b2 != outputConfig["channels"][outidx][curIdx]["brightness"].AsString()) { + changed = true; + outputConfig["channels"][outidx][curIdx]["brightness"] = b2; + } } - } - if (pixels != outputConfig["channels"][outidx][curIdx]["pixel_count"].AsString()) { - changed = true; - outputConfig["channels"][outidx][curIdx]["pixel_count"] = pixels; - } - } else if (proto == "GECE") { - if (brightness != -1) { - int b = brightness; - if (b > 100) { - b = 100; - } - std::string const b2 = std::to_string(b); - if (b2 != outputConfig["channels"][outidx][curIdx]["brightness"].AsString()) { + + if (pixels != outputConfig["channels"][outidx][curIdx]["pixel_count"].AsString()) { changed = true; - outputConfig["channels"][outidx][curIdx]["brightness"] = b2; + outputConfig["channels"][outidx][curIdx]["pixel_count"] = pixels; } } - - if (pixels != outputConfig["channels"][outidx][curIdx]["pixel_count"].AsString()) { - changed = true; - outputConfig["channels"][outidx][curIdx]["pixel_count"] = pixels; - } } } for (int x = 0; x < cud.GetMaxSerialPort(); x++) { - UDControllerPort* port = cud.GetControllerSerialPort(x + 1); - std::string proto = MapV4Type(port->GetProtocol()); - std::string channels = std::to_string(port->Channels()); - - std::string outidx = std::to_string(x + rules->GetMaxPixelPort()); - std::string curIdx = std::to_string(outputConfig["channels"][outidx]["type"].AsInt()); - if (outputConfig["channels"][outidx][curIdx]["type"].AsString() != proto) { - changed = true; - for (int i = 0; i < 20; i++) { - std::string idx = std::to_string(i); - if (!outputConfig["channels"][outidx].HasMember(idx)) { - return false; - } - if (outputConfig["channels"][outidx][idx]["type"].AsString() == proto) { - //found the new element, flip over to using that protocol - outputConfig["channels"][outidx]["type"] = i; - curIdx = idx; - break; + if (cud.HasSerialPort(x + 1)) { + UDControllerPort* port = cud.GetControllerSerialPort(x + 1); + std::string proto = MapV4Type(port->GetProtocol()); + std::string channels = std::to_string(port->Channels()); + + std::string outidx = std::to_string(x); + std::string curIdx = std::to_string(outputConfig["channels"][outidx]["type"].AsInt()); + if (outputConfig["channels"][outidx][curIdx]["type"].AsString() != proto) { + changed = true; + for (int i = 0; i < 20; i++) { + std::string idx = std::to_string(i); + if (!outputConfig["channels"][outidx].HasMember(idx)) { + return false; + } + if (outputConfig["channels"][outidx][idx]["type"].AsString() == proto) { + // found the new element, flip over to using that protocol + outputConfig["channels"][outidx]["type"] = i; + curIdx = idx; + break; + } } } - } - if (channels != outputConfig["channels"][outidx][curIdx]["num_chan"].AsString()) { - changed = true; - outputConfig["channels"][outidx][curIdx]["num_chan"] = channels; + if (channels != outputConfig["channels"][outidx][curIdx]["num_chan"].AsString()) { + changed = true; + outputConfig["channels"][outidx][curIdx]["num_chan"] = channels; + } } } if (changed) diff --git a/xLights/controllers/Experience.cpp b/xLights/controllers/Experience.cpp index c8985dd092..94367e1912 100644 --- a/xLights/controllers/Experience.cpp +++ b/xLights/controllers/Experience.cpp @@ -183,7 +183,7 @@ int32_t Experience::SetInputUniverses(wxJSONValue& data, Controller* controller) } else { //should never hit this DisplayError(wxString::Format( - "Invalud Input Type For Experience Controller %s.", + "Invalid Input Type For Experience Controller %s.", out->GetType()) .ToStdString()); return startChannel;