Skip to content

Commit

Permalink
Merge branch 'main' into I2SClocklessLedDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
netmindz committed Mar 2, 2024
2 parents 996abe4 + b08db57 commit c8704fc
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 135 deletions.
74 changes: 39 additions & 35 deletions src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Effect {

virtual void loop(Leds &leds) {}

virtual void controls(JsonObject parentVar, Leds &leds) {}
virtual void controls(JsonObject parentVar) {}

void addPalette(JsonObject parentVar, uint8_t value) {
//currentVar["value"][contextRowNr] will be set to value parameter
Expand Down Expand Up @@ -80,7 +80,7 @@ class SolidEffect: public Effect {
CRGB color = CRGB(red, green, blue);
leds.fill_solid(color);
}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
ui->initSlider(parentVar, "Red", 182);
ui->initSlider(parentVar, "Green", 15);
ui->initSlider(parentVar, "Blue", 98);
Expand Down Expand Up @@ -127,7 +127,7 @@ class SinelonEffect: public Effect {
int pos = beatsin16( mdl->getValue("BPM").as<int>(), 0, leds.nrOfLeds-1 );
leds[pos] = leds.getPixelColor(pos) + CHSV( gHue, 255, 192);
}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
ui->initSlider(parentVar, "BPM", 60);
}
}; //Sinelon
Expand All @@ -146,7 +146,7 @@ class RunningEffect: public Effect {
leds[pos] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value
// leds[leds.nrOfLeds -1 - pos2] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value
}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
ui->initSlider(parentVar, "BPM", 60, 0, 255, false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
case f_UIFun:
ui->setComment(var, "in BPM!");
Expand Down Expand Up @@ -187,7 +187,7 @@ class BPMEffect: public Effect {
leds[i] = ColorFromPalette(pal, gHue+(i*2), beat-gHue+(i*10));
}
}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
}
};
Expand Down Expand Up @@ -215,23 +215,25 @@ class Ripples3DEffect: public Effect {
}
void loop(Leds &leds) {
uint8_t interval = mdl->getValue("interval");
uint8_t speed = mdl->getValue("speed");

float ripple_interval = 1.3 * (interval/128.0);
float ripple_interval = 1.3f * (interval/128.0f);

leds.fill_solid(CRGB::Black);
// fill(CRGB::Black);

Coord3D pos = {0,0,0};
for (pos.z=0; pos.z<leds.size.z; pos.z++) {
for (pos.x=0; pos.x<leds.size.x; pos.x++) {
float d = leds.fixture->distance(3.5, 3.5, 0, pos.x, pos.z, 0)/9.899495*leds.size.y;
pos.y = floor(leds.size.y/2.0+sinf(d/ripple_interval + now/100/((256.0-128.0)/20.0))*leds.size.y/2.0); //between 0 and 8
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;
uint32_t 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

leds[pos] = CHSV( gHue + random8(64), 200, 255);// ColorFromPalette(pal,call, bri, LINEARBLEND);
}
}
}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 50, 0, 99);
ui->initSlider(parentVar, "interval", 128);
}
};
Expand All @@ -242,27 +244,25 @@ class SphereMove3DEffect: public Effect {
return "SphereMove 3D";
}
void loop(Leds &leds) {
uint16_t origin_x, origin_y, origin_z, d;
float diameter;
uint8_t speed = mdl->getValue("speed");

leds.fill_solid(CRGB::Black);
// fill(CRGB::Black);

uint32_t interval = now/100/((256.0-128.0)/20.0);
uint32_t time_interval = now/(100 - speed)/((256.0f-128.0f)/20.0f);

Coord3D origin;
origin.x = 3.5+sinf(interval)*2.5;
origin.y = 3.5+cosf(interval)*2.5;
origin.z = 3.5+cosf(interval)*2.0;
origin.x = 3.5f+sinf(time_interval)*2.5f;
origin.y = 3.5f+cosf(time_interval)*2.5f;
origin.z = 3.5f+cosf(time_interval)*2.0f;

diameter = 2.0+sinf(interval/3.0);
float diameter = 2.0f+sinf(time_interval/3.0f);

// CRGBPalette256 pal;
Coord3D pos;
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++) {
d = leds.fixture->distance(pos.x, pos.y, pos.z, origin.x, origin.y, origin.z);
uint16_t d = leds.fixture->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 All @@ -271,6 +271,9 @@ class SphereMove3DEffect: public Effect {
}
}
}
void controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 50, 0, 99);
}
}; // SphereMove3DEffect

