From 00362695650efae03adc9cb9285caa525fc117d5 Mon Sep 17 00:00:00 2001 From: Ewoud Date: Fri, 9 Aug 2024 12:26:25 +0200 Subject: [PATCH] UserModLive: sync live script with main loop (smooth on real leds) 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 --- misc/animwleSL.sc | 2 +- misc/green_ripple_reflectionsSL.sc | 2 +- platformio.ini | 9 ++++---- src/User/UserModLive.h | 35 +++++++++++++++++++----------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/misc/animwleSL.sc b/misc/animwleSL.sc index 6421500c..6c0cb5e2 100644 --- a/misc/animwleSL.sc +++ b/misc/animwleSL.sc @@ -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 diff --git a/misc/green_ripple_reflectionsSL.sc b/misc/green_ripple_reflectionsSL.sc index 5fec1d7a..4d3a499a 100644 --- a/misc/green_ripple_reflectionsSL.sc +++ b/misc/green_ripple_reflectionsSL.sc @@ -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); } } } diff --git a/platformio.ini b/platformio.ini index 82b799d6..f3b09454 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 = @@ -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 @@ -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 diff --git a/src/User/UserModLive.h b/src/User/UserModLive.h index f99bd32b..3ffed7e6 100644 --- a/src/User/UserModLive.h +++ b/src/User/UserModLive.h @@ -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) @@ -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() @@ -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 @@ -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() { @@ -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(); } @@ -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, "");