Skip to content

Commit

Permalink
Set fixture to generated fixture
Browse files Browse the repository at this point in the history
FixtureGen
- generate chFun assign fileName to fixture variable (using ui->selectOptionToValue)
- generateChFun: return fileName

SysModUI: add selectOptionToValue
  • Loading branch information
ewowi committed Apr 1, 2024
1 parent 940d9d0 commit c37f59f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
53 changes: 33 additions & 20 deletions src/App/LedModFixtureGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,17 @@ class LedModFixtureGen:public SysModule {
// }});

ui->initButton(parentVar, "generate", false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ChangeFun:
generateChFun(var);
//reload fixture select
ui->callVarFun("fixture", UINT8_MAX, f_UIFun);
return true;
case f_ChangeFun: {

char fileName[32];
generateChFun(var, fileName);
ui->callVarFun("fixture", UINT8_MAX, f_UIFun); //reload fixture select

uint8_t value = ui->selectOptionToValue("fixture", fileName);
if (value != UINT8_MAX)
mdl->setValue("fixture", value);

return true; }
default: return false;
}});

Expand Down Expand Up @@ -894,22 +900,22 @@ class LedModFixtureGen:public SysModule {
genFix.closeHeader();
}

void generateChFun(JsonObject var) {
void generateChFun(JsonObject var, char * fileName) {

stackUnsigned8 fgValue = mdl->getValue("fixtureGen");

if (fgValue == f_Matrix) {

Coord3D size = (mdl->getValue("mrxColEnd").as<Coord3D>() - mdl->getValue("pnlFirst").as<Coord3D>()) + Coord3D{1,1,1};
char fileName[32]; print->fFormat(fileName, 31, "F_Matrix%d%d%d", size.x, size.y, size.z);
print->fFormat(fileName, 31, "F_Matrix%d%d%d", size.x, size.y, size.z);

getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->matrix(mdl->getValue("pnlFirst", rowNr), mdl->getValue("mrxRowEnd", rowNr), mdl->getValue("mrxColEnd", rowNr), mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
});

} else if (fgValue == f_Ring) {

char fileName[32]; print->fFormat(fileName, 31, "F_Ring%d", mdl->getValue("fixLeds").as<unsigned8>());
print->fFormat(fileName, 31, "F_Ring%d", mdl->getValue("fixLeds").as<unsigned8>());

getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
Coord3D middle = mdl->getValue("pnlFirst", rowNr);
Expand All @@ -923,7 +929,7 @@ class LedModFixtureGen:public SysModule {

} else if (fgValue == f_Rings241) {

char fileName[32]; print->fFormat(fileName, 31, "F_Rings241-%d", mdl->getValue("nrOfRings").as<unsigned8>());
print->fFormat(fileName, 31, "F_Rings241-%d", mdl->getValue("nrOfRings").as<unsigned8>());

getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
Coord3D middle = mdl->getValue("pnlFirst", rowNr);
Expand All @@ -936,43 +942,46 @@ class LedModFixtureGen:public SysModule {

} else if (fgValue == f_Spiral) {

char fileName[32]; print->fFormat(fileName, 31, "F_Spiral%d", mdl->getValue("fixLeds").as<unsigned8>());
print->fFormat(fileName, 31, "F_Spiral%d", mdl->getValue("fixLeds").as<unsigned8>());

getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->spiral(mdl->getValue("pnlFirst", rowNr), mdl->getValue("fixLeds", rowNr), mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
});

} else if (fgValue == f_Wheel) {

char fileName[32]; print->fFormat(fileName, 31, "F_Wheel%d%d", mdl->getValue("nrOfSpokes").as<unsigned8>(), mdl->getValue("ledsPerSpoke").as<unsigned8>());
print->fFormat(fileName, 31, "F_Wheel%d%d", mdl->getValue("nrOfSpokes").as<unsigned8>(), mdl->getValue("ledsPerSpoke").as<unsigned8>());

getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->wheel(mdl->getValue("pnlFirst", rowNr), mdl->getValue("nrOfSpokes", rowNr), mdl->getValue("ledsPerSpoke", rowNr), mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
});

} else if (fgValue == f_Hexagon) {

getPanels("F_Hexagon", [](GenFix * genFix, unsigned8 rowNr) {
strcpy(fileName, "F_Hexagon");
getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->hexagon(mdl->getValue("pnlFirst", rowNr), mdl->getValue("ledsPerSide", rowNr), mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
});

} else if (fgValue == f_Cone) {

char fileName[32]; print->fFormat(fileName, 31, "F_Cone%d", mdl->getValue("nrOfRings").as<unsigned8>());
print->fFormat(fileName, 31, "F_Cone%d", mdl->getValue("nrOfRings").as<unsigned8>());

getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->cone(mdl->getValue("pnlFirst", rowNr), mdl->getValue("nrOfRings", rowNr), mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
});

} else if (fgValue == f_Cloud) {

getPanels("F_Cloud5416", [](GenFix * genFix, unsigned8 rowNr) {
strcpy(fileName, "F_Cloud5416");
getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->cloud(mdl->getValue("pnlFirst", rowNr), mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
});

} else if (fgValue == f_Wall) {

getPanels("F_Wall", [](GenFix * genFix, unsigned8 rowNr) {
strcpy(fileName, "F_Wall");
getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->rings241(Coord3D{110,110,0}, 9, true, mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));

genFix->matrix(Coord3D{19,0,0}, Coord3D{19,8,0}, Coord3D{27,0,0}, mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
Expand All @@ -985,7 +994,8 @@ class LedModFixtureGen:public SysModule {

} else if (fgValue == f_6Rings) {

getPanels("F_6Rings", [](GenFix * genFix, unsigned8 rowNr) {
strcpy(fileName, "F_6Rings");
getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->rings241(Coord3D{110,110,0}, 9, true, mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
genFix->rings241(Coord3D{0,110,110}, 9, true, mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr), 90); //pan 90
genFix->rings241(Coord3D{110,110,220}, 9, true, mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
Expand All @@ -996,7 +1006,8 @@ class LedModFixtureGen:public SysModule {

} else if (fgValue == f_SpaceStation) {

getPanels("F_SpaceStation", [](GenFix * genFix, unsigned8 rowNr) {
strcpy(fileName, "F_SpaceStation");
getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
Trigo trigo;
for (int i=0; i<360; i+=20) {
uint8_t ringDiam = 50;
Expand All @@ -1008,7 +1019,8 @@ class LedModFixtureGen:public SysModule {

} else if (fgValue == f_Human) {

getPanels("F_Human", [](GenFix * genFix, unsigned8 rowNr) {
strcpy(fileName, "F_Human");
getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {

//total dimensions width: 10 + 18 + 10
// height 18 + 5 +
Expand All @@ -1032,15 +1044,16 @@ class LedModFixtureGen:public SysModule {

} else if (fgValue == f_Globe) {

char fileName[32]; print->fFormat(fileName, 31, "F_Globe%d", mdl->getValue("width").as<unsigned8>());
print->fFormat(fileName, 31, "F_Globe%d", mdl->getValue("width").as<unsigned8>());

getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->globe(mdl->getValue("pnlFirst", rowNr), mdl->getValue("width", rowNr), mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
});

} else if (fgValue == f_GeodesicDome) {

getPanels("F_GeodesicDome", [](GenFix * genFix, unsigned8 rowNr) {
strcpy(fileName, "F_GeodesicDome");
getPanels(fileName, [](GenFix * genFix, unsigned8 rowNr) {
genFix->geodesicDome(mdl->getValue("pnlFirst", rowNr), mdl->getValue("width", rowNr), mdl->getValue("fixIP", rowNr), mdl->getValue("fixPin", rowNr));
});

Expand Down
1 change: 0 additions & 1 deletion src/Sys/SysModNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "SysModWeb.h"
#include "SysModUI.h"
#include "SysModModel.h"
// #include "SysModWorkFlow.h"
#include "User/UserModMDNS.h"

SysModNetwork::SysModNetwork() :SysModule("Network") {};
Expand Down
14 changes: 14 additions & 0 deletions src/Sys/SysModUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ class SysModUI: public SysModule {
return result;
}

// assuming ui->callVarFun(varID, UINT8_MAX, f_UIFun); has been called before
uint8_t selectOptionToValue(const char *varID, const char *label) {
JsonArray options = web->getResponseObject()[varID]["options"];
// USER_PRINTF("selectOptionToValue fileName %s %s\n", label, options[0].as<String>().c_str());
uint8_t value = 0;
for (JsonVariant option: options) {
// USER_PRINTF("selectOptionToValue fileName2 %s %s\n", label, option.as<String>().c_str());
if (strstr(option, label) != nullptr) //if label part of value
return value;
value++;
}
return UINT8_MAX; //not found
}

//interpret json and run commands or set values like deserializeJson / deserializeState / deserializeConfig
void processJson(JsonVariant json); //must be Variant, not object for jsonhandler

Expand Down

0 comments on commit c37f59f

Please sign in to comment.