Skip to content

Commit

Permalink
VarFun refactor: only one functions per variable
Browse files Browse the repository at this point in the history
General
- change from multiple var funs (uiFun, chFun, loopFun, valueFun) to one *with funType parameter
- save 1% of flash code (now 68.5)

SysModUI:
- add FunIDs enum with function types
- extend UFun with function parameter
- remove CFun
- remove cFunctions
- initVarAndUpdate: run varFun for valueFun and changeFun
- loopfun: call varFun with f_loopFun parameter
- init functions: remove other functions parameters
- processJson: call varFun with f_UIFun parameter (and dummy rowNr)
  • Loading branch information
ewowi committed Feb 10, 2024
1 parent ee15eef commit 4afd430
Show file tree
Hide file tree
Showing 25 changed files with 2,255 additions and 1,873 deletions.
8 changes: 4 additions & 4 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {
}

//don't call uiFun on table rows (the table header calls uiFun and propagate this to table row columns in changeHTML when needed - e.g. select)
if (variable.uiFun == null || variable.uiFun == -2) { //request processed
if (variable.fun == null || variable.fun == -2) { //request processed
variable.chk = "gen2";
changeHTML(variable, variable, rowNr); // set the variable with its own changed values
}
Expand All @@ -433,12 +433,12 @@ function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {
changeHTML(variable, {"value":variable.value, "chk":"gen1"}, rowNr); //set only the value

//call ui Functionality, if defined (to set label, comment, select etc)
if (variable.uiFun >= 0) { //>=0 as element in var
if (variable.fun >= 0) { //>=0 as element in var
uiFunCommands.push(variable.id);
if (uiFunCommands.length > 8) { //every 8 vars (to respect responseDoc size) check WS_EVT_DATA info
flushUIFunCommands();
}
variable.uiFun = -1; //requested
variable.fun = -1; //requested
}
}

Expand Down Expand Up @@ -576,7 +576,7 @@ function receiveData(json) {
let variable = findVar(key);

if (variable) {
variable.uiFun = -2; // request processed
variable.fun = -2; // request processed

value.chk = "uiFun";
changeHTML(variable, value); //changeHTML will find the rownumbers if needed
Expand Down
64 changes: 39 additions & 25 deletions src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,27 @@ class Effect {
virtual void controls(JsonObject parentVar, Leds &leds) {}

void addPalette(JsonObject parentVar, uint8_t value, uint8_t rowNr) {
JsonObject currentVar = ui->initSelect(parentVar, "pal", value, rowNr, false, [](JsonObject var) { //uiFun.
web->addResponse(var["id"], "label", "Palette");
web->addResponse(var["id"], "comment", "Colors");
JsonArray select = web->addResponseA(var["id"], "options");
select.add("CloudColors");
select.add("LavaColors");
select.add("OceanColors");
select.add("ForestColors");
select.add("RainbowColors");
select.add("RainbowStripeColors");
select.add("PartyColors");
select.add("HeatColors");
}, nullptr, nullptr, 2, [this](JsonObject var, uint8_t rowNr) { //valueFun
JsonObject currentVar = ui->initSelect(parentVar, "pal", value, rowNr, false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_ValueFun:
mdl->setValue(var, 4, rowNr); //4 is default
});
return true;
case f_UIFun: {
web->addResponse(var["id"], "label", "Palette");
web->addResponse(var["id"], "comment", "Colors");
JsonArray select = web->addResponseA(var["id"], "options");
select.add("CloudColors");
select.add("LavaColors");
select.add("OceanColors");
select.add("ForestColors");
select.add("RainbowColors");
select.add("RainbowStripeColors");
select.add("PartyColors");
select.add("HeatColors");
return true;
}
default: return false;
}});
//tbd: check if memory is freed!
currentVar["stage"] = true;
}

Expand Down Expand Up @@ -191,9 +197,13 @@ class RunningEffect: public Effect {
// leds[leds.nrOfLeds -1 - pos2] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value
}
void controls(JsonObject parentVar, Leds &leds) {
ui->initSlider(parentVar, "BPM", 60, leds.rowNr, 0, 255, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "comment", "in BPM!");
});
ui->initSlider(parentVar, "BPM", 60, leds.rowNr, 0, 255, false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_UIFun:
web->addResponse(var["id"], "comment", "in BPM!");
return true;
default: return false;
}});
//tbd: check if memory is freed!
ui->initSlider(parentVar, "fade", 128, leds.rowNr);
}
};
Expand Down Expand Up @@ -696,14 +706,18 @@ class ScrollingText2D: public Effect {
void controls(JsonObject parentVar, Leds &leds) {
ui->initText(parentVar, "text", "StarMod", leds.rowNr);
ui->initSlider(parentVar, "Speed", 128, leds.rowNr);
ui->initSelect(parentVar, "font", 0, leds.rowNr, false, [](JsonObject var) { //uiFun.
JsonArray select = web->addResponseA(var["id"], "options");
select.add("4x6");
select.add("5x8");
select.add("5x12");
select.add("6x8");
select.add("7x9");
});
ui->initSelect(parentVar, "font", 0, leds.rowNr, false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_UIFun: {
JsonArray select = web->addResponseA(var["id"], "options");
select.add("4x6");
select.add("5x8");
select.add("5x12");
select.add("6x8");
select.add("7x9");
return true;
}
default: return false;
}});
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/App/AppFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

for (std::vector<Leds>::iterator leds=ledsList.begin(); leds!=ledsList.end(); ++leds) {
//vectors really gone now?
for (std::vector<std::vector<uint16_t>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); physMap++)
for (std::vector<std::vector<uint16_t>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap)
physMap->clear();
leds->mappingTable.clear();
}
Expand Down Expand Up @@ -302,7 +302,7 @@

// uint16_t x=0; //indexV
// uint16_t y=0;
// // for (std::vector<std::vector<uint16_t>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); physMap++) {
// // for (std::vector<std::vector<uint16_t>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap) {
// for (std::vector<uint16_t>physMap:leds->mappingTable) {
// if (physMap.size()) {
// USER_PRINTF("ledV %d mapping: firstLedP: %d #ledsP: %d", x, physMap[0], physMap.size());
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum Projections
p_Multiply,
p_Kaleidoscope,
p_Fun,
count
p_count
};


Expand Down
6 changes: 3 additions & 3 deletions src/App/AppLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ CRGB Leds::getPixelColor(uint16_t indexV) {
void Leds::fadeToBlackBy(uint8_t fadeBy) {
//fade2black for old start to endpos

for (std::vector<std::vector<uint16_t>>::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); physMap++) {
for (std::vector<std::vector<uint16_t>>::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (uint16_t indexP:*physMap) {
CRGB oldValue = fixture->ledsP[indexP];
fixture->ledsP[indexP].nscale8(255-fadeBy); //this overrides the old value
Expand All @@ -66,7 +66,7 @@ void Leds::fadeToBlackBy(uint8_t fadeBy) {

void Leds::fill_solid(const struct CRGB& color) {
//fade2black for old start to endpos
for (std::vector<std::vector<uint16_t>> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); physMap++) {
for (std::vector<std::vector<uint16_t>> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (uint16_t indexP:*physMap) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], 128);
}
Expand All @@ -79,7 +79,7 @@ void Leds::fill_rainbow(uint8_t initialhue, uint8_t deltahue) {
hsv.val = 255;
hsv.sat = 240;

for (std::vector<std::vector<uint16_t>> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); physMap++) {
for (std::vector<std::vector<uint16_t>> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (uint16_t indexP:*physMap) {
fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], 128);
}
Expand Down
Loading

0 comments on commit 4afd430

Please sign in to comment.