diff --git a/src/App/AppLedsV.h b/src/App/AppLedsV.h index 576de3d0..ddddfcfd 100644 --- a/src/App/AppLedsV.h +++ b/src/App/AppLedsV.h @@ -27,7 +27,8 @@ enum Projections p_None, p_Random, p_DistanceFromPoint, - p_DistanceFromCentre + p_DistanceFromCentre, + count }; class LedsV { diff --git a/src/App/AppModLeds.h b/src/App/AppModLeds.h index 5dd2b9b7..4c0f5dee 100644 --- a/src/App/AppModLeds.h +++ b/src/App/AppModLeds.h @@ -12,9 +12,6 @@ #include "AppLedsV.h" #include "AppEffects.h" -#ifdef USERMOD_E131 - #include "../User/UserModE131.h" -#endif #include #include "FastLED.h" @@ -32,6 +29,8 @@ class AppModLeds:public Module { //need to make these static as they are called in lambda functions static uint16_t fps; + unsigned long lastMappingMillis = 0; + static bool doMap; AppModLeds() :Module("Leds") {}; @@ -62,11 +61,11 @@ class AppModLeds:public Module { // if (LedsV::projectionNr == p_DistanceFromPoint) { if (fx == 9 && LedsV::fxDimension != 2) { // 9 = "Frizzles2D" LedsV::fxDimension = 2; - ledsV.ledFixProjectAndMap(); //luckily not called during reboot as ledFixNr not defined yet then + doMap = true; } if (fx != 9 && LedsV::fxDimension != 1) { // 9 = "Frizzles2D" LedsV::fxDimension = 1; - ledsV.ledFixProjectAndMap(); //luckily not called during reboot as ledFixNr not defined yet then + doMap = true; } // if (false) { @@ -136,7 +135,7 @@ class AppModLeds:public Module { print->print("%s Change %s to %d\n", "initSelect chFun", var["id"].as(), var["value"].as()); LedsV::projectionNr = var["value"]; - ledsV.ledFixProjectAndMap(); //luckily not called during reboot as ledFixNr not defined yet then + doMap = true; }); ui->initCanvas(parentVar, "pview", -1, false, [](JsonObject var) { //uiFun @@ -172,7 +171,7 @@ class AppModLeds:public Module { print->print("%s Change %s to %d\n", "initSelect chFun", var["id"].as(), var["value"].as()); LedsV::ledFixNr = var["value"]; - ledsV.ledFixProjectAndMap(); + doMap = true; char fileName[30] = ""; if (files->seqNrToName(fileName, LedsV::ledFixNr)) { @@ -234,10 +233,9 @@ class AppModLeds:public Module { // FastLED.addLeds(leds, 1); FastLED.addLeds(ledsP, NUM_LEDS_FastLed); - #ifdef USERMOD_E131 - e131mod->addWatch(1, "bri", 256); - e131mod->addWatch(2, "fx", effects.size()); - #endif + mdl->addWatch(1, "bri", 256); + mdl->addWatch(2, "fx", effects.size()); + mdl->addWatch(3, "projection", Projections::count); print->print("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed"); } @@ -245,7 +243,7 @@ class AppModLeds:public Module { void loop() { // Module::loop(); - if(millis() - frameMillis >= 1000.0/fps) { + if (millis() - frameMillis >= 1000.0/fps) { frameMillis = millis(); Effect* effect = effects[mdl->getValue("fx")]; @@ -257,12 +255,19 @@ class AppModLeds:public Module { frameCounter++; call++; } - if (millis() - secondMillis >= 1000 || !secondMillis) { + + if (millis() - secondMillis >= 1000) { secondMillis = millis(); mdl->setValueV("realFps", "%lu /s", frameCounter); frameCounter = 0; } + if (millis() - lastMappingMillis >= 1000 && doMap) { //not more then once per second (for E131) + lastMappingMillis = millis(); + doMap = false; + ledsV.ledFixProjectAndMap(); + } + // do some periodic updates EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow } @@ -271,4 +276,5 @@ class AppModLeds:public Module { static AppModLeds *lds; -uint16_t AppModLeds::fps = 40; \ No newline at end of file +uint16_t AppModLeds::fps = 40; +bool AppModLeds::doMap = false; \ No newline at end of file diff --git a/src/Sys/SysModModel.h b/src/Sys/SysModModel.h index 4c3f71ce..30c759f0 100644 --- a/src/Sys/SysModModel.h +++ b/src/Sys/SysModModel.h @@ -13,6 +13,14 @@ #include "ArduinoJson.h" +struct VarToWatch { + const char * id = nullptr; + uint16_t max = -1; + uint8_t savedValue = -1; +}; + +#define maxChannels 10 + class SysModModel:public Module { public: @@ -20,6 +28,8 @@ class SysModModel:public Module { // StaticJsonDocument<24576> model; //not static as that blows up the stack. Use extern?? static DynamicJsonDocument *model; + VarToWatch varsToWatch[maxChannels]; + SysModModel(); void setup(); void loop(); @@ -65,6 +75,11 @@ class SysModModel:public Module { //returns the var defined by id (parent to recursively call findVar) static JsonObject findVar(const char * id, JsonArray parent = JsonArray()); //static for processJson + void addWatch(uint8_t channel, const char * id, uint16_t max) { + varsToWatch[channel].id = id; + varsToWatch[channel].max = max; + } + private: static bool doWriteModel; static bool doShowObsolete; diff --git a/src/User/UserModE131.h b/src/User/UserModE131.h index cf45a1e5..fedc2b88 100644 --- a/src/User/UserModE131.h +++ b/src/User/UserModE131.h @@ -13,20 +13,10 @@ #include -#define maxChannels 10 - -struct VarToWatch { - const char * id = nullptr; - uint16_t max = -1; - uint8_t savedValue = -1; -}; - class UserModE131:public Module { public: - VarToWatch varsToWatch[maxChannels]; //up to 513 - UserModE131() :Module("e131/sACN support") { print->print("%s %s\n", __PRETTY_FUNCTION__, name); @@ -69,7 +59,7 @@ class UserModE131:public Module { e131.pull(&packet); // Pull packet from ring buffer for (int i=0; i < maxChannels; i++) { - if (packet.property_values[i] != varsToWatch[i].savedValue) { + if (packet.property_values[i] != mdl->varsToWatch[i].savedValue) { print->print("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH%d: %u -> %u", htons(packet.universe), // The Universe for this packet @@ -77,14 +67,14 @@ class UserModE131:public Module { e131.stats.num_packets, // Packet counter e131.stats.packet_errors, // Packet error counter i, - varsToWatch[i].savedValue, + mdl->varsToWatch[i].savedValue, packet.property_values[i]); // Dimmer data for Channel i - varsToWatch[i].savedValue = packet.property_values[i]; + mdl->varsToWatch[i].savedValue = packet.property_values[i]; - if (varsToWatch[i].id != nullptr) { - print->print(" var: %s\n", varsToWatch[i].id); - mdl->setValueI(varsToWatch[i].id, varsToWatch[i].savedValue%varsToWatch[i].max); // TODO: ugly to have magic string + if (mdl->varsToWatch[i].id != nullptr) { + print->print(" var: %s\n", mdl->varsToWatch[i].id); + mdl->setValueI(mdl->varsToWatch[i].id, mdl->varsToWatch[i].savedValue%mdl->varsToWatch[i].max); // TODO: ugly to have magic string } else print->print("\n"); @@ -93,11 +83,6 @@ class UserModE131:public Module { } } - void addWatch(uint8_t channel, const char * id, uint16_t max) { - varsToWatch[channel].id = id; - varsToWatch[channel].max = max; - } - private: ESPAsyncE131 e131; boolean e131Created = false;