Skip to content

Commit

Permalink
Add tekLive (😍) module
Browse files Browse the repository at this point in the history
pio.ini, main
- add live usermod

SysModFiles: seqNrToName: add filter

UserModLive: new module
  • Loading branch information
ewoudwijma committed Jun 28, 2024
1 parent 374d498 commit d01e949
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 12 deletions.
14 changes: 14 additions & 0 deletions data/helloworld1.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
external void show1();

void main()
{
int h=1;
while(h>0)
{
for(int i=0;i<10;i++)
{
}
show1();
h++;
}
}
14 changes: 14 additions & 0 deletions data/helloworld2.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
external void show2();

void main()
{
int h=1;
while(h>0)
{
for(int i=0;i<10;i++)
{
}
show2();
h++;
}
}
8 changes: 8 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ build_flags =
lib_deps =
ElectronicCats/MPU6050 @ 1.3.0

[STARBASE_USERMOD_LIVE]
build_flags =
-D STARBASE_USERMOD_LIVE
lib_deps =
https://github.com/hpwit/ASMParser.git


[STARBASE]
build_flags =
Expand All @@ -60,13 +66,15 @@ build_flags =
${STARBASE_USERMOD_E131.build_flags}
${STARBASE_USERMOD_MPU6050.build_flags}
; ${STARBASE_USERMOD_HA.build_flags}
${STARBASE_USERMOD_LIVE.build_flags}
lib_deps =
${ESPAsyncWebServer.lib_deps}
https://github.com/bblanchon/ArduinoJson.git#v7.0.3
; https://github.com/Jason2866/ESP32_Show_Info.git
${STARBASE_USERMOD_E131.lib_deps}
${STARBASE_USERMOD_MPU6050.lib_deps}
; ${STARBASE_USERMOD_HA.lib_deps}
${STARBASE_USERMOD_LIVE.lib_deps}



Expand Down
21 changes: 11 additions & 10 deletions src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,26 @@ void SysModFiles::dirToJson(JsonArray array, bool nameOnly, const char * filter)
root.close();
}

