Skip to content

Commit

Permalink
Instance module: full instance sync!
Browse files Browse the repository at this point in the history
index.js
- generateHTML: better support for tables
- processUpdate: support for updrow (of table)
- processVarNode: no comment on th
- processVarNode: select th: propagate select options
- showHideModules improvements

AppModLeds
- projection: add x,y,z (WIP)
- set FastLed max power to 2 A (WIP, temp)

SysModPins
- add pin 19 checkbox (for relay on serg shield)

SysModUI
- add stageVarChanged
- chFun: add stageVarChanged

main
- instances last so all stage vars are initiated

SysModule and SysModules
- add one and ten secondMillis to each module (WIP)

UserModInstances
- rename dch, dun and sma (3 letters, stage vars)
- add addTblRow (wip)
- use initVar for simplified stage var handling
- updateNode: send updrow command instead of recreate table
  • Loading branch information
ewowi committed Nov 30, 2023
1 parent dff4d67 commit 8de5957
Show file tree
Hide file tree
Showing 18 changed files with 1,528 additions and 1,434 deletions.
2 changes: 1 addition & 1 deletion data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<h1>StarMod by MoonModules 💫 <div id="instanceName"></div></h1>
<input type="button" value="App" id="vApp" onclick="showHideModules(this)">
<input type="button" value="Stage" id="vStage" onclick="showHideModules(this)">
<input type="button" value="User" id="vUser" onclick="showHideModules(this)">
<!-- <input type="button" value="User" id="vUser" onclick="showHideModules(this)"> -->
<input type="button" value="System" id="vSys" onclick="showHideModules(this)">
<input type="button" value="All" id="vAll" onclick="showHideModules(this)">
<div id="instPH"></div>
Expand Down
387 changes: 213 additions & 174 deletions data/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions data/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"max": 10
},
{
"id": "dmxChannel",
"id": "dch",
"type": "number",
"ro": false,
"o": 87,
Expand Down Expand Up @@ -330,7 +330,7 @@
]
},
{
"id": "syncMaster",
"id": "sma",
"type": "number",
"ro": false,
"o": 44,
Expand Down Expand Up @@ -776,7 +776,7 @@
"o": 85,
"n": [
{
"id": "dmxUni",
"id": "dun",
"type": "number",
"ro": false,
"o": 86,
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppLedsV.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <vector>
#include "ArduinoJson.h"

#define NUM_LEDS_Preview 8192
#define NUM_LEDS_Preview 4096

enum Projections
{
Expand Down
22 changes: 15 additions & 7 deletions src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class AppModLeds:public SysModule {

currentVar = ui->initCheckBox(parentVar, "on", true, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "On/Off");
}, [](JsonObject var, uint8_t) { //chFun
ui->valChangedForInstancesTemp = true;
});
currentVar["stage"] = true;

Expand All @@ -68,7 +66,6 @@ class AppModLeds:public SysModule {
FastLED.setBrightness(result);

USER_PRINTF("Set Brightness to %d -> b:%d r:%d\n", var["value"].as<int>(), bri, result);
ui->valChangedForInstancesTemp = true;
});
currentVar["log"] = true; //logarithmic
currentVar["stage"] = true; //these values override model.json???
Expand Down Expand Up @@ -103,7 +100,6 @@ class AppModLeds:public SysModule {
USER_PRINTF("%s Change %s to %d\n", "initSelect chFun", var["id"].as<const char *>(), fx);

doMap = effects.setEffect("fx", fx);
ui->valChangedForInstancesTemp = true;
});
currentVar["stage"] = true;

Expand Down Expand Up @@ -131,7 +127,6 @@ class AppModLeds:public SysModule {
case 7: palette = HeatColors_p; break;
default: palette = PartyColors_p; break;
}
ui->valChangedForInstancesTemp = true;
});
currentVar["stage"] = true;

Expand All @@ -153,7 +148,18 @@ class AppModLeds:public SysModule {

ledsV.projectionNr = var["value"];
doMap = true;
ui->valChangedForInstancesTemp = true;

JsonObject parentVar = var;
parentVar.remove("n"); //tbd: we should also remove the uiFun and chFun !!

if (ledsV.projectionNr == 2) {
ui->initSlider(parentVar, "pointX", 128);
ui->initSlider(parentVar, "pointY", 128);
ui->initSlider(parentVar, "pointZ", 128);
}

web->sendDataWs(parentVar); //always send, also when no children, to remove them from ui

});
currentVar["stage"] = true;

