Skip to content

Commit

Permalink
Live script: loopState + create and delete file triggers
Browse files Browse the repository at this point in the history
SysModFiles: FilesTbl.onDelete: trigger Live scripts to delete file

SysModWeb: serveUpload: trigger Live scripts to run file

UserModLive:
- add loopState and use in loop()
- add functions triangle, time, sliders, millis
- script.onChange set lastFileUpdated instead of run
- loop20ms: kill if lastFileUpdated contains from onDelete
- run: force by default
- script: add main code to file
  • Loading branch information
ewoudwijma committed Aug 19, 2024
1 parent 0886757 commit bef8479
Show file tree
Hide file tree
Showing 11 changed files with 646 additions and 627 deletions.
2 changes: 1 addition & 1 deletion data/newui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class Controller {

// console.log("requestJson", command);

this.ws.send(req);
this.ws.send(req);
}
}

Expand Down
9 changes: 7 additions & 2 deletions data/newui/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Modules {
}

//used by fetchModel and by makeWS
addModule(moduleJson) {
addModule(moduleJson) {
moduleJson.type = moduleJson.type=="appmod"?appName():moduleJson.type=="usermod"?"User":"System";
this.model.push(moduleJson);

Expand Down Expand Up @@ -407,12 +407,17 @@ class CanvasVariable extends Variable {
// console.log(this.variable)
if (this.variable.file) {
this.variable.file.new = true;
console.log("canvas createHTML", this.variable.file, this.variable.file.new);
// console.log("canvas createHTML", this.variable.file, this.variable.file.new);
}
return super.createHTML(`<canvas id=${this.variable.id} class="${this.variable.type}"></canvas>`);
}

receiveData(properties) {
super.receiveData(properties)
}

generateData() {
//tbd: this is StarLight, remove here...
if (this.node && this.variable.file == null)
super.generateData(`"file":"F_panel2x2-16x16.json"`)

Expand Down
12 changes: 2 additions & 10 deletions misc/blink.sc → misc/LiveScripts/blinkSL.sc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//blinkSL.sc

//externals generated

//how to deal with external defines?
Expand All @@ -21,13 +23,3 @@ void loop() {
digitalWrite(blinkPin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

void main()
{
setup();
while (0==0)
{
loop();
show();
}
}
15 changes: 0 additions & 15 deletions misc/showtest1.sc

This file was deleted.

15 changes: 0 additions & 15 deletions misc/showtest2.sc

This file was deleted.

11 changes: 7 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ lib_deps =
[env:lolin_s2_mini]
board = lolin_s2_mini ;https://github.com/platformio/platform-espressif32/blob/develop/boards/lolin_s2_mini.json
; platform = [email protected] ; WLED default framework version
platform = [email protected] ; this one behaves better for debugging
platform = [email protected] ; this one behaves better for debugging 6.5.0 is latest
upload_speed = 256000
build_flags =
${env.build_flags}
-mtext-section-literals ;otherwise [UserModLive::setup()]+0xa17): dangerous relocation: l32r: literal target out of range (try using text-section-literals)
; -DARDUINO_ARCH_ESP32 ; no proof of necessity yet...
-D CONFIG_IDF_TARGET_ESP32S2=1
-D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_DFU_ON_BOOT=1 -D ARDUINO_USB_MSC_ON_BOOT=0 ; for debugging over USB
Expand All @@ -185,6 +186,8 @@ build_flags =
lib_deps =
${env.lib_deps}

; using framework-arduinoespressif32 @ 3.20009.0 (2.0.9)

; attention! : manual action needed to select CLedDriver
; uncomment last 4 lines in the env description
; comment the following lines in the CLD-S3 repo (workaround), otherwise compile error:
Expand All @@ -194,7 +197,7 @@ lib_deps =
; [env:lolin_c3_mini]
; board = lolin_c3_mini ;https://github.com/platformio/platform-espressif32/blob/develop/boards/lolin_c3_mini.json
; ; platform = [email protected] ; WLED default framework version
; platform = [email protected] ; this one behaves better for debugging
; platform = [email protected] ; this one behaves better for debugging 6.5.0 is latest
; upload_speed = 256000
; build_unflags =
; ${env.build_unflags}
Expand All @@ -216,7 +219,7 @@ lib_deps =
; for Waveshare ESP32-S3 Mini/Zero https://www.waveshare.com/esp32-s3-zero.htm
; --> 4MB Flash, has PSRAM, memory type "qio_qspi", USB-CDC only
[env:lolin_s3_mini]
platform = [email protected] ; this one behaves better for debugging
platform = [email protected] ; this one behaves better for debugging 6.5.0 is latest
board = lolin_s3_mini ;https://github.com/platformio/platform-espressif32/blob/develop/boards/lolin_s3_mini.json
build_flags =
${env.build_flags}
Expand Down Expand Up @@ -249,7 +252,7 @@ lib_deps =
; https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html
; https://github.com/platformio/platform-espressif32/blob/develop/boards/esp32-s3-devkitc-1.json
[env:esp32-s3-devkitc-1-n16r8v]
platform = espressif32 ;default is Espressif 32 (6.5.0)
platform = espressif32@6.5.0 ;default is Espressif 32 (6.5.0)
; WLEDMM: espressif32@ ~6.3.2
; TroyHacks: platformio/espressif32@^6.7.0
; platform_packages ;default is framework-arduinoespressif32 @ 3.20014.231204 (2.0.14)
Expand Down
11 changes: 10 additions & 1 deletion src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,23 @@ void SysModFiles::setup() {
rowNr = fileList.size();
web->getResponseObject()["addRow"]["rowNr"] = rowNr;
//add a row with all defaults
//tbd: File upload does not call onAddRow (bug?)
return true;
case onDeleteRow:
if (rowNr != UINT8_MAX && rowNr < fileList.size()) {
const char * fileName = fileList[rowNr].name;
// ppf("fileTbl delRow %s[%d] = %s %s\n", mdl->varID(var), rowNr, var["value"].as<String>().c_str(), fileName);
this->removeFiles(fileName, false);

#ifdef STARBASE_USERMOD_LIVE
if (strstr(fileName, ".sc") != nullptr) {
char name[32]="del:/"; //del:/ is recognized by LiveM->loop20ms
strcat(name, fileName);
ppf("sc file removed %s\n", name);
strcpy(web->lastFileUpdated, name);
}
#endif

// print->printVar(var);
// ppf("\n");
}
Expand Down Expand Up @@ -227,7 +237,6 @@ bool SysModFiles::seqNrToName(char * fileName, size_t seqNr, const char * filter
}
counter++;
}

file.close();
file = root.openNextFile();
}
Expand Down
19 changes: 11 additions & 8 deletions src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ void SysModWeb::connectedChanged() {

server.addHandler(new AsyncCallbackJsonWebHandler("/json", [this](WebRequest *request, JsonVariant &json){jsonHandler(request, json);}));

server.on("/update", HTTP_POST, [](WebRequest *) {}, [this](WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final) {serveUpdate(request, filename, index, data, len, final);});
server.on("/update", HTTP_POST, [](WebRequest *) {}, [this](WebRequest *request, const String& fileName, size_t index, byte *data, size_t len, bool final) {serveUpdate(request, fileName, index, data, len, final);});
server.on("/file", HTTP_GET, [this](WebRequest *request) {serveFiles(request);});
server.on("/upload", HTTP_POST, [](WebRequest *) {}, [this](WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final) {serveUpload(request, filename, index, data, len, final);});
server.on("/upload", HTTP_POST, [](WebRequest *) {}, [this](WebRequest *request, const String& fileName, size_t index, byte *data, size_t len, bool final) {serveUpload(request, fileName, index, data, len, final);});

server.onNotFound([this](AsyncWebServerRequest *request) {
ppf("Not-Found HTTP call: URI: %s\n", request->url().c_str()); ///hotspot-detect.html
Expand Down Expand Up @@ -491,16 +491,16 @@ void SysModWeb::serveNewUI(WebRequest *request) {
ppf("!\n");
}

void SysModWeb::serveUpload(WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final) {
void SysModWeb::serveUpload(WebRequest *request, const String& fileName, size_t index, byte *data, size_t len, bool final) {

// curl -F '[email protected]' 192.168.8.213/upload
ppf("serveUpload r:%s f:%s i:%d l:%d f:%d\n", request->url().c_str(), filename.c_str(), index, len, final);
ppf("serveUpload r:%s f:%s i:%d l:%d f:%d\n", request->url().c_str(), fileName.c_str(), index, len, final);

mdl->setValue("upload", index/10000);
sendResponseObject(); //otherwise not send in asyn_tcp thread

if (!index) {
String finalname = filename;
String finalname = fileName;
if (finalname.charAt(0) != '/') {
finalname = '/' + finalname; // prepend slash if missing
}
Expand All @@ -526,7 +526,10 @@ void SysModWeb::serveUpload(WebRequest *request, const String& filename, size_t
//if sc files send command to live
#ifdef STARBASE_USERMOD_LIVE

strcpy(lastFileUpdated, filename.c_str()); //workaround
if (fileName.indexOf(".sc") > 0) {
ppf("sc file added %s\n", fileName.c_str());
strcpy(lastFileUpdated, ("/"+fileName).c_str()); //workaround
}

// got multiple definition error here ???
// if (filename.indexOf(".sc") > 0)
Expand All @@ -535,10 +538,10 @@ void SysModWeb::serveUpload(WebRequest *request, const String& filename, size_t
}
}

void SysModWeb::serveUpdate(WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final) {
void SysModWeb::serveUpdate(WebRequest *request, const String& fileName, size_t index, byte *data, size_t len, bool final) {

// curl -F '[email protected]' 192.168.8.213/upload
// ppf("serveUpdate r:%s f:%s i:%d l:%d f:%d\n", request->url().c_str(), filename.c_str(), index, len, final);
// ppf("serveUpdate r:%s f:%s i:%d l:%d f:%d\n", request->url().c_str(), fileName.c_str(), index, len, final);

mdl->setValue("update", index/10000);
sendResponseObject(); //otherwise not send in asyn_tcp thread
Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModWeb.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ class SysModWeb:public SysModule {


// curl -F '[email protected]' 192.168.8.213/upload
void serveUpload(WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final);
void serveUpload(WebRequest *request, const String& fileName, size_t index, byte *data, size_t len, bool final);
// curl -s -F "update=@/Users/ewoudwijma/Developer/GitHub/ewowi/StarBase/.pio/build/esp32dev/firmware.bin" 192.168.8.102/update /dev/null &
void serveUpdate(WebRequest *request, const String& filename, size_t index, byte *data, size_t len, bool final);
void serveUpdate(WebRequest *request, const String& fileName, size_t index, byte *data, size_t len, bool final);
void serveFiles(WebRequest *request);

//processJsonUrl handles requests send in javascript using fetch and from a browser or curl
Expand Down
Loading

0 comments on commit bef8479

Please sign in to comment.