Skip to content

Commit

Permalink
Small changes, add FastLed.show toggle variable
Browse files Browse the repository at this point in the history
index.css: ndiv margin left smaller

LedEffects:
- refactor distance
- Popcorn: add fill_solid
- move head to fixture level in LedModEffects

LedFixture: use Coord3D.distance

LedModEffects: add fShow for performance tuning
LedModFixture: add fShow variable

SysModModel: add Coord3D.distance

SysModPins, SysModUI, ArtNet, DDP, E131, Instances: range-based for loop use &
  • Loading branch information
ewowi committed Mar 15, 2024
1 parent 3e262bc commit 7023f73
Show file tree
Hide file tree
Showing 15 changed files with 1,383 additions and 1,388 deletions.
4 changes: 2 additions & 2 deletions data/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ canvas {

.ndiv {
/* border: 2px solid black; */
margin-left: 25px;
border-radius: 12px;
margin-left: 10px;
/* border-radius: 12px; */
}

/*table layout */
Expand Down
32 changes: 9 additions & 23 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ unsigned8 gHue = 0; // rotating "base color" used by many of the patterns
unsigned long call = 0; //not used at the moment (don't use in effect calculations)
unsigned long now = millis();

//utility function
float distance(float x1, float y1, float z1, float x2, float y2, float z2) {
return sqrtf((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}

//should not contain variables/bytes to keep mem as small as possible!!
class Effect {
public:
Expand Down Expand Up @@ -652,6 +657,8 @@ class PopCorn: public Effect {

Spark *popcorn = leds.sharedData.bind(popcorn, maxNumPopcorn); //array

leds.fill_solid(CRGB::Black);

float gravity = -0.0001 - (speed/200000.0); // m/s/s
gravity *= leds.nrOfLeds;

Expand Down Expand Up @@ -1373,7 +1380,7 @@ class RipplesEffect: public Effect {
Coord3D pos = {0,0,0};
for (pos.z=0; pos.z<leds.size.z; pos.z++) {
for (pos.y=0; pos.y<leds.size.y; pos.y++) {
float d = leds.fixture->distance(3.5f, 3.5f, 0.0f, (float)pos.x, (float)pos.z, 0.0f) / 9.899495f * leds.size.x;
float d = distance(3.5f, 3.5f, 0.0f, (float)pos.x, (float)pos.z, 0.0f) / 9.899495f * leds.size.x;
stackUnsigned32 time_interval = now/(100 - speed)/((256.0f-128.0f)/20.0f);
pos.x = floor(leds.size.x/2.0f + sinf(d/ripple_interval + time_interval) * leds.size.x/2.0f); //between 0 and leds.size.x

Expand Down Expand Up @@ -1412,7 +1419,7 @@ class SphereMoveEffect: public Effect {
for (pos.x=0; pos.x<leds.size.x; pos.x++) {
for (pos.y=0; pos.y<leds.size.y; pos.y++) {
for (pos.z=0; pos.z<leds.size.z; pos.z++) {
stackUnsigned16 d = leds.fixture->distance(pos.x, pos.y, pos.z, origin.x, origin.y, origin.z);
stackUnsigned16 d = distance(pos.x, pos.y, pos.z, origin.x, origin.y, origin.z);

if (d>diameter && d<diameter+1) {
leds[pos] = CHSV( gHue + random8(64), 200, 255);// ColorFromPalette(pal,call, bri, LINEARBLEND);
Expand Down Expand Up @@ -1513,16 +1520,6 @@ class Effects {
leds.sharedData.loop(); //sets the sharedData pointer back to 0 so loop effect can go through it
effects[leds.fx%effects.size()]->loop(leds);

#ifdef STARMOD_USERMOD_WLEDAUDIO

if (mdl->getValue("mHead") ) {
leds.fixture->head.x = wledAudioMod->fftResults[3];
leds.fixture->head.y = wledAudioMod->fftResults[8];
leds.fixture->head.z = wledAudioMod->fftResults[13];
}

#endif

call++;

EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
Expand All @@ -1549,17 +1546,6 @@ class Effects {
effect->setup(leds); //if changed then run setup once (like call==0 in WLED)

print->printJson("control", var);
// if (mdl->varOrder(var) >= 0) { //post init
// var["o"] = -mdl->varOrder(var); //make positive again
//set unused vars to inactive
// if (mdl->varOrder(var) >=0)
// mdl->setValue(var, UINT16_MAX, rowNr);
// }
// for (JsonObject var: var["n"].as<JsonArray>()) {
// if (mdl->varOrder(var) <0)
// var["o"] = -mdl->varOrder(var);
// }
//remove vars with all values -99

if (effects[leds.fx]->dim() != leds.effectDimension) {
leds.effectDimension = effects[leds.fx]->dim();
Expand Down
4 changes: 2 additions & 2 deletions src/App/LedFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ void Fixture::projectAndMap() {
switch (leds->effectDimension) {
case _1D: //1DxD
if (leds->size == Coord3D{0,0,0}) { // first
leds->size.x = distance(sizeAdjusted, proCenter);
leds->size.x = sizeAdjusted.distance(proCenter);
leds->size.y = 1;
leds->size.z = 1;
}

mapped.x = distance(pixelAdjusted, proCenter);
mapped.x = pixelAdjusted.distance(proCenter);
mapped.y = 0;
mapped.z = 0;

Expand Down
12 changes: 0 additions & 12 deletions src/App/LedFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,4 @@ class Fixture {
//load fixture json file, parse it and depending on the projection, create a mapping for it
void projectAndMap();

float distance(float x1, float y1, float z1, float x2, float y2, float z2) {
return sqrtf((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}
float distance(unsigned16 x1, unsigned16 y1, unsigned16 z1, unsigned16 x2, unsigned16 y2, unsigned16 z2) {
return distance(Coord3D{x1, y1, z1}, Coord3D{x2,y2,z2});
// return sqrtf((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}
float distance(Coord3D c1, Coord3D c2) {
Coord3D delta = (c1-c2);
return sqrtf((delta.x)*(delta.x) + (delta.y)*(delta.y) + (delta.z)*(delta.z));
}

};
19 changes: 14 additions & 5 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
#include "LedFixture.h"
#include "LedEffects.h"

// #ifdef STARMOD_USERMOD_E131
// #include "../User/UserModE131.h"
// #endif

// #define FASTLED_RGBW

//https://www.partsnotincluded.com/fastled-rgbw-neopixels-sk6812/
Expand All @@ -51,6 +47,8 @@ class LedModEffects:public SysModule {

Fixture fixture = Fixture();

bool fShow = true;

LedModEffects() :SysModule("Effects") {
};

Expand Down Expand Up @@ -346,7 +344,18 @@ class LedModEffects:public SysModule {
}
}

FastLED.show();
#ifdef STARMOD_USERMOD_WLEDAUDIO

if (mdl->getValue("mHead") ) {
fixture.head.x = wledAudioMod->fftResults[3];
fixture.head.y = wledAudioMod->fftResults[8];
fixture.head.z = wledAudioMod->fftResults[13];
}

#endif

if (fShow)
FastLED.show();

frameCounter++;
}
Expand Down
13 changes: 12 additions & 1 deletion src/App/LedModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LedModFixture:public SysModule {
ui->initCanvas(parentVar, "pview", UINT16_MAX, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "Preview");
ui->setComment(var, "Shows the fixture");
// ui->setComment(var, "Shows the fixture");
// ui->setComment(var, "Click to enlarge");
return true;
case f_LoopFun: {
Expand Down Expand Up @@ -150,6 +150,17 @@ class LedModFixture:public SysModule {
default: return false;
}});

ui->initCheckBox(parentVar, "fShow", eff->fShow, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "FastLed show");
ui->setComment(var, "dev performance tuning");
return true;
case f_ChangeFun:
eff->fShow = var["value"];
return true;
default: return false;
}});

ui->initText(parentVar, "realFps", nullptr, 10, true, [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
web->addResponseV(var["id"], "comment", "f(%d leds)", eff->fixture.nrOfLeds);
Expand Down
4 changes: 4 additions & 0 deletions src/Sys/SysModModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ struct Coord3D {
if (z != goal.z) z += (z<goal.z)?1:-1;
return *this;
}
unsigned distance(Coord3D rhs) {
Coord3D delta = (*this-rhs);
return sqrt((delta.x)*(delta.x) + (delta.y)*(delta.y) + (delta.z)*(delta.z));
}
};

//used to sort keys of jsonobjects
Expand Down
6 changes: 3 additions & 3 deletions src/Sys/SysModPins.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SysModPins:public SysModule {
//temporary functions until we refactored the PinObject
PinObject getNthAllocatedPinObject(unsigned8 rowNr) {
stackUnsigned8 n = 0;
for (PinObject pinObject:pinObjects) {
for (PinObject &pinObject:pinObjects) {
if (strcmp(pinObject.owner, "") != 0) {
if (n == rowNr)
return pinObject;
Expand All @@ -48,7 +48,7 @@ class SysModPins:public SysModule {
}
unsigned8 getNrOfAllocatedPins() {
stackUnsigned8 n = 0;
for (PinObject pinObject:pinObjects) {
for (PinObject &pinObject:pinObjects) {
if (strcmp(pinObject.owner, "") != 0) {
n++;
}
Expand All @@ -58,7 +58,7 @@ class SysModPins:public SysModule {
unsigned8 getPinNr(unsigned8 rowNr) {
stackUnsigned8 pinNr = 0;
stackUnsigned8 n = 0;
for (PinObject pinObject:pinObjects) {
for (PinObject &pinObject:pinObjects) {
if (strcmp(pinObject.owner, "") != 0) {
if (n == rowNr)
return pinNr;
Expand Down
14 changes: 7 additions & 7 deletions src/Sys/SysModUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ void SysModUI::setup() {
void SysModUI::loop() {
// SysModule::loop();

for (auto varLoop = begin (loopFunctions); varLoop != end (loopFunctions); ++varLoop) {
if (millis() - varLoop->lastMillis >= varLoop->var["interval"].as<int>()) {
varLoop->lastMillis = millis();
for (VarLoop &varLoop : loopFunctions) {
if (millis() - varLoop.lastMillis >= varLoop.var["interval"].as<int>()) {
varLoop.lastMillis = millis();

varLoop->loopFun(varLoop->var, 1, f_LoopFun); //rowNr..
varLoop.loopFun(varLoop.var, 1, f_LoopFun); //rowNr..

varLoop->counter++;
varLoop.counter++;
// USER_PRINTF("%s %u %u %d %d\n", varLoop->mdl->varID(var), varLoop->lastMillis, millis(), varLoop->interval, varLoop->counter);
}
}
Expand All @@ -76,8 +76,8 @@ void SysModUI::loop() {
void SysModUI::loop1s() {
//if something changed in vloops
ui->callVarFun("vlLoopps", UINT8_MAX, f_ValueFun);
for (auto varLoop = begin (loopFunctions); varLoop != end (loopFunctions); ++varLoop)
varLoop->counter = 0;
for (VarLoop &varLoop : loopFunctions)
varLoop.counter = 0;
}

JsonObject SysModUI::initVar(JsonObject parent, const char * id, const char * type, bool readOnly, VarFun varFun) {
Expand Down
2 changes: 1 addition & 1 deletion src/SysModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void SysModules::add(SysModule* module) {
}

void SysModules::connectedChanged() {
for (SysModule * module:modules) {
for (SysModule *module:modules) {
module->connectedChanged();
}
}
10 changes: 5 additions & 5 deletions src/User/UserModArtNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class UserModArtNet:public SysModule {
JsonArray instanceObject = options.add<JsonArray>();
instanceObject.add(0);
instanceObject.add("no sync");
for (auto node=instances->instances.begin(); node!=instances->instances.end(); ++node) {
if (node->ip != WiFi.localIP()) {
for (InstanceInfo &instance : instances->instances) {
if (instance.ip != WiFi.localIP()) {
char option[64] = { 0 };
strncpy(option, node->name, sizeof(option)-1);
strncpy(option, instance.name, sizeof(option)-1);
strncat(option, " ", sizeof(option)-1);
strncat(option, node->ip.toString().c_str(), sizeof(option)-1);
strncat(option, instance.ip.toString().c_str(), sizeof(option)-1);
instanceObject = options.add<JsonArray>();
instanceObject.add(node->ip[3]);
instanceObject.add(instance.ip[3]);
instanceObject.add(option);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/User/UserModDDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ class UserModDDP:public SysModule {
JsonArray instanceObject = options.add<JsonArray>();
instanceObject.add(0);
instanceObject.add("no sync");
for (auto node=instances->instances.begin(); node!=instances->instances.end(); ++node) {
if (node->ip != WiFi.localIP()) {
for (InstanceInfo &instance : instances->instances) {
if (instance.ip != WiFi.localIP()) {
char option[64] = { 0 };
strncpy(option, node->name, sizeof(option)-1);
strncpy(option, instance.name, sizeof(option)-1);
strncat(option, " ", sizeof(option)-1);
strncat(option, node->ip.toString().c_str(), sizeof(option)-1);
strncat(option, instance.ip.toString().c_str(), sizeof(option)-1);
instanceObject = options.add<JsonArray>();
instanceObject.add(node->ip[3]);
instanceObject.add(instance.ip[3]);
instanceObject.add(option);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/User/UserModE131.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,25 @@ class UserModE131:public SysModule {
e131_packet_t packet;
e131.pull(&packet); // Pull packet from ring buffer

for (auto varToWatch=varsToWatch.begin(); varToWatch!=varsToWatch.end(); ++varToWatch) {
for (VarToWatch &varToWatch : varsToWatch) {
for (int i=0; i < maxChannels; i++) {
if (i == varToWatch->channel) {
if (packet.property_values[i] != varToWatch->savedValue) {
if (i == varToWatch.channel) {
if (packet.property_values[i] != varToWatch.savedValue) {

USER_PRINTF("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH%d: %u -> %u",
htons(packet.universe), // The Universe for this packet
htons(packet.property_value_count) - 1, // Start code is ignored, we're interested in dimmer data
e131.stats.num_packets, // Packet counter
e131.stats.packet_errors, // Packet error counter
i,
varToWatch->savedValue,
varToWatch.savedValue,
packet.property_values[i]); // Dimmer data for Channel i

varToWatch->savedValue = packet.property_values[i];
varToWatch.savedValue = packet.property_values[i];

if (varToWatch->id != nullptr && varToWatch->max != 0) {
USER_PRINTF(" varsToWatch: %s\n", varToWatch->id);
mdl->setValue(varToWatch->id, varToWatch->savedValue%(varToWatch->max+1)); // TODO: ugly to have magic string
if (varToWatch.id != nullptr && varToWatch.max != 0) {
USER_PRINTF(" varsToWatch: %s\n", varToWatch.id);
mdl->setValue(varToWatch.id, varToWatch.savedValue%(varToWatch.max+1)); // TODO: ugly to have magic string
}
else
USER_PRINTF("\n");
Expand Down
Loading

0 comments on commit 7023f73

Please sign in to comment.