Skip to content

Commit

Permalink
Live Scripts: run after reboot, run after file update
Browse files Browse the repository at this point in the history
LedEffects.h
- LiveScriptEffect.script2.onChange: set lastFileUpdated to handle running of Live Script (so done after all setups done)

UserModLive.h
- remove scPreCustomScript
- script.onChange: set lastFileUpdated to handle running of Live Script
- run: remove force parameter: force new effect always
- run: add leds post script values here (not in onChange so latest leds.size is used
  • Loading branch information
ewoudwijma committed Aug 18, 2024
1 parent 2a55683 commit b52f27e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
23 changes: 4 additions & 19 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 17 additions & 20 deletions src/User/UserModLive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; }
Expand Down Expand Up @@ -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, "");
}
Expand All @@ -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();

Expand All @@ -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());

Expand Down

0 comments on commit b52f27e

Please sign in to comment.