Skip to content

Commit

Permalink
Post Merge: change on<event> also in led modules
Browse files Browse the repository at this point in the history
Plus re-enable motion tracking
  • Loading branch information
ewoudwijma committed Jun 24, 2024
1 parent 2459377 commit 3b95efc
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 84 deletions.
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ build_flags =
-D STARBASE_DEVMODE
${ESPAsyncWebServer.build_flags}
${STARBASE_USERMOD_E131.build_flags}
; ${STARBASE_USERMOD_MPU6050.build_flags}
${STARBASE_USERMOD_MPU6050.build_flags}
; ${STARBASE_USERMOD_HA.build_flags}
lib_deps =
${ESPAsyncWebServer.lib_deps}
https://github.com/bblanchon/ArduinoJson.git#v7.0.3
; https://github.com/Jason2866/ESP32_Show_Info.git
${STARBASE_USERMOD_E131.lib_deps}
; ${STARBASE_USERMOD_MPU6050.lib_deps}
${STARBASE_USERMOD_MPU6050.lib_deps}
; ${STARBASE_USERMOD_HA.lib_deps}


Expand Down
14 changes: 7 additions & 7 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Effect {

virtual void controls(Leds &leds, JsonObject parentVar) {
ui->initSelect(parentVar, "pal", 4, false, [&leds](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_UIFun: {
case onUI: {
ui->setLabel(var, "Palette");
JsonArray options = ui->setOptions(var);
options.add("CloudColors");
Expand All @@ -51,7 +51,7 @@ class Effect {
options.add("HeatColors");
options.add("RandomColors");
return true; }
case f_ChangeFun:
case onChange:
switch (var["value"][rowNr].as<uint8_t>()) {
case 0: leds.palette = CloudColors_p; break;
case 1: leds.palette = LavaColors_p; break;
Expand Down Expand Up @@ -223,7 +223,7 @@ class RunningEffect: public Effect {

void controls(Leds &leds, JsonObject parentVar) {
ui->initSlider(parentVar, "BPM", leds.sharedData.write<uint8_t>(60), 0, 255, false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_UIFun:
case onUI:
ui->setComment(var, "in BPM!");
return true;
default: return false;
Expand Down Expand Up @@ -1276,7 +1276,7 @@ class ScrollingText: public Effect {
ui->initText(parentVar, "text", "StarLeds"); //sharedData to be implemented!
ui->initSlider(parentVar, "speed", leds.sharedData.write<uint8_t>(128));
ui->initSelect(parentVar, "font", leds.sharedData.write<uint8_t>(0), false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_UIFun: {
case onUI: {
JsonArray options = ui->setOptions(var);
options.add("4x6");
options.add("5x8");
Expand Down Expand Up @@ -1597,7 +1597,7 @@ class GameOfLife: public Effect {
void controls(Leds &leds, JsonObject parentVar) {
Effect::controls(leds, parentVar);
ui->initSelect(parentVar, "Overlay", leds.sharedData.write<byte>(0), false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) {
case f_UIFun: {
case onUI: {
JsonArray options = ui->setOptions(var);
options.add("None");
options.add("Background");
Expand All @@ -1608,7 +1608,7 @@ class GameOfLife: public Effect {
}});
ui->initCoord3D(parentVar, "Background or Overlay Color", leds.sharedData.write<Coord3D>({0,0,0}), 0, 255);
ui->initSelect (parentVar, "ruleset", leds.sharedData.write<uint8_t>(1), false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) {
case f_UIFun: {
case onUI: {
JsonArray options = ui->setOptions(var);
options.add("Custom B/S");
options.add("Conway's Game of Life B3/S23");
Expand Down Expand Up @@ -2318,7 +2318,7 @@ class GEQEffect: public Effect {
// e131mod->patchChannel(3, "fadeOut", 255); // TODO: add constant for name
// e131mod->patchChannel(4, "ripple", 255);
// for (JsonObject childVar: mdl->findVar("e131Tbl")["n"].as<JsonArray>()) {
// ui->callVarFun(childVar, UINT8_MAX, f_UIFun);
// ui->callVarFun(childVar, UINT8_MAX, onUI);
// }
// }

Expand Down
44 changes: 22 additions & 22 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ class LedModEffects:public SysModule {
JsonObject currentVar;

JsonObject tableVar = ui->initTable(parentVar, "fxTbl", nullptr, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
case onUI:
ui->setLabel(var, "Effects");
ui->setComment(var, "List of effects");
return true;
case f_AddRow: {
case onAddRow: {
rowNr = fixture.listOfLeds.size();
// ppf("chFun addRow %s[%d]\n", mdl->varID(var), rowNr);

Expand All @@ -131,7 +131,7 @@ class LedModEffects:public SysModule {
if (rowNr >= fixture.listOfLeds.size())
fixture.listOfLeds.push_back(new Leds(fixture));
return true; }
case f_DelRow: {
case onDeleteRow: {
// ppf("chFun delrow %s[%d]\n", mdl->varID(var), rowNr);
//tbd: fade to black
if (rowNr <fixture.listOfLeds.size()) {
Expand All @@ -144,11 +144,11 @@ class LedModEffects:public SysModule {
}});

currentVar = ui->initSelect(tableVar, "fx", 0, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
case onSetValue:
for (forUnsigned8 rowNr = 0; rowNr < fixture.listOfLeds.size(); rowNr++)
mdl->setValue(var, fixture.listOfLeds[rowNr]->fx, rowNr);
return true;
case f_UIFun: {
case onUI: {
ui->setLabel(var, "Effect");
ui->setComment(var, "Effect to show");
JsonArray options = ui->setOptions(var);
Expand All @@ -161,13 +161,13 @@ class LedModEffects:public SysModule {
options.add(JsonString(buf, JsonString::Copied)); //copy!
}
return true; }
case f_ChangeFun:
case onChange:

if (rowNr == UINT8_MAX) rowNr = 0; // in case fx without a rowNr

//create a new leds instance if a new row is created
if (rowNr >= fixture.listOfLeds.size()) {
ppf("listOfLeds fx[%d] changeFun %d %s\n", rowNr, fixture.listOfLeds.size(), mdl->findVar("fx")["value"].as<String>().c_str());
ppf("listOfLeds fx[%d] onChange %d %s\n", rowNr, fixture.listOfLeds.size(), mdl->findVar("fx")["value"].as<String>().c_str());
fixture.listOfLeds.push_back(new Leds(fixture));
}

Expand Down Expand Up @@ -211,11 +211,11 @@ class LedModEffects:public SysModule {

//projection, default projection is 'default'
currentVar = ui->initSelect(tableVar, "pro", 1, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
case onSetValue:
for (forUnsigned8 rowNr = 0; rowNr < fixture.listOfLeds.size(); rowNr++)
mdl->setValue(var, fixture.listOfLeds[rowNr]->projectionNr, rowNr);
return true;
case f_UIFun: {
case onUI: {
ui->setLabel(var, "Projection");
ui->setComment(var, "How to project fx");

Expand All @@ -229,7 +229,7 @@ class LedModEffects:public SysModule {
options.add(JsonString(buf, JsonString::Copied)); //copy!
}
return true; }
case f_ChangeFun:
case onChange:

if (rowNr == UINT8_MAX) rowNr = 0; // in case fx without a rowNr

Expand Down Expand Up @@ -257,17 +257,17 @@ class LedModEffects:public SysModule {
currentVar["dash"] = true;

ui->initCoord3D(tableVar, "fxStart", {0,0,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
case onSetValue:
for (forUnsigned8 rowNr = 0; rowNr < fixture.listOfLeds.size(); rowNr++) {
ppf("fxStart[%d] valueFun %d,%d,%d\n", rowNr, fixture.listOfLeds[rowNr]->startPos.x, fixture.listOfLeds[rowNr]->startPos.y, fixture.listOfLeds[rowNr]->startPos.z);
ppf("fxStart[%d] onSetValue %d,%d,%d\n", rowNr, fixture.listOfLeds[rowNr]->startPos.x, fixture.listOfLeds[rowNr]->startPos.y, fixture.listOfLeds[rowNr]->startPos.z);
mdl->setValue(var, fixture.listOfLeds[rowNr]->startPos, rowNr);
}
return true;
case f_UIFun:
case onUI:
ui->setLabel(var, "Start");
ui->setComment(var, "In pixels");
return true;
case f_ChangeFun:
case onChange:
if (rowNr < fixture.listOfLeds.size()) {
fixture.listOfLeds[rowNr]->startPos = mdl->getValue(var, rowNr).as<Coord3D>();

Expand All @@ -285,17 +285,17 @@ class LedModEffects:public SysModule {
}});

ui->initCoord3D(tableVar, "fxEnd", {8,8,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
case onSetValue:
for (forUnsigned8 rowNr = 0; rowNr < fixture.listOfLeds.size(); rowNr++) {
ppf("fxEnd[%d] valueFun %d,%d,%d\n", rowNr, fixture.listOfLeds[rowNr]->endPos.x, fixture.listOfLeds[rowNr]->endPos.y, fixture.listOfLeds[rowNr]->endPos.z);
ppf("fxEnd[%d] onSetValue %d,%d,%d\n", rowNr, fixture.listOfLeds[rowNr]->endPos.x, fixture.listOfLeds[rowNr]->endPos.y, fixture.listOfLeds[rowNr]->endPos.z);
mdl->setValue(var, fixture.listOfLeds[rowNr]->endPos, rowNr);
}
return true;
case f_UIFun:
case onUI:
ui->setLabel(var, "End");
ui->setComment(var, "In pixels");
return true;
case f_ChangeFun:
case onChange:
if (rowNr < fixture.listOfLeds.size()) {
fixture.listOfLeds[rowNr]->endPos = mdl->getValue(var, rowNr).as<Coord3D>();

Expand All @@ -313,25 +313,25 @@ class LedModEffects:public SysModule {
}});

ui->initText(tableVar, "fxSize", nullptr, 32, true, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun: {
case onSetValue: {
// for (std::vector<Leds *>::iterator leds=fixture.listOfLeds.begin(); leds!=fixture.listOfLeds.end(); ++leds) {
stackUnsigned8 rowNr = 0;
for (Leds *leds:fixture.listOfLeds) {
char message[32];
print->fFormat(message, sizeof(message)-1, "%d x %d x %d -> %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds);
ppf("valueFun fxSize[%d] = %s\n", rowNr, message);
ppf("onSetValue fxSize[%d] = %s\n", rowNr, message);
mdl->setValue(var, JsonString(message, JsonString::Copied), rowNr); //rowNr
rowNr++;
}
return true; }
case f_UIFun:
case onUI:
ui->setLabel(var, "Size");
return true;
default: return false;
}});

// ui->initSelect(parentVar, "fxLayout", 0, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
// case f_UIFun: {
// case onUI: {
// ui->setLabel(var, "Layout");
// ui->setComment(var, "WIP");
// JsonArray options = ui->setOptions(var);
Expand Down
34 changes: 17 additions & 17 deletions src/App/LedModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class LedModFixture:public SysModule {
parentVar = ui->initAppMod(parentVar, name, 1100);

JsonObject currentVar = ui->initCheckBox(parentVar, "on", true, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
case onUI:
ui->setLabel(var, "On");
return true;
case f_ChangeFun:
case onChange:
mdl->callVarChangeFun(mdl->findVar("bri"), UINT8_MAX, true); //set FastLed brightness (init is true so bri value not send via udp)
return true;
default: return false;
Expand All @@ -36,11 +36,11 @@ class LedModFixture:public SysModule {

//logarithmic slider (10)
currentVar = ui->initSlider(parentVar, "bri", &bri, 0, 255, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
case onUI:
ui->setLabel(var, "Brightness");
return true;
case f_ChangeFun: {
//bri set by StarMod during changeFun
case onChange: {
//bri set by StarMod during onChange
stackUnsigned8 result = mdl->getValue("on").as<bool>()?mdl->varLinearToLogarithm(var, bri):0;

FastLED.setBrightness(result);
Expand All @@ -53,12 +53,12 @@ class LedModFixture:public SysModule {
currentVar["dash"] = true; //these values override model.json???

currentVar = ui->initCanvas(parentVar, "pview", UINT16_MAX, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
case onUI:
ui->setLabel(var, "Preview");
// ui->setComment(var, "Shows the fixture");
// ui->setComment(var, "Click to enlarge");
return true;
case f_LoopFun: {
case onLoop: {
var["interval"] = max(eff->fixture.nrOfLeds * web->ws.count()/200, 16U)*10; //interval in ms * 10, not too fast //from cs to ms

web->sendDataWs([this](AsyncWebSocketMessageBuffer * wsBuf) {
Expand Down Expand Up @@ -108,7 +108,7 @@ class LedModFixture:public SysModule {
}});

ui->initSelect(currentVar, "viewRot", &viewRotation, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun: {
case onUI: {
ui->setLabel(var, "Rotation");
// ui->setComment(var, "View rotation");
JsonArray options = ui->setOptions(var);
Expand All @@ -124,7 +124,7 @@ class LedModFixture:public SysModule {
}});

currentVar = ui->initSelect(parentVar, "fixture", &eff->fixture.fixtureNr, false ,[](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun: {
case onUI: {
// ui->setComment(var, "Fixture to display effect on");
JsonArray options = ui->setOptions(var);
files->dirToJson(options, true, "F_"); //only files containing F(ixture), alphabetically
Expand All @@ -135,7 +135,7 @@ class LedModFixture:public SysModule {
web->addResponse("pview", "file", JsonString(fileName, JsonString::Copied));
}
return true; }
case f_ChangeFun: {
case onChange: {
eff->fixture.doMap = true;
eff->fixture.doAllocPins = true;

Expand All @@ -155,42 +155,42 @@ class LedModFixture:public SysModule {
}}); //fixture

ui->initCoord3D(currentVar, "fixSize", eff->fixture.fixSize, 0, NUM_LEDS_Max, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
case onSetValue:
mdl->setValue(var, eff->fixture.fixSize);
return true;
case f_UIFun:
case onUI:
ui->setLabel(var, "Size");
return true;
default: return false;
}});

ui->initNumber(currentVar, "fixCount", eff->fixture.nrOfLeds, 0, UINT16_MAX, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
case onSetValue:
mdl->setValue(var, eff->fixture.nrOfLeds);
return true;
case f_UIFun:
case onUI:
ui->setLabel(var, "Count");
web->addResponseV(var["id"], "comment", "Max %d", NUM_LEDS_Max);
return true;
default: return false;
}});

ui->initNumber(parentVar, "fps", &eff->fps, 1, 999, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
case onUI:
ui->setComment(var, "Frames per second");
return true;
default: return false;
}});

ui->initText(parentVar, "realFps", nullptr, 10, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
case onUI:
web->addResponseV(var["id"], "comment", "f(%d leds)", eff->fixture.nrOfLeds);
return true;
default: return false;
}});

ui->initCheckBox(parentVar, "fShow", &eff->fShow, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
case onUI:
ui->setLabel(var, "FastLed show");
ui->setComment(var, "dev performance tuning");
return true;
Expand Down
Loading

0 comments on commit 3b95efc

Please sign in to comment.