From 1bd64bfc86c38ef5d5301ef19a8b633f136a68a8 Mon Sep 17 00:00:00 2001 From: Ewoud Date: Sat, 28 Oct 2023 11:00:45 +0200 Subject: [PATCH] Lambda for AppModLeds, dmx info in instances AppModLeds - non static: fps, doMap, effects - [this] in functions using these vars SysModUI - non static: valChangedForInstancesTemp UserModE131 - varsToWatch p - universe from 0..7 (+1?) - channel from 0..511 (+1?) UserModInstances - dmx struct for universe:start-count --- src/App/AppEffects.h | 1 - src/App/AppModLeds.h | 36 +++++++++++++++-------------------- src/Sys/SysModUI.cpp | 2 -- src/Sys/SysModUI.h | 2 +- src/User/UserModE131.h | 4 ++-- src/User/UserModInstances.h | 38 +++++++++++++++++++++++++------------ 6 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/App/AppEffects.h b/src/App/AppEffects.h index 4d596bd7..1c20564c 100644 --- a/src/App/AppEffects.h +++ b/src/App/AppEffects.h @@ -738,7 +738,6 @@ class GEQEffect:public Effect { #ifdef USERMOD_E131 if (e131mod->isEnabled) { - uint16_t dmxChannel = mdl->getValue("dmxChannel"); e131mod->patchChannel(3, "fadeOut", 255); // TODO: add constant for name e131mod->patchChannel(4, "ripple", 255); } diff --git a/src/App/AppModLeds.h b/src/App/AppModLeds.h index 5cc5587d..165babcf 100644 --- a/src/App/AppModLeds.h +++ b/src/App/AppModLeds.h @@ -38,12 +38,10 @@ class AppModLeds:public Module { unsigned long frameCounter = 0; bool newFrame = false; //for other modules (DDP) - //need to make these static as they are called in lambda functions - static uint16_t fps; + uint16_t fps = 60; unsigned long lastMappingMillis = 0; - static bool doMap; - - static Effects effects; + bool doMap = false; + Effects effects; AppModLeds() :Module("Leds") {}; @@ -67,7 +65,7 @@ class AppModLeds:public Module { FastLED.setBrightness(result); USER_PRINTF("Set Brightness to %d -> b:%d r:%d\n", var["value"].as(), bri, result); - SysModUI::valChangedForInstancesTemp = true; + ui->valChangedForInstancesTemp = true; }); ui->initCanvas(parentVar, "pview", -1, false, [](JsonObject var) { //uiFun @@ -88,19 +86,19 @@ class AppModLeds:public Module { buffer[3] = max(LedsV::nrOfLedsP * SysModWeb::ws->count()/200, 16U); //interval in ms * 10, not too fast }); - ui->initSelect(parentVar, "fx", 0, false, [](JsonObject var) { //uiFun + ui->initSelect(parentVar, "fx", 0, false, [this](JsonObject var) { //uiFun web->addResponse(var["id"], "label", "Effect"); web->addResponse(var["id"], "comment", "Effect to show"); JsonArray select = web->addResponseA(var["id"], "select"); for (Effect *effect:effects.effects) { select.add(effect->name()); } - }, [](JsonObject var) { //chFun + }, [this](JsonObject var) { //chFun uint8_t fx = var["value"]; USER_PRINTF("%s Change %s to %d\n", "initSelect chFun", var["id"].as(), fx); doMap = effects.setEffect("fx", fx); - SysModUI::valChangedForInstancesTemp = true; + ui->valChangedForInstancesTemp = true; }); ui->initSelect(parentVar, "palette", 4, false, [](JsonObject var) { //uiFun. @@ -126,7 +124,7 @@ class AppModLeds:public Module { case 7: palette = HeatColors_p; break; default: palette = PartyColors_p; break; } - SysModUI::valChangedForInstancesTemp = true; + ui->valChangedForInstancesTemp = true; }); ui->initSelect(parentVar, "projection", 2, false, [](JsonObject var) { //uiFun. @@ -137,12 +135,12 @@ class AppModLeds:public Module { select.add("Random"); // 1 select.add("Distance from point"); //2 select.add("Distance from centre"); //3 - }, [](JsonObject var) { //chFun + }, [this](JsonObject var) { //chFun USER_PRINTF("%s Change %s to %d\n", "initSelect chFun", var["id"].as(), var["value"].as()); LedsV::projectionNr = var["value"]; doMap = true; - SysModUI::valChangedForInstancesTemp = true; + ui->valChangedForInstancesTemp = true; }); ui->initSelect(parentVar, "ledFix", 0, false, [](JsonObject var) { //uiFun @@ -156,7 +154,7 @@ class AppModLeds:public Module { if (files->seqNrToName(fileName, var["value"])) { web->addResponse("pview", "file", fileName); } - }, [](JsonObject var) { //chFun + }, [this](JsonObject var) { //chFun USER_PRINTF("%s Change %s to %d\n", "initSelect chFun", var["id"].as(), var["value"].as()); LedsV::ledFixNr = var["value"]; @@ -190,9 +188,9 @@ class AppModLeds:public Module { ui->initNumber(parentVar, "fps", fps, 1, 999, false, [](JsonObject var) { //uiFun web->addResponse(var["id"], "comment", "Frames per second"); - }, [](JsonObject var) { //chFun - AppModLeds::fps = var["value"]; - USER_PRINTF("fps changed %d\n", AppModLeds::fps); + }, [this](JsonObject var) { //chFun + fps = var["value"]; + USER_PRINTF("fps changed %d\n", fps); }); ui->initText(parentVar, "realFps", nullptr, 10, true, [](JsonObject var) { //uiFun @@ -332,8 +330,4 @@ class AppModLeds:public Module { }; -static AppModLeds *lds; - -uint16_t AppModLeds::fps = 120; -bool AppModLeds::doMap = false; -Effects AppModLeds::effects; +static AppModLeds *lds; \ No newline at end of file diff --git a/src/Sys/SysModUI.cpp b/src/Sys/SysModUI.cpp index ca5de16a..e7781148 100644 --- a/src/Sys/SysModUI.cpp +++ b/src/Sys/SysModUI.cpp @@ -19,8 +19,6 @@ std::vector SysModUI::ucFunctions; std::vector SysModUI::loopFunctions; int SysModUI::varCounter = 1; //start with 1 so it can be negative, see var["o"] -bool SysModUI::valChangedForInstancesTemp = false; - bool SysModUI::varLoopsChanged = false;; SysModUI::SysModUI() :Module("UI") { diff --git a/src/Sys/SysModUI.h b/src/Sys/SysModUI.h index 327cd483..e0cd18ee 100644 --- a/src/Sys/SysModUI.h +++ b/src/Sys/SysModUI.h @@ -46,7 +46,7 @@ static uint8_t linearToLogarithm(JsonObject var, uint8_t value) { class SysModUI:public Module { public: - static bool valChangedForInstancesTemp; + bool valChangedForInstancesTemp = false; SysModUI(); diff --git a/src/User/UserModE131.h b/src/User/UserModE131.h index 5c3b49fa..4f9829f0 100644 --- a/src/User/UserModE131.h +++ b/src/User/UserModE131.h @@ -34,14 +34,14 @@ class UserModE131:public Module { parentVar = ui->initModule(parentVar, name); - ui->initNumber(parentVar, "dmxUni", universe, 1, 512, false, [](JsonObject var) { //uiFun + ui->initNumber(parentVar, "dmxUni", universe, 0, 7, false, [](JsonObject var) { //uiFun web->addResponse(var["id"], "label", "Universe"); }, [this](JsonObject var) { //chFun universe = var["value"]; ui->valChangedForInstancesTemp = true; }); - ui->initNumber(parentVar, "dmxChannel", 1, 1, 512, false, [](JsonObject var) { //uiFun + ui->initNumber(parentVar, "dmxChannel", 1, 0, 511, false, [](JsonObject var) { //uiFun web->addResponse(var["id"], "label", "Channel"); web->addResponse(var["id"], "comment", "First channel"); }, [](JsonObject var) { //chFun diff --git a/src/User/UserModInstances.h b/src/User/UserModInstances.h index 73355d5e..44fb1525 100644 --- a/src/User/UserModInstances.h +++ b/src/User/UserModInstances.h @@ -19,14 +19,22 @@ struct AppData { uint8_t fx; uint8_t palette; uint8_t projection; -}; // 4 bytes +}; + +struct DMX { + uint8_t universe:3; //3 bits / 8 + uint16_t start:9; //9 bits / 512 + uint8_t count:4; // 4 bits / 16 +}; //total 16 bits struct SysData { unsigned long upTime; uint8_t type; uint8_t syncGroups; - uint16_t dmxChannel; -}; //8 bytes + DMX dmx; +}; + +//note: changing AppData and SysData sizes: all instances should have the same version so change with care struct NodeInfo { IPAddress ip; @@ -52,9 +60,9 @@ struct UDPWLEDMessage { //compatible with WLED nodes as it only interprets first 44 bytes struct UDPStarModMessage { - UDPWLEDMessage header; // 44 bytes - SysData sys; //44 - AppData app; //52 + UDPWLEDMessage header; // 44 bytes fixed! + SysData sys; + AppData app; char body[1460 - sizeof(UDPWLEDMessage) - sizeof(SysData) - sizeof(AppData)]; }; @@ -121,7 +129,7 @@ class UserModInstances:public Module { } else { row.add("StarMod"); - print->fFormat(text, sizeof(text)-1, "ver:%d up:%d br:%d fx:%d pal:%d pro:%d syn:%d d:%d", node.version, node.sys.upTime, node.app.bri, node.app.fx, node.app.palette, node.app.projection, node.sys.syncGroups, node.sys.dmxChannel); + print->fFormat(text, sizeof(text)-1, "ver:%d up:%d br:%d fx:%d pal:%d pro:%d syn:%d d:%d:%d-%d", node.version, node.sys.upTime, node.app.bri, node.app.fx, node.app.palette, node.app.projection, node.sys.syncGroups, node.sys.dmx.universe, node.sys.dmx.start, node.sys.dmx.start + node.sys.dmx.count - 1); } row.add(text); @@ -197,7 +205,6 @@ class UserModInstances:public Module { ui->valChangedForInstancesTemp = false; sendSysInfoUDP(); - } } @@ -327,10 +334,15 @@ class UserModInstances:public Module { starModMessage.sys.type = 1; //StarMod starModMessage.sys.upTime = millis()/1000; starModMessage.sys.syncGroups = mdl->getValue("syncGroups"); - starModMessage.sys.dmxChannel = 0; + starModMessage.sys.dmx.universe = 0; + starModMessage.sys.dmx.start = 0; + starModMessage.sys.dmx.count = 0; #ifdef USERMOD_E131 - if (e131mod->isEnabled) - starModMessage.sys.dmxChannel = mdl->getValue("dmxChannel"); + if (e131mod->isEnabled) { + starModMessage.sys.dmx.universe = mdl->getValue("dmxUni"); + starModMessage.sys.dmx.start = mdl->getValue("dmxChannel"); + starModMessage.sys.dmx.count = 3;//e131->varsToWatch.size(); + } #endif starModMessage.app.bri = mdl->getValue("bri"); starModMessage.app.fx = mdl->getValue("fx"); @@ -375,7 +387,9 @@ class UserModInstances:public Module { node.sys.type = 0; //WLED //updated in udp sync message: node.sys.upTime = 0; - node.sys.dmxChannel = 0; + node.sys.dmx.universe = 0; + node.sys.dmx.start = 0; + node.sys.dmx.count = 0; node.sys.syncGroups = 0; node.app.bri = 0; node.app.fx = 0;