//Frizzles2D inspired by WLED, Stepko, Andrew Tuline, https://editor.soulmatelights.com/gallery/640-color-frizzles
Expand All @@ -297,7 +300,7 @@ class Frizzles2D: public Effect {
leds.blur2d(mdl->getValue("blur"));
}

void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "BPM", 60);
ui->initSlider(parentVar, "intensity", 128);
Expand Down Expand Up @@ -329,7 +332,7 @@ class Lines2D: public Effect {
}
}

void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
ui->initSlider(parentVar, "BPM", 60);
ui->initCheckBox(parentVar, "Vertical", true);
}
Expand Down Expand Up @@ -389,7 +392,7 @@ class DistortionWaves2D: public Effect {
}
}
}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 128);
ui->initSlider(parentVar, "scale", 128);
}
Expand Down Expand Up @@ -461,7 +464,7 @@ class Octopus2D: public Effect {
}
}
}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {

//bind the variables to sharedData...
// uint8_t *speed2 = leds.sharedData.bind(speed2);
Expand Down Expand Up @@ -529,7 +532,7 @@ class Lissajous2D: public Effect {
leds[locn] = ColorFromPalette(pal, now/100+i);
}
}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "X frequency", 64);
ui->initSlider(parentVar, "Fade rate", 128);
Expand Down Expand Up @@ -612,7 +615,7 @@ class BouncingBalls1D: public Effect {
} //balls
}

void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "gravity", 128);
ui->initSlider(parentVar, "balls", 8, 1, 16);
Expand Down Expand Up @@ -667,7 +670,7 @@ class ScrollingText2D: public Effect {
}

}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
ui->initText(parentVar, "text", "StarMod");
ui->initSlider(parentVar, "speed", 128);
ui->initSelect(parentVar, "font", 0, false, [](JsonObject var, uint8_t rowNr, uint8_t funType) { switch (funType) { //varFun
Expand Down Expand Up @@ -712,15 +715,16 @@ class Waverly2D: public Effect {
uint16_t thisMax = min(map(thisVal, 0, 512, 0, leds.size.y), (long)leds.size.x);

for (pos.y = 0; pos.y < thisMax; pos.y++) {
CRGB color = ColorFromPalette(pal, map(pos.y, 0, thisMax, 250, 0), 255, LINEARBLEND);
if (!noClouds)
leds.addPixelColor(pos, ColorFromPalette(pal, map(pos.y, 0, thisMax, 250, 0), 255, LINEARBLEND));
leds.addPixelColor(leds.XY((leds.size.x - 1) - pos.x, (leds.size.y - 1) - pos.y), ColorFromPalette(pal, map(pos.y, 0, thisMax, 250, 0), 255, LINEARBLEND));
leds.addPixelColor(pos, color);
leds.addPixelColor(leds.XY((leds.size.x - 1) - pos.x, (leds.size.y - 1) - pos.y), color);
}
}
leds.blur2d(16);

}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "Amplification", 128);
ui->initSlider(parentVar, "Sensitivity", 128);
Expand Down Expand Up @@ -807,7 +811,7 @@ class PopCorn1D: public Effect {
}

}
void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "speed", 128);
ui->initSlider(parentVar, "intensity", 128);
Expand Down Expand Up @@ -913,7 +917,7 @@ class GEQEffect:public Effect {
}
}

void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "fadeOut", 255);
ui->initSlider(parentVar, "ripple", 128);
Expand Down Expand Up @@ -975,7 +979,7 @@ class AudioRings:public RingEffect {
setRing(leds, ring, color);
}

void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
ui->initCheckBox(parentVar, "inWards", true);
}
Expand Down Expand Up @@ -1035,7 +1039,7 @@ class FreqMatrix:public Effect {
}
}