Expand Down Expand Up @@ -219,7 +225,7 @@ class AppModLeds:public SysModule {
// e131mod->patchChannel(3, "pro", Projections::count);
// e131mod->patchChannel(4, "fixture", 5); //assuming 5!!!

ui->valChangedForInstancesTemp = true;
// ui->stageVarChanged = true;

// }
// else
Expand All @@ -228,6 +234,8 @@ class AppModLeds:public SysModule {

effects.setup();

FastLED.setMaxPowerInVoltsAndMilliamps(5,2000); // 5v, 2000mA

USER_PRINT_FUNCTION("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed");
}

Expand Down
19 changes: 18 additions & 1 deletion src/Sys/SysModModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,24 @@ JsonObject SysModModel::setValueC(const char * id, const char * value, uint8_t r
}
}
} else {
USER_PRINTF("setValueC Var %s (%s) table row nr not implemented yet %d\n", id, value, rowNr);
//if we deal with multiple rows, value should be an array, if not we create one

if (var["value"].isNull() || !var["value"].is<JsonArray>()) {
USER_PRINTF("setValueC var %s (%d) value %s not array, creating\n", id, rowNr, var["value"].as<String>().c_str());
// print->printJson("setValueB var %s value %s not array, creating", id, var["value"].as<String>().c_str());
var.createNestedArray("value");
}

if (var["value"].is<JsonArray>()) {
//set the right value in the array (if array did not contain values yet, all values before rownr are set to false)
if (var["value"][rowNr] != value) {
var["value"][rowNr] = (char *)value; //create a copy
ui->setChFunAndWs(var, rowNr);
}
}
else
USER_PRINTF("setValueI %s could not create value array\n", id);
// USER_PRINTF("setValueC Var %s (%s) table row nr not implemented yet %d\n", id, value, rowNr);
}
}
else
Expand Down
5 changes: 4 additions & 1 deletion src/Sys/SysModPins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SysModPins::SysModPins() :SysModule("Pins") {

pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(19, OUTPUT);
pinMode(33, OUTPUT);

//start with no pins allocated
Expand Down Expand Up @@ -82,6 +83,7 @@ void SysModPins::setup() {

// ui->initCheckBox(parentVar, "pin2", true, false, nullptr, updateGPIO);
// ui->initCheckBox(parentVar, "pin4");
ui->initCheckBox(parentVar, "pin19", true, false, nullptr, updateGPIO);
// ui->initCheckBox(parentVar, "pin33", true);

USER_PRINT_FUNCTION("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed");
Expand All @@ -95,7 +97,7 @@ void SysModPins::loop1s() {
}
}

void SysModPins::updateGPIO(JsonObject var) {
void SysModPins::updateGPIO(JsonObject var, size_t index) {
if (var["value"].is<bool>()) {
bool pinValue = var["value"];
JsonString id = var["id"];
Expand All @@ -104,6 +106,7 @@ void SysModPins::updateGPIO(JsonObject var) {

if (id == "pin2") digitalWrite(2, pinValue?HIGH:LOW);
if (id == "pin4") digitalWrite(4, pinValue?HIGH:LOW);
if (id == "pin19") digitalWrite(19, pinValue?HIGH:LOW);
if (id == "pin33") digitalWrite(33, pinValue?HIGH:LOW);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModPins.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SysModPins:public SysModule {
void allocatePin(uint8_t pinNr, const char * owner, const char * details);
void deallocatePin(uint8_t pinNr, const char * owner);

void updateGPIO(JsonObject var);
static void updateGPIO(JsonObject var, size_t index);

private:
static bool pinsChanged; //update pins table if pins changed
Expand Down
11 changes: 7 additions & 4 deletions src/Sys/SysModUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ std::vector<UFun> SysModUI::uFunctions;
std::vector<CFun> SysModUI::cFunctions;
std::vector<VarLoop> SysModUI::loopFunctions;
int SysModUI::varCounter = 1; //start with 1 so it can be negative, see var["o"]
bool SysModUI::varLoopsChanged = false;;
bool SysModUI::varLoopsChanged = false;
bool SysModUI::stageVarChanged = false;

SysModUI::SysModUI() :SysModule("UI") {
USER_PRINT_FUNCTION("%s %s\n", __PRETTY_FUNCTION__, name);
Expand Down Expand Up @@ -229,6 +230,9 @@ void SysModUI::setChFunAndWs(JsonObject var, uint8_t rowNr, const char * value)
USER_PRINTF("setChFunAndWs function nr %s outside bounds %d >= %d\n", var["id"].as<const char *>(), funNr, cFunctions.size());
}

if (var["stage"])
stageVarChanged = true;

JsonDocument *responseDoc = web->getResponseDoc();
responseDoc->clear(); //needed for deserializeJson?
JsonVariant responseVariant = responseDoc->as<JsonVariant>();
Expand Down Expand Up @@ -265,11 +269,10 @@ const char * SysModUI::processJson(JsonVariant &json) {

// commands
if (pair.key() == "v") {
// do nothing as it is no real var bu the verbose command of WLED
// do nothing as it is no real var but the verbose command of WLED
USER_PRINTF("processJson v type %s\n", pair.value().as<String>());
}
else if (pair.key() == "view") {
// do nothing as it is no real var bu the verbose command of WLED
else if (pair.key() == "view") { //save the chosen view in System (see index.js)
JsonObject var = mdl->findVar("System");
USER_PRINTF("processJson view v:%s n: %d s:%s\n", pair.value().as<String>(), var.isNull(), var["id"].as<const char *>());
var["view"] = (char *)value.as<const char *>(); //create a copy!
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static uint8_t linearToLogarithm(JsonObject var, uint8_t value) {
class SysModUI:public SysModule {

public:
bool valChangedForInstancesTemp = false; //tbd: move mechanism to UserModInstances as there it will be used
static bool stageVarChanged;// = false; //tbd: move mechanism to UserModInstances as there it will be used
static std::vector<UFun> uFunctions; //static because of static functions setChFunAndWs, processJson...

SysModUI();
Expand Down
3 changes: 1 addition & 2 deletions src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,7 @@ bool SysModWeb::setupJsonHandlers(const char * uri, const char * (*processFunc)(
if (json["v"]) { //WLED compatibility: verbose response
serveJson (request);
}
else
if (responseVariant.size()) { //responseVariant set by processFunc
else if (responseVariant.size()) { //responseVariant set by processFunc
char resStr[200];
serializeJson(responseVariant, resStr, 200);
USER_PRINT_Async("processJsonUrl response %s\n", resStr);
Expand Down
2 changes: 2 additions & 0 deletions src/SysModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class SysModule {
const char * name;
bool success;
bool isEnabled;
unsigned long oneSecondMillis = millis() - random(1000); //random so not all 1s are fired at once
unsigned long tenSecondMillis = millis() - random(1000); //random within a second

JsonObject parentVar;

Expand Down
28 changes: 17 additions & 11 deletions src/SysModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,27 @@ void SysModules::setup() {
}

void SysModules::loop() {
bool oneSec = false;
// bool oneSec = false;
bool tenSec = false;
if (millis() - oneSecondMillis >= 1000) {
oneSecondMillis = millis();
oneSec = true;
}
if (millis() - tenSecondMillis >= 10000) {
tenSecondMillis = millis();
tenSec = true;
}
// if (millis() - oneSecondMillis >= 1000) {
// oneSecondMillis = millis();
// oneSec = true;
// }
// if (millis() - tenSecondMillis >= 10000) {
// tenSecondMillis = millis();
// tenSec = true;
// }
for (SysModule *module:modules) {
if (module->isEnabled && module->success) {
module->loop();
if (oneSec) module->loop1s();
if (tenSec) module->loop10s();
if (millis() - module->oneSecondMillis >= 1000) {
module->oneSecondMillis = millis();
module->loop1s();
}
if (millis() - module->tenSecondMillis >= 10000) {
module->tenSecondMillis = millis();
module->loop10s();
}
// module->testManager();
// module->performanceManager();
// module->dataSizeManager();
Expand Down
4 changes: 2 additions & 2 deletions src/SysModules.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class SysModules {

private:
std::vector<SysModule *> modules;
unsigned long oneSecondMillis = 0;
unsigned long tenSecondMillis = millis() - 4500;
// unsigned long oneSecondMillis = 0;
// unsigned long tenSecondMillis = millis() - 4500;
};

static SysModules *mdls;
16 changes: 6 additions & 10 deletions src/User/UserModE131.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,27 @@ class UserModE131:public SysModule {

parentVar = ui->initModule(parentVar, name);

ui->initNumber(parentVar, "dmxUni", universe, 0, 7, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Universe");
ui->initNumber(parentVar, "dun", universe, 0, 7, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "DMX Universe");
}, [this](JsonObject var, uint8_t) { //chFun
universe = var["value"];
ui->valChangedForInstancesTemp = true;
});

ui->initNumber(parentVar, "dmxChannel", 1, 0, 511, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Channel");
JsonObject currentVar = ui->initNumber(parentVar, "dch", 1, 1, 512, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "DMX Channel");
web->addResponse(var["id"], "comment", "First channel");
}, [](JsonObject var, uint8_t) { //chFun

ui->valChangedForInstancesTemp = true;

ui->processUiFun("e131Tbl"); //rebuild table

});
currentVar["stage"] = true;

JsonObject tableVar = ui->initTable(parentVar, "e131Tbl", nullptr, false, [this](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Vars to watch");
web->addResponse(var["id"], "comment", "List of instances");
JsonArray rows = web->addResponseA(var["id"], "table");
for (auto varToWatch: varsToWatch) {
JsonArray row = rows.createNestedArray();
row.add(varToWatch.channel + mdl->getValue("dmxChannel").as<uint8_t>());
row.add(varToWatch.channel + mdl->getValue("dch").as<uint8_t>());
row.add((char *)varToWatch.id);
row.add(varToWatch.max);
row.add(varToWatch.savedValue);
Expand Down
Loading

0 comments on commit 8de5957

Please sign in to comment.