From 2a556836ccbece50f4d0ea4cdf56d844d80fb671 Mon Sep 17 00:00:00 2001 From: Ewoud Date: Sun, 18 Aug 2024 18:19:40 +0200 Subject: [PATCH] Live scripts: add rgb, inoise8, random8 and millis, slider3 function move sc files to LiveScripts folder add noiseSL (not working yet) and hello scripts LedEffects.h - LiveScriptEffect.script2.onChange: change debug info - LiveScriptEffect: add Slider3 LedModEffects - fx.onChange: kill live script if other effect UserModLive - show every 10s - add rgb, inoise8, random8 and millis function - add slider3 - kill: only if __run_handle --- misc/{ => LiveScripts}/animwleSL.sc | 0 misc/{ => LiveScripts}/ballsSL.sc | 0 misc/{ => LiveScripts}/beatmaniaSL.sc | 0 .../green_ripple_reflectionsSL.sc | 0 misc/LiveScripts/helloSL.sc | 26 +++++++++++++++++ misc/LiveScripts/noiseSL.sc | 14 ++++++++++ misc/{ => LiveScripts}/octoSL.sc | 0 misc/{ => LiveScripts}/showtest1.sc | 0 misc/{ => LiveScripts}/showtest2.sc | 0 src/App/LedEffects.h | 10 +++---- src/App/LedModEffects.h | 10 +++++++ src/User/UserModLive.h | 28 +++++++++++++------ 12 files changed, 75 insertions(+), 13 deletions(-) rename misc/{ => LiveScripts}/animwleSL.sc (100%) rename misc/{ => LiveScripts}/ballsSL.sc (100%) rename misc/{ => LiveScripts}/beatmaniaSL.sc (100%) rename misc/{ => LiveScripts}/green_ripple_reflectionsSL.sc (100%) create mode 100644 misc/LiveScripts/helloSL.sc create mode 100644 misc/LiveScripts/noiseSL.sc rename misc/{ => LiveScripts}/octoSL.sc (100%) rename misc/{ => LiveScripts}/showtest1.sc (100%) rename misc/{ => LiveScripts}/showtest2.sc (100%) diff --git a/misc/animwleSL.sc b/misc/LiveScripts/animwleSL.sc similarity index 100% rename from misc/animwleSL.sc rename to misc/LiveScripts/animwleSL.sc diff --git a/misc/ballsSL.sc b/misc/LiveScripts/ballsSL.sc similarity index 100% rename from misc/ballsSL.sc rename to misc/LiveScripts/ballsSL.sc diff --git a/misc/beatmaniaSL.sc b/misc/LiveScripts/beatmaniaSL.sc similarity index 100% rename from misc/beatmaniaSL.sc rename to misc/LiveScripts/beatmaniaSL.sc diff --git a/misc/green_ripple_reflectionsSL.sc b/misc/LiveScripts/green_ripple_reflectionsSL.sc similarity index 100% rename from misc/green_ripple_reflectionsSL.sc rename to misc/LiveScripts/green_ripple_reflectionsSL.sc diff --git a/misc/LiveScripts/helloSL.sc b/misc/LiveScripts/helloSL.sc new file mode 100644 index 00000000..4ae3e22f --- /dev/null +++ b/misc/LiveScripts/helloSL.sc @@ -0,0 +1,26 @@ +int i; + +void setup() +{ + +} + + +void loop() { + + fadeToBlackBy(2); // Adjustable fade rate. +// for (uint8_t y = 0; y < height; y++) { +// for (uint8_t x = 0; x < width; x++) { + //sCFP(y*panel_width+x,i, 255); + CRGB gg = rgb(slider1,0,slider3); + //CRGB gg = hsv(beatSin8(i, 0, 255),255,255); + //CRGB gg = hsv(i,255,beatSin8(i, 0, 255)); + //sPC(y*panel_width+x, gg); + sPC(i, gg); + i= i + 1; + if ( i == width * height) { + i =0; +} +// } +//} +} \ No newline at end of file diff --git a/misc/LiveScripts/noiseSL.sc b/misc/LiveScripts/noiseSL.sc new file mode 100644 index 00000000..545299f2 --- /dev/null +++ b/misc/LiveScripts/noiseSL.sc @@ -0,0 +1,14 @@ +void setup() +{ +} + +void loop() { + for (int y = 0; y < width; y++) { + for (int x = 0; x < height; x++) { + uint8_t pixelHue8 = inoise8(x * slider1, y * slider1, millis() / (16 - slider2)); + // leds.setPixelColor(leds.XY(x, y), ColorFromPalette(leds.palette, pixelHue8)); + //leds.setPixelColorPal(leds.XY(x, y), pixelHue8); + sCFP(y*panel_width+x, pixelHue8, 255); + } + } +} \ No newline at end of file diff --git a/misc/octoSL.sc b/misc/LiveScripts/octoSL.sc similarity index 100% rename from misc/octoSL.sc rename to misc/LiveScripts/octoSL.sc diff --git a/misc/showtest1.sc b/misc/LiveScripts/showtest1.sc similarity index 100% rename from misc/showtest1.sc rename to misc/LiveScripts/showtest1.sc diff --git a/misc/showtest2.sc b/misc/LiveScripts/showtest2.sc similarity index 100% rename from misc/showtest2.sc rename to misc/LiveScripts/showtest2.sc diff --git a/src/App/LedEffects.h b/src/App/LedEffects.h index 4b4a5569..88cd6210 100644 --- a/src/App/LedEffects.h +++ b/src/App/LedEffects.h @@ -2893,14 +2893,12 @@ class LiveScriptEffect: public Effect { //set script uint8_t fileNr = var["value"][rowNr]; - ppf("script f:%d f:%d\n", funType, fileNr); - char fileName[32] = ""; - if (fileNr > 0 && liveM->scPreBaseScript.length()) { //not None and live setup done + 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("script f:%d f:%d s:%s\n", funType, fileNr, fileName); + ppf("script2.onChange f:%d s:%s\n", fileNr, fileName); // in LedLayer.h: void setPixelColorLive(unsigned16 indexV, uint32_t color) {setPixelColor(indexV, CRGB::Black);} // void (LedsLayer::*sPCCached)(unsigned16, uint32_t) = &LedsLayer::setPixelColorLive; @@ -2916,6 +2914,8 @@ class LiveScriptEffect: public Effect { 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 @@ -2929,7 +2929,7 @@ class LiveScriptEffect: public Effect { ui->initSlider(parentVar, "Slider1", &slider1); ui->initSlider(parentVar, "Slider2", &slider2); - + ui->initSlider(parentVar, "Slider3", &slider3); } }; diff --git a/src/App/LedModEffects.h b/src/App/LedModEffects.h index 0f2a951e..739a679f 100644 --- a/src/App/LedModEffects.h +++ b/src/App/LedModEffects.h @@ -222,6 +222,16 @@ class LedModEffects:public SysModule { // leds->doMap = true; //stop the effects loop already here + #ifdef STARBASE_USERMOD_LIVE + //kill live script of moving to other effect + if (leds->fx < effects.size()) { + Effect* effect = effects[leds->fx]; + if (strcmp(effect->name(), "Live Script") == 0) { + liveM->kill(); + } + } + #endif + leds->fx = mdl->getValue(var, rowNr); if (leds->fx < effects.size()) { diff --git a/src/User/UserModLive.h b/src/User/UserModLive.h index 6347f4ab..aed21b20 100644 --- a/src/User/UserModLive.h +++ b/src/User/UserModLive.h @@ -51,7 +51,7 @@ static void show() _max = fps; if (_nb_stat > 10) _totfps += fps; - if (_nb_stat%1000 == 0) + if (_nb_stat%10000 == 0) //every 10 sec. (temp) //Serial.printf("current show fps:%.2f\tglobal fps:%.2f\tfps animation:%.2f\taverage:%.2f\tmin:%.2f\tmax:%.2f\r\n", fps2, fps3, fps, _totfps / (_nb_stat - 10), _min, _max); ppf("current show fps:%.2f\tglobal fps:%.2f\tfps animation:%.2f average:%.2f min:%.2f max:%.2f\r\n",fps2, fps3, fps, _totfps / (_nb_stat - 10), _min, _max); time1 = ESP.getCycleCount(); @@ -92,18 +92,22 @@ static float _time(float j) { myVal = fmod(myVal, 1.0); // ewowi: with 0.015 as input, you get fmod(millis/1000,1.0), which has a period of 1 second, sounds right return myVal; } +// static millis() //LEDS specific static CRGB POSV(uint8_t h, uint8_t s, uint8_t v) {return CHSV(h, s, v);} //why call POSV and not hsv? +static CRGB rgb(uint8_t r, uint8_t g, uint8_t b) {return CRGB(r, g, b);} //why call POSV and not hsv? static uint8_t _sin8(uint8_t a) {return sin8(a);} static uint8_t _cos8(uint8_t a) {return cos8(a);} static uint8_t _beatSin8(uint8_t a1, uint8_t a2, uint8_t a3) {return beatsin8(a1, a2, a3);} +static uint8_t _inoise8(uint16_t a1, uint16_t a2, uint16_t a3) {return inoise8(a1, a2, a3);} +static uint8_t _random8() {return random8();} static LedsLayer *gLeds = nullptr; static void _fadeToBlackBy(uint8_t a1) {gLeds->fadeToBlackBy(a1);} static void sPCLive(uint16_t pixel, CRGB color) { // int t needed - otherwise wrong colors, very strange if (gLeds) { - // if (t == 0) ppf(" %d,%d,%d", color.r, color.g, color.b); + // ppf(" %d,%d,%d", color.r, color.g, color.b); gLeds->setPixelColor(pixel, color); } } @@ -113,6 +117,7 @@ static void sCFPLive(uint16_t pixel, uint8_t index, uint8_t brightness) { // int } uint8_t slider1 = 128; uint8_t slider2 = 128; +uint8_t slider3 = 128; //End LEDS specific @@ -184,7 +189,7 @@ class UserModLive:public SysModule { addExternalFun("float", "sin", "(float a1)", (void *)_sin); addExternalFun("float", "time", "(float a1)", (void *)_time); addExternalFun("float", "triangle", "(float a1)", (void *)_triangle); - addExternalFun("uint8_t", "beatSin8", "(uint8_t a1, uint8_t a2, uint8_t a3)", (void *)_beatSin8); + addExternalFun("uint32_t", "millis", "()", (void *)millis); // added by StarBase addExternalFun("void", "pinMode", "(int a1, int a2)", (void *)&pinMode); @@ -196,6 +201,10 @@ class UserModLive:public SysModule { //LEDS specific addExternalFun("CRGB", "hsv", "(int a1, int a2, int a3)", (void *)POSV); + addExternalFun("CRGB", "rgb", "(int a1, int a2, int a3)", (void *)rgb); + addExternalFun("uint8_t", "beatSin8", "(uint8_t a1, uint8_t a2, uint8_t a3)", (void *)_beatSin8); + addExternalFun("uint8_t", "inoise8", "(uint16_t a1, uint16_t a2, uint16_t a3)", (void *)_inoise8); + addExternalFun("uint8_t", "random8", "()", (void *)_random8); addExternalFun("uint8_t", "sin8","(uint8_t a1)",(void*)_sin8); //using int here causes value must be between 0 and 16 error!!! addExternalFun("uint8_t", "cos8","(uint8_t a1)",(void*)_cos8); //using int here causes value must be between 0 and 16 error!!! addExternalFun("void", "sPC", "(uint16_t a1, CRGB a2)", (void *)sPCLive); // int t needed - otherwise wrong colors, very strange @@ -206,6 +215,7 @@ class UserModLive:public SysModule { //converting from 'void (LedsLayer::*)(uint16_t, uint32_t)' {aka 'void (LedsLayer::*)(short unsigned int, unsigned int)'} to 'void*' [-Wpmf-conversions] addExternalVal("uint8_t", "slider1", &slider1); //used in map function addExternalVal("uint8_t", "slider2", &slider2); //used in map function + addExternalVal("uint8_t", "slider3", &slider3); //used in map function //End LEDS specific @@ -294,7 +304,7 @@ class UserModLive:public SysModule { preScriptNrOfLines++; } - ppf("preScript of %s has %d lines\n", fileName, preScriptNrOfLines); + ppf("preScript of %s has %d lines\n", fileName, preScriptNrOfLines+1); //+1 to subtract the line from parser error line reported scScript += string(f.readString().c_str()); // add sc file @@ -320,10 +330,12 @@ class UserModLive:public SysModule { } void kill() { - ppf("kill %s\n", fileName); - SCExecutable._kill(); //kill any old tasks - fps = 0; - strcpy(fileName, ""); + if (__run_handle) { //isRunning + ppf("kill %s\n", fileName); + SCExecutable._kill(); //kill any old tasks + fps = 0; + strcpy(fileName, ""); + } } };