Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ewowi committed Jan 26, 2024
1 parent 81371e4 commit 365f98e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ build_flags =
-D USERMOD_ARTNET
-D USERMOD_DDP
lib_deps =
https://github.com/FastLED/FastLED.git
https://github.com/FastLED/FastLED.git@3.6.0

[usermod_e131]
build_flags =
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void Leds::fixtureProjectAndMap() {
//1024 crash in makebuffer...
float scale = 1;
if (size.x * size.y > 256)
scale = (sqrt((float)256.0 / (size.x * size.y))); //avoid very high virtual resolutions
scale = (sqrt((float)256.0 / (size.x * size.y))); //avoid high virtual resolutions
size.x *= scale;
size.y *= scale;
x = (x+1) * scale - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Leds {
//track pins and leds
uint8_t currPin;
uint16_t prevLeds;
Coord3D startPos = {0,0,0}, endPos = {8,8,1}; //default
Coord3D startPos = {0,0,0}, endPos = {7,7,0}; //default

float distance(uint16_t x1, uint16_t y1, uint16_t z1, uint16_t x2, uint16_t y2, uint16_t z2) {
return sqrtf((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
Expand Down
27 changes: 19 additions & 8 deletions src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,39 @@ class AppModLeds:public SysModule {
});
currentVar["stage"] = true;

ui->initCoord3D(tableVar, "fxStart", 0, 0, 127, false, [](JsonObject var) { //uiFun
ui->initCoord3D(tableVar, "fxStart", UINT16_MAX, 0, 127, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Start");
}, [this](JsonObject var, uint8_t rowNr) { //chFun

leds.startPos = mdl->getValue(var, rowNr).as<Coord3D>();

USER_PRINTF("fxStart %d %d %d - %d %d %d\n", leds.startPos.x, leds.startPos.y, leds.startPos.z, leds.endPos.x, leds.endPos.y, leds.endPos.z);

leds.fadeToBlackBy();

leds.startPos = mdl->getValue(var, rowNr).as<Coord3D>();
doMap = true;
}, nullptr, 1, [this](JsonObject var, uint8_t rowNr) { //valueFun
mdl->setValue(var, leds.startPos, rowNr);
});
ui->initCoord3D(tableVar, "fxEnd", 0, 0, 127, false, [](JsonObject var) { //uiFun

ui->initCoord3D(tableVar, "fxEnd", UINT16_MAX, 0, 127, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "End");
}, [this](JsonObject var, uint8_t rowNr) { //chFun

leds.endPos = mdl->getValue(var, rowNr).as<Coord3D>();

USER_PRINTF("fxEnd %d %d %d - %d %d %d\n", leds.startPos.x, leds.startPos.y, leds.startPos.z, leds.endPos.x, leds.endPos.y, leds.endPos.z);

leds.fadeToBlackBy();

leds.endPos = mdl->getValue(var, rowNr).as<Coord3D>();
doMap = true;
}, nullptr, 1, [this](JsonObject var, uint8_t rowNr) { //valueFun
mdl->setValue(var, leds.endPos, rowNr);
});

ui->initCoord3D(tableVar, "fxSize", 0, 0, 127, true, [this](JsonObject var) { //uiFun
ui->initCoord3D(tableVar, "fxSize", UINT16_MAX, 0, 127, true, [this](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Size");
web->addResponse(var["id"], "value", leds.size);
web->addResponse(var["id"], "value", leds.size); //value in uiFun is only send to the ui, not stored in model
});
// , nullptr, nullptr, 1, [this](JsonObject var, uint8_t rowNr) { //valueFun
// // char detail[32];
Expand All @@ -173,7 +184,7 @@ class AppModLeds:public SysModule {

ui->initNumber(tableVar, "fxCount", UINT16_MAX, 0, UINT8_MAX, true, [this](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Count");
// web->addResponse(var["id"], "value", leds.nrOfLeds);
// web->addResponse(var["id"], "value", leds.nrOfLeds); //value in uiFun is only send to the ui, not stored in model
}, nullptr, nullptr, 1, [this](JsonObject var, uint8_t rowNr) { //valueFun
mdl->setValue(var, leds.nrOfLeds, rowNr);
});
Expand Down Expand Up @@ -206,7 +217,7 @@ class AppModLeds:public SysModule {
}
}); //fixture

ui->initCoord3D(parentVar, "fixSize", 0, 0, 127, true, [this](JsonObject var) { //uiFun
ui->initCoord3D(parentVar, "fixSize", UINT16_MAX, 0, 127, true, [this](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Size");
web->addResponse(var["id"], "value", leds.sizeP);
});
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void SysModNetwork::setup() {
ui->initButton(parentVar, "connect", nullptr, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "comment", "Force reconnect (loose current connection)");
}, [this](JsonObject var, uint8_t) { //chFun
mdl->doWriteModel = true; //saves the model
// mdl->doWriteModel = true; //saves the model
forceReconnect = true;
});
ui->initText(parentVar, "nwstatus", nullptr, 32, true, [](JsonObject var) { //uiFun
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void SysModUI::setChFunAndWs(JsonObject var, uint8_t rowNr, const char * value)
if (!var["chFun"].isNull()) {//isNull needed here!
size_t funNr = var["chFun"];
if (funNr < cFunctions.size()) {
USER_PRINTF("chFun %s r:%d v:%s\n", var["id"].as<const char *>(), rowNr, var["value"].as<String>().c_str());
USER_PRINTF("chFun %s[%d] <- %s\n", var["id"].as<const char *>(), rowNr, var["value"].as<String>().c_str());
cFunctions[funNr](var, rowNr);
}
else
Expand Down
11 changes: 6 additions & 5 deletions src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,13 @@ void SysModWeb::sendDataWs(std::function<void(AsyncWebSocketMessageBuffer *)> fi

for (auto loopClient:ws->getClients()) {
if (!client || client == loopClient) {
if (loopClient->status() == WS_CONNECTED && !loopClient->queueIsFull() && (!isBinary || loopClient->queueLength() <= WS_MAX_QUEUED_MESSAGES / web->ws->count() / 2)) { //binary is lossy
if (loopClient->status() == WS_CONNECTED && !loopClient->queueIsFull() && (!isBinary || loopClient->queueLength() <= 3)) { //WS_MAX_QUEUED_MESSAGES / ws->count() / 2)) { //binary is lossy
isBinary?loopClient->binary(wsBuf): loopClient->text(wsBuf);
sendDataWsCounter++;
}
else {
print->printClient("sendDataWs client full or not connected\n", loopClient);
print->printClient("sendDataWs client full or not connected", loopClient); //causes crash
// USER_PRINTF("sendDataWs client full or not connected\n");
// ws->cleanupClients(); //only if above threshold
// ws->_cleanBuffers();
}
Expand All @@ -365,9 +366,9 @@ void SysModWeb::sendDataWs(std::function<void(AsyncWebSocketMessageBuffer *)> fi
}
else {
USER_PRINT_Async("sendDataWs WS buffer allocation failed\n");
ws->_cleanBuffers();
ws->cleanupClients(0); //disconnect ALL clients to release memory
ws->closeAll(1013); //code 1013 = temporary overload, try again later
ws->cleanupClients(0); //disconnect ALL clients to release memory
ws->_cleanBuffers();
}
}

Expand All @@ -387,7 +388,7 @@ bool SysModWeb::addURL(const char * uri, const char * contentType, const char *

if (strcmp(uri, "/") == 0) {

if (captivePortal(request)) return;
// if (captivePortal(request)) return;

// if (handleIfNoneMatchCacheHeader(request)) return;

Expand Down

0 comments on commit 365f98e

Please sign in to comment.