Skip to content

Commit

Permalink
Stack size 8K->16K, controls bugfix, setValue refactor
Browse files Browse the repository at this point in the history
pio.ini
- latest ESPLiveScript (3.1)

main.cpp
- set SET_LOOP_TASK_STACK_SIZE to 16K (WIP)

SysModModel
- preDetails: if oldvalue then remove old details
- Variable::value: support rowNr
- refactor setValue

UserModLive / SysModSystem
- measure stack size
  • Loading branch information
ewowi committed Dec 16, 2024
1 parent ed06493 commit f5f9021
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 54 deletions.
6 changes: 4 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ build_flags =
-D STARBASE_USERMOD_LIVE
-D EXTPRINTF=ppf ;redirect Live Script prints to StarBase print
lib_deps =
https://github.com/ewowi/ESPLiveScript.git#c6463f6 ; v3.1 ;ewowi repo adds some proposed PR's and makes sure we don't have unexpected updates
https://github.com/ewowi/ESPLiveScript.git#7bcd5bf ; v3.1 ;ewowi repo adds some proposed PR's and makes sure we don't have unexpected updates

[STARLIGHT_CLOCKLESS_LED_DRIVER]
build_flags =
Expand Down Expand Up @@ -248,11 +248,13 @@ build_flags =
-mfix-esp32-psram-cache-issue
-D STARBASE_BOOT_BUTTON_PIN=0 ; boot pin on the esp32 board, works!
; ${STARLIGHT_CLOCKLESS_LED_DRIVER.build_flags}
${STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER.build_flags}
-D STARLIGHT_MAXLEDS=12288 ;LEDs specific
; -D STARLIGHT_LIVE_MAPPING
lib_deps =
${env.lib_deps}
; ${STARLIGHT_CLOCKLESS_LED_DRIVER.lib_deps}
${STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER.lib_deps}

;End LEDs specific builds

Expand Down Expand Up @@ -369,7 +371,7 @@ build_flags =
${env.build_flags}
-D CONFIG_IDF_TARGET_ESP32S3=1
-D STARBASE_LOLIN_WIFI_FIX ; shouldn't be necessary, but otherwise WiFi issues on my board
-D STARBASE_BOOT_BUTTON_PIN=0 ; boot pin on the esp32 board, check 48?
-D STARBASE_BOOT_BUTTON_PIN=0 ; boot pin on the esp32 board
-D STARLIGHT_MAXLEDS=16384 ;LEDs specific
${STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER.build_flags}
lib_deps =
Expand Down
10 changes: 8 additions & 2 deletions src/Sys/SysModModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@
}

