Skip to content

Commit

Permalink
change static to extern -> remove class static, setup workflow actions
Browse files Browse the repository at this point in the history
General:
- replace static <Module> *<mdl> with extern
- remove 'all' class static variables (except SysModWeb - todo)
- replace all <Module>:: with mdl->

main.cpp:
- implement all extern <Module>

SysModSystem
- replace serverName with instanceName

SysModWorkflow
  • Loading branch information
ewowi committed Mar 28, 2024
1 parent 93bbbc5 commit 8daea1c
Show file tree
Hide file tree
Showing 35 changed files with 1,085 additions and 1,072 deletions.
2 changes: 1 addition & 1 deletion data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1 style="float: left;">StarMod💫 LEDs 🎨 by MoonModules 🌔</h1>
<a href="https://ewowi.github.io/StarDocs" style="float: right;"></a>
</hgroup>
<br>
<h2><div id="instanceName"></div></h2>
<h2><div id="serverName"></div></h2>
<input type="button" value="App" id="vApp" onclick="setView(this)">
<input type="button" value="DashBoard" id="vDash" onclick="setView(this)">
<input type="button" value="User" id="vUser" onclick="setView(this)">
Expand Down
6 changes: 3 additions & 3 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,9 @@ function changeHTML(variable, commandJson, rowNr = UINT8_MAX) {
node.dispatchEvent(new Event("input")); // triggers addEventListener('input',...). now only used for input type range (slider), needed e.g. for qlc+ input
}

