Skip to content

Commit

Permalink
Lambda for AppModLeds, dmx info in instances
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ewowi committed Oct 28, 2023
1 parent a85c321 commit 1bd64bf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 39 deletions.
1 change: 0 additions & 1 deletion src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
36 changes: 15 additions & 21 deletions src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -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") {};

Expand All @@ -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<int>(), bri, result);
SysModUI::valChangedForInstancesTemp = true;
ui->valChangedForInstancesTemp = true;
});

ui->initCanvas(parentVar, "pview", -1, false, [](JsonObject var) { //uiFun
Expand All @@ -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<const char *>(), fx);

doMap = effects.setEffect("fx", fx);
SysModUI::valChangedForInstancesTemp = true;
ui->valChangedForInstancesTemp = true;
});

ui->initSelect(parentVar, "palette", 4, false, [](JsonObject var) { //uiFun.
Expand All @@ -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.
Expand All @@ -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<const char *>(), var["value"].as<int>());

LedsV::projectionNr = var["value"];
doMap = true;
SysModUI::valChangedForInstancesTemp = true;
ui->valChangedForInstancesTemp = true;
});

ui->initSelect(parentVar, "ledFix", 0, false, [](JsonObject var) { //uiFun
Expand All @@ -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<const char *>(), var["value"].as<int>());

LedsV::ledFixNr = var["value"];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
2 changes: 0 additions & 2 deletions src/Sys/SysModUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
std::vector<UCFun> SysModUI::ucFunctions;
std::vector<VarLoop> 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") {
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/User/UserModE131.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 26 additions & 12 deletions src/User/UserModInstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)];
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -197,7 +205,6 @@ class UserModInstances:public Module {
ui->valChangedForInstancesTemp = false;

sendSysInfoUDP();

}
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1bd64bf

Please sign in to comment.