Skip to content

Commit

Permalink
UserModLive: sync live script with main loop (smooth on real leds)
Browse files Browse the repository at this point in the history
pio.ini
- asmParser v2.1.1 to release 1.1.0

UserModLive
- add loopState for sync between live script and main loop
- check loopState in main loop and in show function
  • Loading branch information
ewoudwijma committed Aug 9, 2024
1 parent 553b6a8 commit 0036269
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion misc/animwleSL.sc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// WIP, By Yves but time and triangle is now external
// WIP, By Yves but time and triangle is now external, not working yet
// Unexpected at line:115
// preScript has 27 lines, so should be 88, or a but around but looks okay there

Expand Down
2 changes: 1 addition & 1 deletion misc/green_ripple_reflectionsSL.sc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void loop() {
//printCustom((float)index,a,b,c,v);
CRGB gg = hsv(0.3 * 255, a * 255, v * 255);
for (uint8_t y = 0; y < height; y++) {
sPC(0, y*panel_width+index, gg);
sPC(y*panel_width+index, gg);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ build_flags =
-D STARBASE_USERMOD_LIVE
lib_deps =
; https://github.com/hpwit/ASMParser.git#4b2da1a ; mem branche commit of 20240716
https://github.com/hpwit/ASMParser.git#v2.1.1 ;
; https://github.com/hpwit/ASMParser.git#v2.1.1 ;
https://github.com/hpwit/ASMParser.git#21186c0 ; this is release 1.1.0 of 20240808 but #1.1.0 gives error

[STARLIGHT_CLOCKLESS_LED_DRIVER]
build_flags =
Expand All @@ -88,7 +89,7 @@ lib_deps =
build_flags =
; -D APP=StarBase
-D PIOENV=$PIOENV
-D VERSION=24072010 ; Date and time (GMT!), update at every commit!!
-D VERSION=24080910 ; Date and time (GMT!), update at every commit!!
-D LFS_THREADSAFE ; enables use of semaphores in LittleFS driver
-D STARBASE_DEVMODE
${ESPAsyncWebServer.build_flags} ;alternatively PsychicHttp
Expand Down Expand Up @@ -265,10 +266,10 @@ build_flags =
-D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_DFU_ON_BOOT=0 -D ARDUINO_USB_MSC_ON_BOOT=0 ; for debugging over USB
; -D DEBUG=1 -D CORE_DEBUG_LEVEL=1 -D ARDUINOJSON_DEBUG=1 ; for more debug output
; -DSTARBASE_LOLIN_WIFI_FIX ; I don't trust the tiny ceramic antenna - use workaround for LOLIN C3/S2/S3 wifi instability. https://www.wemos.cc/en/latest/c3/c3_mini_1_0_0.html#about-wifi
${STARLIGHT_CLOCKLESS_LED_DRIVER_S3.build_flags} ; temporary here, until there is one driver for s3 and non s3
; ${STARLIGHT_CLOCKLESS_LED_DRIVER_S3.build_flags} ; temporary here, until there is one driver for s3 and non s3
lib_deps =
${env.lib_deps}
${STARLIGHT_CLOCKLESS_LED_DRIVER_S3.lib_deps} ; temporary here, until there is one driver for s3 and non s3
; ${STARLIGHT_CLOCKLESS_LED_DRIVER_S3.lib_deps} ; temporary here, until there is one driver for s3 and non s3

; check: https://docs.espressif.com/projects/esp-idf/en/stable/esp32s3/api-reference/peripherals/temp_sensor.html

Expand Down
35 changes: 22 additions & 13 deletions src/User/UserModLive.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static uint32_t _nb_stat = 0;
static float _totfps;
static float fps = 0; //integer?
static unsigned long frameCounter = 0;
static uint8_t loopState = 0; //waiting on live script

//external function implementation (tbd: move into class)

Expand Down Expand Up @@ -58,7 +59,14 @@ static void show()

// SKIPPED: check that both v1 and v2 are int numbers
// RETURN_VALUE(VALUE_FROM_INT(0), rindex);
delay(1); //to feed the watchdog
delay(1); //to feed the watchdog (also if loopState == 0)
while (loopState != 0) { //not waiting on live script
delay(1); //to feed the watchdog
// set to 0 by main loop
}
//do live script cycle
loopState = 1; //live script produced a frame, main loop will deal with it
// ppf("loopState %d\n", loopState);
}

static void resetShowStats()
Expand Down Expand Up @@ -116,7 +124,6 @@ class UserModLive:public SysModule {
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...)
// bool setupDone = false;

UserModLive() :SysModule("Live") {
isEnabled = false; //need to enable after fresh setup
Expand Down Expand Up @@ -235,12 +242,16 @@ class UserModLive:public SysModule {
}

void loop() {
// this will result in: Stopping the program...
// if (setupDone) {
// SCExecutable.executeAsTask("loop");
// ppf(".");
// show();
// }
if (__run_handle) { //isRunning
if (loopState == 2) {// show has been called (in other loop)
loopState = 0; //waiting on live script
// ppf("loopState %d\n", loopState);
}
else if (loopState == 1) {
loopState = 2; //other loop can call show (or preview)
// ppf("loopState %d\n", loopState);
}
}
}

void loop20ms() {
Expand Down Expand Up @@ -283,22 +294,21 @@ class UserModLive:public SysModule {
preScriptNrOfLines++;
}

ppf("preScript has %d lines\n", preScriptNrOfLines);
ppf("preScript of %s has %d lines\n", fileName, preScriptNrOfLines);

scScript += string(f.readString().c_str()); // add sc file

ppf("Before parsing\n");
ppf("Before parsing of %s\n", fileName);
ppf("%s:%d f:%d / t:%d (l:%d) B [%d %d]\n", __FUNCTION__, __LINE__, ESP.getFreeHeap(), ESP.getHeapSize(), ESP.getMaxAllocHeap(), esp_get_free_heap_size(), esp_get_free_internal_heap_size());

if (p.parseScript(&scScript))
{
ppf("parsing done\n");
ppf("parsing %s done\n", fileName);
ppf("%s:%d f:%d / t:%d (l:%d) B [%d %d]\n", __FUNCTION__, __LINE__, ESP.getFreeHeap(), ESP.getHeapSize(), ESP.getMaxAllocHeap(), esp_get_free_heap_size(), esp_get_free_internal_heap_size());

SCExecutable.executeAsTask("main"); //"setup" not working
// ppf("setup done\n");
strcpy(this->fileName, fileName);
// setupDone = true;
}
f.close();
}
Expand All @@ -309,7 +319,6 @@ class UserModLive:public SysModule {

void kill() {
ppf("kill %s\n", fileName);
// setupDone = false;
SCExecutable._kill(); //kill any old tasks
fps = 0;
strcpy(fileName, "");
Expand Down

0 comments on commit 0036269

Please sign in to comment.