Skip to content

Commit

Permalink
Live scripts: add rgb, inoise8, random8 and millis, slider3 function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ewoudwijma committed Aug 18, 2024
1 parent f129d92 commit 2a55683
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 13 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions misc/LiveScripts/helloSL.sc
Original file line number Diff line number Diff line change
@@ -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;
}
// }
//}
}
14 changes: 14 additions & 0 deletions misc/LiveScripts/noiseSL.sc
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -2929,7 +2929,7 @@ class LiveScriptEffect: public Effect {

ui->initSlider(parentVar, "Slider1", &slider1);
ui->initSlider(parentVar, "Slider2", &slider2);

ui->initSlider(parentVar, "Slider3", &slider3);
}
};

Expand Down
10 changes: 10 additions & 0 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
28 changes: 20 additions & 8 deletions src/User/UserModLive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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

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

Expand Down Expand Up @@ -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

Expand All @@ -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, "");
}
}

};
Expand Down

0 comments on commit 2a55683

Please sign in to comment.