void controls(JsonObject parentVar, Leds &leds) {
void controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 255);
ui->initSlider(parentVar, "Sound effect", 128);
ui->initSlider(parentVar, "Low bin", 18);
Expand Down Expand Up @@ -1142,7 +1146,7 @@ class Effects {
// effect->loop(leds); //do a loop to set sharedData right
// leds.sharedData.loop();
mdl->varPreDetails(var, rowNr);
effect->controls(var, leds); //new controls have positive order (var["o"])
effect->controls(var);
mdl->varPostDetails(var, rowNr);

effect->setup(leds); //if changed then run setup once (like call==0 in WLED)
Expand Down
81 changes: 43 additions & 38 deletions src/App/AppFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void Fixture::projectAndMap() {
for (std::vector<std::vector<uint16_t>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap)
physMap->clear();
leds->mappingTable.clear();
leds->sharedData.clear();
}
rowNr++;
}
Expand Down Expand Up @@ -95,7 +96,7 @@ void Fixture::projectAndMap() {
//set start and endPos between bounderies of fixture
Coord3D startPosAdjusted = (leds->startPos).minimum(size - Coord3D{1,1,1}) * 10;
Coord3D endPosAdjusted = (leds->endPos).minimum(size - Coord3D{1,1,1}) * 10;
Coord3D projSize = (endPosAdjusted - startPosAdjusted).absx()/10 + Coord3D{1,1,1};
Coord3D projSize = (endPosAdjusted - startPosAdjusted)/10 + Coord3D{1,1,1};

// 0 to 3D depending on start and endpos (e.g. to display ScrollingText on one side of a cube)
uint8_t projectionDimension = 0;
Expand All @@ -109,8 +110,6 @@ void Fixture::projectAndMap() {
//only needed one time
//does not work for some reason...

Coord3D split = mdl->getValue("proSplit", rowNr);

// if (indexP == 0) //first
{
uint16_t maxDistance = distance(endPosAdjusted, startPosAdjusted) / 10;
Expand All @@ -132,6 +131,7 @@ void Fixture::projectAndMap() {
break;
case _2D:
if (leds->projectionNr == p_Multiply) {
Coord3D split = mdl->getValue("proSplit", rowNr);
leds->size = map2Dto2D(projSize) / split;
// USER_PRINTF("Multiply %d,%d,%d\n", leds->size.x, leds->size.y, leds->size.z);
}
Expand Down Expand Up @@ -168,7 +168,7 @@ void Fixture::projectAndMap() {
//scaling (check rounding errors)
//1024 crash in makebuffer...
// if (leds->size.x * leds->size.y > 256)
// scale = (sqrt((float)256.0 / (leds->size.x * leds->size.y))); //avoid high virtual resolutions
// scale = (sqrt(256.0f / (leds->size.x * leds->size.y))); //avoid high virtual resolutions
// leds->size.x *= scale;
// leds->size.y *= scale;
}
Expand Down Expand Up @@ -323,18 +323,21 @@ void Fixture::projectAndMap() {
if (indexV >= leds->nrOfLeds || indexV >= NUM_LEDS_Max) {
USER_PRINTF("dev post [%d] indexV too high %d>=%d or %d (p:%d m:%d) p:%d,%d,%d\n", rowNr, indexV, leds->nrOfLeds, NUM_LEDS_Max, leds->mappingTable.size(), indexP, pixel.x, pixel.y, pixel.z);
}
else {
else if (indexP < NUM_LEDS_Max) {
//create new physMaps if needed
if (indexV >= leds->mappingTable.size()) {
for (size_t i = leds->mappingTable.size(); i <= indexV; i++) {
// USER_PRINTF("mapping %d,%d,%d add physMap before %d %d\n", pixel.y, pixel.y, pixel.z, indexV, leds->mappingTable.size());
std::vector<uint16_t> physMap;
physMap.push_back(0);
leds->mappingTable.push_back(physMap); //abort() was called at PC 0x40191473 on core 1 std::allocator<unsigned short> >&&)
}
}
//indexV is within the square
if (indexP < NUM_LEDS_Max) leds->mappingTable[indexV].push_back(indexP); //add the current led in the right physMap
leds->mappingTable[indexV].push_back(indexP); //add the current led in the right physMap
}
else
USER_PRINTF("dev post [%d] indexP too high %d>=%d or %d (p:%d m:%d) p:%d,%d,%d\n", rowNr, indexP, nrOfLeds, NUM_LEDS_Max, leds->mappingTable.size(), indexP, pixel.x, pixel.y, pixel.z);
}
// USER_PRINTF("mapping b:%d t:%d V:%d\n", indexV, indexP, leds->mappingTable.size());
} //indexV not too high
Expand All @@ -349,33 +352,35 @@ void Fixture::projectAndMap() {
} //if 1D-3D
else { // end of leds array

//check if pin already allocated, if so, extend range in details
PinObject pinObject = pins->pinObjects[currPin];
char details[32] = "";
if (strcmp(pinObject.owner, "Leds") == 0) { //if owner

char * after = strtok((char *)pinObject.details, "-");
if (after != NULL ) {
char * before;
before = after;
after = strtok(NULL, " ");
uint16_t startLed = atoi(before);
uint16_t nrOfLeds = atoi(after) - atoi(before) + 1;
print->fFormat(details, sizeof(details)-1, "%d-%d", min(prevIndexP, startLed), max((uint16_t)(indexP - 1), nrOfLeds)); //careful: AppModLeds:loop uses this to assign to FastLed
USER_PRINTF("pins extend leds %d: %s\n", currPin, details);
//tbd: more check

strncpy(pins->pinObjects[currPin].details, details, sizeof(PinObject::details)-1);
if (doAllocPins) {
//check if pin already allocated, if so, extend range in details
PinObject pinObject = pins->pinObjects[currPin];
char details[32] = "";
if (pins->isOwner(currPin, "Leds")) { //if owner

char * after = strtok((char *)pinObject.details, "-");
if (after != NULL ) {
char * before;
before = after;
after = strtok(NULL, " ");
uint16_t startLed = atoi(before);
uint16_t nrOfLeds = atoi(after) - atoi(before) + 1;
print->fFormat(details, sizeof(details)-1, "%d-%d", min(prevIndexP, startLed), max((uint16_t)(indexP - 1), nrOfLeds)); //careful: AppModLeds:loop uses this to assign to FastLed
USER_PRINTF("pins extend leds %d: %s\n", currPin, details);
//tbd: more check

strncpy(pins->pinObjects[currPin].details, details, sizeof(PinObject::details)-1);
}
}
else {//allocate new pin
//tbd: check if free
print->fFormat(details, sizeof(details)-1, "%d-%d", prevIndexP, indexP - 1); //careful: AppModLeds:loop uses this to assign to FastLed
USER_PRINTF("pins %d: %s\n", currPin, details);
pins->allocatePin(currPin, "Leds", details);
}
}
else {//allocate new pin
//tbd: check if free
print->fFormat(details, sizeof(details)-1, "%d-%d", prevIndexP, indexP - 1); //careful: AppModLeds:loop uses this to assign to FastLed
USER_PRINTF("pins %d: %s\n", currPin, details);
pins->allocatePin(currPin, "Leds", details);
}

prevIndexP = indexP;
prevIndexP = indexP;
}
}
}); //starModJson.lookFor("leds" (create the right type, otherwise crash)

Expand All @@ -398,13 +403,13 @@ void Fixture::projectAndMap() {

} else {

// if (leds->mappingTable.size() < leds->size.x * leds->size.y * leds->size.z)
// USER_PRINTF("mapping add extra physMap %d of %d %d,%d,%d\n", leds->mappingTable.size(), leds->size.x * leds->size.y * leds->size.z, leds->size.x, leds->size.y, leds->size.z);
// for (size_t i = leds->mappingTable.size(); i < leds->size.x * leds->size.y * leds->size.z; i++) {
// std::vector<uint16_t> physMap;
// physMap.push_back(0);
// leds->mappingTable.push_back(physMap);
// }
if (leds->mappingTable.size() < leds->size.x * leds->size.y * leds->size.z)
USER_PRINTF("mapping add extra physMap %d of %d %d,%d,%d\n", leds->mappingTable.size(), leds->size.x * leds->size.y * leds->size.z, leds->size.x, leds->size.y, leds->size.z);
for (size_t i = leds->mappingTable.size(); i < leds->size.x * leds->size.y * leds->size.z; i++) {
std::vector<uint16_t> physMap;
physMap.push_back(0);
leds->mappingTable.push_back(physMap);
}

leds->nrOfLeds = leds->mappingTable.size();

Expand Down
Loading

0 comments on commit c8704fc

Please sign in to comment.