void Variable::preDetails() {
for (JsonObject varChild: children()) { //for all controls
varChild.remove("o");
print->printJson("preDetails pre", var);
if (var["oldValue"].isNull()) //no previous effect: during boot
for (JsonObject varChild: children()) { //for all controls
varChild.remove("o");
}
else {
var["n"].to<JsonArray>(); //delete old values
}

ppf("preDetails %s.%s post ", pid(), id());
print->printVar(var);
ppf("\n");
Expand Down
76 changes: 27 additions & 49 deletions src/Sys/SysModModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ class Variable {
const char *id() const {return var["id"];}
const char *type() const {return var["type"];}

JsonVariant value() const {return var["value"];}
JsonVariant value(uint8_t rowNr) const {return var["value"][rowNr];}
JsonVariant value(uint8_t rowNr = UINT8_MAX) const {return (rowNr==UINT8_MAX)?var["value"].as<JsonVariant>(): var["value"][rowNr].as<JsonVariant>();}

String valueString(uint8_t rowNr = UINT8_MAX);

Expand Down Expand Up @@ -289,62 +288,41 @@ class Variable {
void setValueJV(JsonVariant value, uint8_t rowNr = UINT8_MAX);

template <typename Type>
void setValue(Type value, uint8_t rowNr = UINT8_MAX) {
bool changed = false;

if (rowNr == UINT8_MAX) { //normal situation
if (var["value"].isNull() || var["value"].as<Type>() != value) { //const char * will be JsonString so comparison works
if (!var["value"].isNull() && !readOnly()) var["oldValue"] = var["value"];
var["value"] = value;
//trick to remove null values
if (var["value"].isNull() || var["value"].as<uint16_t>() == UINT16_MAX) {
var.remove("value");
// ppf("dev setValue value removed %s %s\n", id(), var["oldValue"].as<String>().c_str());
}
else {
//only print if ! read only
// if (!readOnly())
// ppf("setValue changed %s.%s %s -> %s\n", pid(), id(), var["oldValue"].as<String>().c_str(), valueString().c_str());
// else
// ppf("setValue changed %s %s\n", id(), var["value"].as<String>().c_str());
JsonVariant value = var["value"];
web->addResponse(var, "value", value);
changed = true;
}
}
}
else {
//if we deal with multiple rows, value should be an array, if not we create one
void setValue(Type newValue, uint8_t rowNr = UINT8_MAX) {

if (var["value"].isNull() || !var["value"].is<JsonArray>()) {
// ppf("setValue var %s[%d] value %s not array, creating\n", id(), rowNr, var["value"].as<String>().c_str());
var["value"].to<JsonArray>();
}
if (value(rowNr).as<Type>() != newValue) { //changed

if (var["value"].is<JsonArray>()) {
JsonArray valueArray = valArray();
//set the right value in the array (if array did not contain values yet, all values before rownr are set to false)
changed = true; //rowNr >= size
if (!readOnly()) var["oldValue"] = value(); //save oldValue

if (rowNr < valueArray.size())
changed = valueArray[rowNr].isNull() || valueArray[rowNr].as<Type>() != value;
//save newValue, cleanup null values
if (rowNr == UINT8_MAX) {
var["value"] = newValue;

if (changed) {
if (value().isNull() || value().as<uint16_t>() == UINT16_MAX) {
ppf("setValue value removed %s.%s %s->%s\n", pid(), id(), valueString().c_str(), var["oldValue"].as<String>().c_str());
var.remove("value");
}

// if (rowNr >= valueArray.size())
// ppf("notSame %d %d\n", rowNr, valueArray.size());
valueArray[rowNr] = value; //if valueArray[<rowNr] not exists it will be created
// ppf(" assigned %d %d %s\n", rowNr, valueArray.size(), valueArray[rowNr].as<String>().c_str());
JsonVariant value = var["value"];
web->addResponse(var, "value", value); //send the whole array to UI as response is in format value:<value> !!
} else {
var["value"][rowNr] = newValue;

//cleanup Array
size_t size = value().size();
while (size > 0 && (value(size-1).isNull() || value(size-1).as<uint16_t>() == UINT16_MAX)) {
ppf("setValue value removed %s.%s[%d] %s->%s\n", pid(), id(), size - 1, valueString().c_str(), var["oldValue"].as<String>().c_str());
var["value"].remove(size-1);
size = value().size();
}
if (size == 0) {
ppf("setValue value array removed %s.%s[] %s->%s\n", pid(), id(), valueString().c_str(), var["oldValue"].as<String>().c_str());
var.remove("value");
}
}
else {
ppf("setValue %s.%s could not create value array\n", pid(), id());
}

web->addResponse(var, "value", value());
triggerEvent(onChange, rowNr);
}

if (changed) triggerEvent(onChange, rowNr);
}

//Set value with argument list
Expand Down
2 changes: 2 additions & 0 deletions src/Sys/SysModSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ SysModSystem::SysModSystem() :SysModule("System") {};

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

ppf("Stack %d of %d B (async %d of %d B) %d\n", sysTools_get_arduino_maxStackUsage(), getArduinoLoopTaskStackSize(), sysTools_get_webserver_maxStackUsage(), CONFIG_ASYNC_TCP_STACK_SIZE, uxTaskGetStackHighWaterMark(xTaskGetCurrentTaskHandle()));

const Variable parentVar = ui->initSysMod(Variable(), name, 2000);
parentVar.var["s"] = true; //setup
Expand Down
3 changes: 2 additions & 1 deletion src/User/UserModLive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ static float _time(float j) {
}

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());
ppf("Heap %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());
ppf("Stack %d of %d B (async %d of %d B) %d\n", sys->sysTools_get_arduino_maxStackUsage(), getArduinoLoopTaskStackSize(), sys->sysTools_get_webserver_maxStackUsage(), CONFIG_ASYNC_TCP_STACK_SIZE, uxTaskGetStackHighWaterMark(xTaskGetCurrentTaskHandle()));

Executable executable = parser.parseScript(&scScript);
executable.name = string(fileName);
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ UserModMDNS *mdns;
UserModAudioSync *audioSync;
#endif

SET_LOOP_TASK_STACK_SIZE(16 * 1024); // 16KB

//setup all modules
void setup() {

mdls = new SysModules();

print = new SysModPrint();
Expand Down

0 comments on commit f5f9021

Please sign in to comment.