//'hack' show the serverName on top of the page
if (variable.id == "serverName") {
gId("instanceName").innerText = commandJson.value;
//'hack' show the instanceName on top of the page
if (variable.id == "instanceName") {
gId("serverName").innerText = commandJson.value;
document.title = commandJson.value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion data/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
"max": 255,
"n": [
{
"id": "serverName",
"id": "instanceName",
"type": "text",
"ro": false,
"o": 42,
Expand Down
11 changes: 7 additions & 4 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ class LedModEffects:public SysModule {
strcat(buf, effect->tags());
options.add(JsonString(buf, JsonString::Copied)); //copy!
}
return true;
}
return true; }
case f_ChangeFun:

if (rowNr == UINT8_MAX) rowNr = 0; // in case fx without a rowNr
Expand All @@ -107,6 +106,10 @@ class LedModEffects:public SysModule {
}
if (rowNr < fixture.projections.size())
effects.setEffect(*fixture.projections[rowNr], var, rowNr);

USER_PRINTF("fx wfl %u\n", wfl);
if (wfl)
wfl->addAction("Choose effect", "Effects");
return true;
default: return false;
}});
Expand Down Expand Up @@ -286,7 +289,7 @@ class LedModEffects:public SysModule {
stackUnsigned8 rowNr = 0;
for (Leds *leds: fixture.projections) {
char message[32];
print->fFormat(message, sizeof(message)-1, "%d x %d x %d = %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds);
print->fFormat(message, sizeof(message)-1, "%d x %d x %d -> %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds);
USER_PRINTF("valueFun fxSize[%d](of %d) = %s\n", rowNr, fixture.projections.size(), message);
mdl->setValue(var, JsonString(message, JsonString::Copied), rowNr); //rowNr
rowNr++;
Expand Down Expand Up @@ -671,4 +674,4 @@ class LedModEffects:public SysModule {

};

static LedModEffects *eff;
extern LedModEffects *eff;
10 changes: 6 additions & 4 deletions src/App/LedModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ class LedModFixture:public SysModule {
ui->callVarFun("bri", UINT8_MAX, f_ChangeFun); //set FastLed brightness

//WIP!!!
wf->addAction("Define fixture", "FixtureGen");
wf->addAction("Save model", "Model");
USER_PRINTF("on wfl %u\n", wfl);
if (!var["value"].as<bool>() && wfl) {
wfl->addAction("Set on", "Fixture");
}

return true;
default: return false;
Expand All @@ -46,7 +48,7 @@ class LedModFixture:public SysModule {
case f_ChangeFun: {
stackUnsigned8 bri = var["value"];

stackUnsigned8 result = mdl->getValue("on").as<bool>()?linearToLogarithm(var, bri):0;
stackUnsigned8 result = mdl->getValue("on").as<bool>()?mdl->varLinearToLogarithm(var, bri):0;

FastLED.setBrightness(result);

Expand Down Expand Up @@ -208,4 +210,4 @@ class LedModFixture:public SysModule {
}
};

static LedModFixture *fix;
extern LedModFixture *fix;
2 changes: 1 addition & 1 deletion src/App/LedModFixtureGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1062,4 +1062,4 @@ class LedModFixtureGen:public SysModule {

};

static LedModFixtureGen *lfg;
extern LedModFixtureGen *lfg;
9 changes: 5 additions & 4 deletions src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

// #include <FS.h>

bool SysModFiles::filesChanged = true; //init fileTbl

SysModFiles::SysModFiles() :SysModule("Files") {
if (!LittleFS.begin(true)) { //true: formatOnFail
USER_PRINTF(" An Error has occurred while mounting File system");
Expand Down Expand Up @@ -134,8 +132,11 @@ void SysModFiles::loop() {
}
root.close();

// wf->addAction("Define fixture", "FixtureGen");
// wf->addAction("Save model", "Model");
USER_PRINTF("filesChanged wfl %u, %u, %u\n", wfl, ui, web);
if (wfl) {
wfl->addAction("Define fixture", "FixtureGen"); // if no F_*.json found
wfl->addAction("Save model", "Model"); // if model.json not found
}

ui->callVarFun(mdl->findVar("drsize")); //valueFun

Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SysModFiles: public SysModule {
public:

std::vector<FileDetails> fileList;
static bool filesChanged;
bool filesChanged = true; //init fileTbl;

SysModFiles();
void setup();
Expand Down Expand Up @@ -61,4 +61,4 @@ class SysModFiles: public SysModule {

};

static SysModFiles *files;
extern SysModFiles *files;
6 changes: 0 additions & 6 deletions src/Sys/SysModModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
#include "SysStarModJson.h"
#include "SysModUI.h"

JsonDocument * SysModModel::model = nullptr;
JsonObject SysModModel::modelParentVar;
unsigned8 SysModModel::setValueRowNr = UINT8_MAX;
unsigned8 SysModModel::getValueRowNr = UINT8_MAX;
int SysModModel::varCounter = 1; //start with 1 so it can be negative, see var["o"]

SysModModel::SysModModel() :SysModule("Model") {
model = new JsonDocument(&allocator);

Expand Down
35 changes: 25 additions & 10 deletions src/Sys/SysModModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,15 @@ class SysModModel:public SysModule {

public:

// StaticJsonDocument<24576> model; //not static as that blows up the stack. Use extern??
// static JsonDocument<DefaultAllocator> *model; //needs to be static as loopTask and asyncTask is using it...
RAM_Allocator allocator;
static JsonDocument *model; //needs to be static as loopTask and asyncTask is using it...
JsonDocument *model = nullptr;

static JsonObject modelParentVar;
JsonObject modelParentVar;

bool doWriteModel = false;

static unsigned8 setValueRowNr;
static unsigned8 getValueRowNr;
unsigned8 setValueRowNr = UINT8_MAX;
unsigned8 getValueRowNr = UINT8_MAX;

SysModModel();
void setup();
Expand Down Expand Up @@ -320,14 +318,14 @@ class SysModModel:public SysModule {
}

//returns the var defined by id (parent to recursively call findVar)
static JsonObject findVar(const char * id, JsonArray parent = JsonArray()); //static for processJson
JsonObject findVar(const char * id, JsonArray parent = JsonArray());
void findVars(const char * id, bool value, FindFun fun, JsonArray parent = JsonArray());

//recursively add values in a variant
void varToValues(JsonObject var, JsonArray values);

//run the change function and send response to all? websocket clients
static void callChangeFun(JsonObject var, unsigned8 rowNr = UINT8_MAX);
void callChangeFun(JsonObject var, unsigned8 rowNr = UINT8_MAX);

//pseudo VarObject: public JsonObject functions
const char * varID(JsonObject var) {return var["id"];}
Expand Down Expand Up @@ -428,11 +426,28 @@ class SysModModel:public SysModule {
web->addResponse("details", "var", var);
}

unsigned8 varLinearToLogarithm(JsonObject var, unsigned8 value) {
if (value == 0) return 0;

float minp = var["min"].isNull()?var["min"]:0;
float maxp = var["max"].isNull()?var["max"]:255;

// The result should be between 100 an 10000000
float minv = minp?log(minp):0;
float maxv = log(maxp);

// calculate adjustment factor
float scale = (maxv-minv) / (maxp-minp);

return round(exp(minv + scale*((float)value-minp)));
}


private:
bool doShowObsolete = false;
bool cleanUpModelDone = false;
static int varCounter; //not static crashes ??? (not called async...?)
int varCounter = 1; //start with 1 so it can be negative, see var["o"]

};

static SysModModel *mdl;
extern SysModModel *mdl;
19 changes: 10 additions & 9 deletions src/Sys/SysModNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ void SysModNetwork::setup() {
// ui->setComment(var, "List of defined and available Wifi APs");
// });

ui->initText(parentVar, "ssid", "", 32, false);
// , nullptr
// , nullptr, nullptr, 1, [this](JsonObject var, unsigned8 rowNr) { //valueFun
// var["value"][0] = "";
// });
ui->initText(parentVar, "ssid", "", 32, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ChangeFun:
USER_PRINTF("ssid wfl %u\n", wfl);
if (wfl)
wfl->addAction("Enter ssid", "Network");
return true;
default: return false;
}});

ui->initPassword(parentVar, "pw", "", 32, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
Expand Down Expand Up @@ -67,8 +70,6 @@ void SysModNetwork::setup() {
return true;
default: return false;
}});

// wf->addAction("Enter credentials", "Network");
}

void SysModNetwork::loop() {
Expand Down Expand Up @@ -113,7 +114,7 @@ void SysModNetwork::handleConnection() {

interfacesInited = true;

SysModules::newConnection = true; // send all modules connect notification
mdls->newConnection = true; // send all modules connect notification

// shut down AP
if (apActive) { //apBehavior != AP_BEHAVIOR_ALWAYS
Expand Down Expand Up @@ -170,6 +171,6 @@ void SysModNetwork::initAP() {
dnsServer.start(53, "*", WiFi.softAPIP());
apActive = true;

SysModules::newConnection = true; // send all modules connect notification
mdls->newConnection = true; // send all modules connect notification
}
}
2 changes: 1 addition & 1 deletion src/Sys/SysModNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ class SysModNetwork:public SysModule {
bool forceReconnect = false;
};

static SysModNetwork *net;
extern SysModNetwork *net;
3 changes: 0 additions & 3 deletions src/Sys/SysModPins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
#include "SysModUI.h"
#include "SysModWeb.h"

PinObject SysModPins::pinObjects[NUM_DIGITAL_PINS];
bool SysModPins::pinsChanged = false;

SysModPins::SysModPins() :SysModule("Pins") {
#if CONFIG_IDF_TARGET_ESP32
// softhack007: configuring these pins on S3/C3/S2 may cause major problems (crashes included)
Expand Down
7 changes: 3 additions & 4 deletions src/Sys/SysModPins.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SysModPins:public SysModule {

public:

static PinObject pinObjects[NUM_DIGITAL_PINS]; //all pins
PinObject pinObjects[NUM_DIGITAL_PINS]; //all pins

SysModPins();
void setup();
Expand Down Expand Up @@ -71,8 +71,7 @@ class SysModPins:public SysModule {

static bool updateGPIO(JsonObject var, unsigned8 rowNr, unsigned8 funType);

static bool pinsChanged; //update pins table if pins changed
private:
bool pinsChanged = false; //update pins table if pins changed
};

static SysModPins *pins;
extern SysModPins *pins;
2 changes: 1 addition & 1 deletion src/Sys/SysModPrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ class SysModPrint:public SysModule {
bool setupsDone = false;
};

static SysModPrint *print;
extern SysModPrint *print;
8 changes: 7 additions & 1 deletion src/Sys/SysModSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "SysModWeb.h"
#include "SysModModel.h"
#include "esp32Tools.h"
#include "SysModWorkFlow.h"

// #include <Esp.h>
#include <rom/rtc.h>
Expand All @@ -25,11 +26,16 @@ void SysModSystem::setup() {
SysModule::setup();
parentVar = ui->initSysMod(parentVar, name, 2000);

ui->initText(parentVar, "serverName", "StarMod", 32, false, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
ui->initText(parentVar, "instanceName", "StarMod", 32, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "Name");
ui->setComment(var, "Instance name");
return true;
case f_ChangeFun:
USER_PRINTF("instanceName wfl %u\n", wfl);
if (wfl) //var["value"] == "StarMod" &&
wfl->addAction("Instance name", "System");
return true;
default: return false;
}});

Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class SysModSystem:public SysModule {

};

static SysModSystem *sys;
extern SysModSystem *sys;
9 changes: 2 additions & 7 deletions src/Sys/SysModUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
#include "SysModWeb.h"
#include "SysModModel.h"

//init static variables (https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm)
std::vector<VarFun> SysModUI::varFunctions;
std::vector<VarLoop> SysModUI::loopFunctions;
bool SysModUI::dashVarChanged = false;

SysModUI::SysModUI() :SysModule("UI") {
};

Expand All @@ -35,7 +30,7 @@ void SysModUI::setup() {
default: return false;
}});

initText(tableVar, "vlVar", nullptr, 32, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
initText(tableVar, "vlVar", nullptr, 32, true, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
for (forUnsigned8 rowNr = 0; rowNr < loopFunctions.size(); rowNr++)
mdl->setValue(var, JsonString(loopFunctions[rowNr].var["id"], JsonString::Copied), rowNr);
Expand All @@ -46,7 +41,7 @@ void SysModUI::setup() {
default: return false;
}});

initNumber(tableVar, "vlLoopps", UINT16_MAX, 0, 999, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
initNumber(tableVar, "vlLoopps", UINT16_MAX, 0, 999, true, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
for (forUnsigned8 rowNr = 0; rowNr < loopFunctions.size(); rowNr++)
mdl->setValue(var, loopFunctions[rowNr].counter, rowNr);
Expand Down
Loading

0 comments on commit 8daea1c

Please sign in to comment.