diff --git a/src/App/LedEffects.h b/src/App/LedEffects.h index 88cd6210..751a01bf 100644 --- a/src/App/LedEffects.h +++ b/src/App/LedEffects.h @@ -2893,36 +2893,21 @@ class LiveScriptEffect: public Effect { //set script uint8_t fileNr = var["value"][rowNr]; - char fileName[32] = ""; + if (fileNr > 0) { //not None and live setup done (before ) + gLeds = &leds; //set the leds class for live script - if (fileNr > 0 && liveM->scPreBaseScript.length()) { //not None and live setup done (before ) fileNr--; //-1 as none is no file - files->seqNrToName(fileName, fileNr, ".sc"); - ppf("script2.onChange f:%d s:%s\n", fileNr, fileName); + files->seqNrToName(web->lastFileUpdated, fileNr, ".sc"); + ppf("script2.onChange f:%d s:%s\n", fileNr, web->lastFileUpdated); // in LedLayer.h: void setPixelColorLive(unsigned16 indexV, uint32_t color) {setPixelColor(indexV, CRGB::Black);} // void (LedsLayer::*sPCCached)(unsigned16, uint32_t) = &LedsLayer::setPixelColorLive; // LedsLayer *leds2 = &leds; // (leds2->*sPCCached)(0, 0); - - gLeds = &leds; //set the leds class for live script - - //set the custom defines - liveM->scPreCustomScript = ""; - liveM->scPreCustomScript += "define width " + to_string(leds.size.x) + "\n"; - liveM->scPreCustomScript += "define height " + to_string(leds.size.y) + "\n"; - liveM->scPreCustomScript += "define NUM_LEDS " + to_string(leds.nrOfLeds) + "\n"; - liveM->scPreCustomScript += "define panel_width " + to_string(leds.size.x) + "\n"; //isn't panel_width always the same as width? } else ppf("script2.onChange not ready:%d\n", fileNr); - if (strcmp(fileName, "") != 0) - liveM->run(fileName, true); //force a new file to run - else { - liveM->kill(); - } - return true; } default: return false; }}); //script diff --git a/src/User/UserModLive.h b/src/User/UserModLive.h index aed21b20..13086fe5 100644 --- a/src/User/UserModLive.h +++ b/src/User/UserModLive.h @@ -128,7 +128,6 @@ class UserModLive:public SysModule { Parser p = Parser(); char fileName[32] = ""; //running sc file string scPreBaseScript = ""; //externals etc generated (would prefer String for esp32...) - string scPreCustomScript = ""; //externals etc generated (would prefer String for esp32...) UserModLive() :SysModule("Live") { isEnabled = false; //need to enable after fresh setup @@ -151,20 +150,12 @@ class UserModLive:public SysModule { //set script uint8_t fileNr = var["value"]; - ppf("%s script f:%d f:%d\n", name, funType, fileNr); + ppf("%s script.onChange f:%d\n", name, fileNr); - char fileName[32] = ""; - - if (fileNr > 0 && scPreBaseScript.length()) { //not None and setup done + if (fileNr > 0) { //not None and setup done fileNr--; //-1 as none is no file - files->seqNrToName(fileName, fileNr, ".sc"); - // ppf("%s script f:%d f:%d\n", name, funType, fileNr); - } - - if (strcmp(fileName, "") != 0) - run(fileName, true); //force a new file to run - else { - kill(); + files->seqNrToName(web->lastFileUpdated, fileNr, ".sc"); + ppf("%s script.onChange f:%d n:%s\n", name, fileNr, web->lastFileUpdated); } return true; } @@ -266,7 +257,7 @@ class UserModLive:public SysModule { void loop20ms() { //workaround - if (strstr(web->lastFileUpdated, ".sc") != nullptr) { + if (strstr(web->lastFileUpdated, ".sc") != nullptr && gLeds && !gLeds->doMap) { run(web->lastFileUpdated); strcpy(web->lastFileUpdated, ""); } @@ -278,11 +269,8 @@ class UserModLive:public SysModule { frameCounter = 0; } - void run(const char *fileName, bool force = false) { - ppf("live run n:%s o:%s (f:%d)\n", fileName, this->fileName, force); - - if (!force && strcmp(fileName, this->fileName) != 0) // if another fileName then force should be true; - return; + void run(const char *fileName) { + ppf("live run n:%s o:%s (f:%d)\n", fileName, this->fileName); kill(); @@ -293,7 +281,16 @@ class UserModLive:public SysModule { ppf("UserModLive setup script open %s for %s failed\n", fileName, "r"); else { - string scScript = scPreBaseScript + scPreCustomScript; + string scScript = scPreBaseScript; + + //LEDs specific + if (gLeds != nullptr) { + scScript += "define width " + to_string(gLeds->size.x) + "\n"; + scScript += "define height " + to_string(gLeds->size.y) + "\n"; + scScript += "define NUM_LEDS " + to_string(gLeds->nrOfLeds) + "\n"; + scScript += "define panel_width " + to_string(gLeds->size.x) + "\n"; //isn't panel_width always the same as width? + } + //end LEDs specific Serial.println(scScript.c_str());