bool SysModFiles::seqNrToName(char * fileName, size_t seqNr) {
bool SysModFiles::seqNrToName(char * fileName, size_t seqNr, const char * filter) {

File root = LittleFS.open("/");
File file = root.openNextFile();

size_t counter = 0;
while (file) {
if (counter == seqNr) {
// ppf("seqNrToName: %d %s %d\n", seqNr, file.name(), file.size());
root.close();
strncat(fileName, "/", 31); //add root prefix, fileName is 32 bytes but sizeof doesn't know so cheating
strncat(fileName, file.name(), 31);
file.close();
return true;
if (filter == nullptr || strstr(file.name(), filter) != nullptr) {
if (counter == seqNr) {
// ppf("seqNrToName: %d %s %d\n", seqNr, file.name(), file.size());
root.close();
strncat(fileName, "/", 31); //add root prefix, fileName is 32 bytes but sizeof doesn't know so cheating
strncat(fileName, file.name(), 31);
file.close();
return true;
}
counter++;
}

file.close();
file = root.openNextFile();
counter++;
}

root.close();
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SysModFiles: public SysModule {
void dirToJson(JsonArray array, bool nameOnly = false, const char * filter = nullptr);

//get back the name of a file based on the sequence
bool seqNrToName(char * fileName, size_t seqNr);
bool seqNrToName(char * fileName, size_t seqNr, const char * filter = nullptr);

//reads file and load it in json
//name is copied from WLED but better to call it readJsonFrom file
Expand Down
125 changes: 125 additions & 0 deletions src/User/UserModLive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
@title StarBase
@file UserModLive.h
@date 20240411
@repo https://github.com/ewowi/StarBase, submit changes to this file as PRs to ewowi/StarBase
@Authors https://github.com/ewowi/StarBase/commits/main
@Copyright © 2024 Github StarBase Commit Authors
@license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
@license For non GPL-v3 usage, commercial licenses must be purchased. Contact [email protected]
*/

#include "parser.h"

long time1;
static float _min = 9999;
static float _max = 0;
static uint32_t _nb_stat = 0;
static float _totfps;

static void show1()
{
// SKIPPED: check nargs (must be 3 because arg[0] is self)
long time2 = ESP.getCycleCount();
// driver.showPixels(WAIT);

float k = (float)(time2 - time1) / 240000000;
float fps = 1 / k;
_nb_stat++;
if (_min > fps && fps > 10 && _nb_stat > 10)
_min = fps;
if (_max < fps && fps < 200 && _nb_stat > 10)
_max = fps;
if (_nb_stat > 10)
_totfps += fps;
ppf("current fps:%.2f average:%.2f min:%.2f max:%.2f\r\n", fps, _totfps / (_nb_stat - 10), _min, _max);
time1 = ESP.getCycleCount();

// SKIPPED: check that both v1 and v2 are int numbers
// RETURN_VALUE(VALUE_FROM_INT(0), rindex);
}

static void show2() {
ppf("show 2\n");
}

class UserModLive:public SysModule {

public:

Parser p = Parser();

UserModLive() :SysModule("Live") {
// isEnabled = false;
};

void setup() override {
SysModule::setup();

parentVar = ui->initUserMod(parentVar, name, 6310);

ui->initSelect(parentVar, "script", UINT16_MAX, false ,[this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onUI: {
// ui->setComment(var, "Fixture to display effect on");
JsonArray options = ui->setOptions(var);
options.add("None");
files->dirToJson(options, true, ".sc"); //only files containing F(ixture), alphabetically

return true; }
case onChange: {
//set script
uint8_t fileNr = var["value"];

if (fileNr > 0) {

fileNr--; //-1 as none is no file

char fileName[32] = "";

files->seqNrToName(fileName, fileNr, ".sc");

ppf("%s script f:%d f:%d\n", name, funType, fileNr);

if (strcmp(fileName, "") != 0) {

File f = files->open(fileName, "r");
if (!f)
ppf("UserModLive setup script open %s for %s failed", fileName, "r");
else {

string script = string(f.readString().c_str());

ppf("%s\n", script);

if (p.parse_c(&script))
{
SCExecutable.execute("main");
}
f.close();
}

}
else
ppf("UserModLive setup file for %d not found", fileNr);
}
return true; }
default: return false;
}}); //fixture

addExternal("show1", externalType::function, (void *)&show1);
addExternal("show2", externalType::function, (void *)&show2);

// addExternal("test", externalType::function, (void *)&test); //compile error ...

}

void test() {
ppf("hello test world\n");
}

};

extern UserModLive *live;


//asm_parser.h:325:1: warning: control reaches end of non-void function
12 changes: 11 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ AppModDemo *appModDemo;
#include "User/UserModMPU6050.h"
UserModMPU6050 *mpu6050;
#endif
#ifdef STARBASE_USERMOD_LIVE
#include "User/UserModLive.h"
UserModLive *live;
#endif

//setup all modules
void setup() {
Expand All @@ -73,9 +77,12 @@ void setup() {
#ifdef STARBASE_USERMOD_MPU6050
mpu6050 = new UserModMPU6050();
#endif
#ifdef STARBASE_USERMOD_LIVE
live = new UserModLive();
#endif

//Reorder with care! this is the order in which setup and loop is executed
//If changed make sure mdlEnabled.chFun executes var["value"].to<JsonArray>(); and saveModel!
//If changed make sure mdlEnabled.onChange executes var["value"].to<JsonArray>(); and saveModel!
//Default: add below, not in between

mdls->add(appModDemo);
Expand All @@ -95,6 +102,9 @@ void setup() {
#ifdef STARBASE_USERMOD_MPU6050
mdls->add(mpu6050);
#endif
#ifdef STARBASE_USERMOD_LIVE
mdls->add(live);
#endif
mdls->add(mdl);
mdls->add(ui);
mdls->add(mdns); //no ui
Expand Down

0 comments on commit d01e949

Please sign in to comment.