Skip to content

Commit

Permalink
Funky Plank and mapping
Browse files Browse the repository at this point in the history
LedEffects: fix Funky Plank

LedFixture: update 1d1d, 2d1d and 2d2d

LedLeds: bugfix fadeToBlackBy, fill
  • Loading branch information
ewowi committed Mar 6, 2024
1 parent 2af0386 commit d25876e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 78 deletions.
46 changes: 18 additions & 28 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ class GEQEffect:public Effect {

stackUnsigned16 lastBandHeight = 0; // WLEDMM: for smoothing out bars

//WLEDMM: evenly ditribut bands
//evenly distribute see also Funky Plank/By ewowi/From AXI
float bandwidth = (float)leds.size.x / NUM_BANDS;
float remaining = bandwidth;
stackUnsigned8 band = 0;
Expand Down Expand Up @@ -1145,53 +1145,43 @@ class FunkyPlank:public Effect {
public:
const char * name() {return "Funky Plank";}
unsigned8 dim() {return _2D;}
const char * tags() {return "💡♫";}
const char * tags() {return "💡💫";}

void setup(Leds &leds) {
leds.fill_solid(CRGB::Black);
}

void loop(Leds &leds) {

const uint16_t cols = leds.size.x;
const uint16_t rows = leds.size.y;

unsigned8 num_bands = mdl->getValue("bands");
int barWidth = (cols / num_bands);
int bandInc = 1;
if (barWidth == 0) {
// Matrix narrower than fft bands
barWidth = 1;
bandInc = (num_bands / cols);
}
unsigned8 speed = mdl->getValue("speed");

unsigned8 *aux0 = leds.sharedData.bind(aux0);
unsigned8 speed = mdl->getValue("speed");

unsigned8 secondHand = (speed < 255) ? (micros()/(256-speed)/500 % 16) : 0;
if((speed > 254) || (*aux0 != secondHand)) { // WLEDMM allow run run at full speed
if ((speed > 254) || (*aux0 != secondHand)) { // WLEDMM allow run run at full speed
*aux0 = secondHand;

// display values of
int b = 0;
for (int band = 0; band < num_bands; band += bandInc, b++) {
int hue = wledAudioMod->fftResults[band % 16];
int v = map(wledAudioMod->fftResults[band % 16], 0, 255, 10, 255);
for (int w = 0; w < barWidth; w++) {
int xpos = (barWidth * b) + w;
leds.setPixelColor(leds.XY(xpos, 0), CHSV(hue, 255, v));
}
//evenly distribute see also GEQ/By ewowi/From AXI
float bandwidth = (float)leds.size.x / num_bands;
float remaining = bandwidth;
stackUnsigned8 band = 0;
for (int posx=0; posx < leds.size.x; posx++) {
if (remaining < 1) {band++; remaining += bandwidth;} //increase remaining but keep the current remaining
remaining--; //consume remaining

int hue = wledAudioMod->fftResults[map(band, 0, num_bands-1, 0, 15)];
int v = map(hue, 0, 255, 10, 255);
leds.setPixelColor(leds.XY(posx, 0), CHSV(hue, 255, v));
}

// Update the display:
for (int i = (rows - 1); i > 0; i--) {
for (int j = (cols - 1); j >= 0; j--) {
// drip down:
for (int i = (leds.size.y - 1); i > 0; i--) {
for (int j = (leds.size.x - 1); j >= 0; j--) {
leds.setPixelColor(leds.XY(j, i), leds.getPixelColor(leds.XY(j, i-1)));
}
}

}

}

void controls(JsonObject parentVar) {
Expand Down
42 changes: 22 additions & 20 deletions src/App/LedFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@
#include "../Sys/SysStarModJson.h"
#include "../Sys/SysModPins.h"

Coord3D map1Dto2D(Coord3D in) {
Coord3D out;
out.x = sqrt(in.x * in.y * in.z); //only one is > 1, square root
out.y = out.x;
out.z = 0;
return out;
}
Coord3D map2Dto2D(Coord3D in) {
Coord3D out;
out.x = in.x;//in.x>1?in.x:in.y; //2 of the 3 sizes are > 1
out.y = in.y;//in.x>1?in.y:in.z;
out.z = in.z;//0;
out.x = in.x;
out.y = in.y;
out.z = in.z;
return out;
}

Expand Down Expand Up @@ -114,9 +107,9 @@ void Fixture::projectAndMap() {
//only needed one time
//does not work for some reason...

// if (indexP == 0) //first
if (indexP == 0) //first
{
stackUnsigned16 maxDistance = distance(endPosAdjusted, startPosAdjusted) / 10;
stackUnsigned16 maxDistance = distance(endPosAdjusted, startPosAdjusted) / 10 + 1;
// USER_PRINTF("maxDistance %d %d,%d,%d %d,%d,%d %d,%d,%d\n", maxDistance, pixel.x, pixel.y, pixel.z, startPosAdjusted.x, startPosAdjusted.y, startPosAdjusted.z, endPosAdjusted.x, endPosAdjusted.y, endPosAdjusted.z);

float scale = 1;
Expand All @@ -129,9 +122,10 @@ void Fixture::projectAndMap() {
case _2D:
switch(projectionDimension) {
case _1D:
leds->size = map1Dto2D(projSize);
// leds->size.x = sqrt(projSize.x * projSize.y * projSize.z); //only one is > 1, square root
// leds->size.y = leds->size.x;
//verified
leds->size.x = sqrt(projSize.x * projSize.y * projSize.z); //only one is > 1, square root
leds->size.y = projSize.x * projSize.y * projSize.z / leds->size.x;
leds->size.z = 1;
break;
case _2D:
if (leds->projectionNr == p_Multiply) {
Expand Down Expand Up @@ -184,6 +178,8 @@ void Fixture::projectAndMap() {

if (pixel >= startPosAdjusted && pixel <= endPosAdjusted ) { //if pixel between start and end pos

Coord3D pixelAdjusted = (pixel - startPosAdjusted)/10;

// if (leds->fx == 11) { //lines2D
// // USER_PRINTF(" XXX %d %d %d %d, %d, %d", leds->projectionNr, leds->effectDimension, projectionDimension, pixel.x, pixel.y, pixel.z);
// USER_PRINTF(" %d: %d,%d,%d", indexP, pixel.x, pixel.y, pixel.z);
Expand Down Expand Up @@ -219,8 +215,14 @@ void Fixture::projectAndMap() {
// }
}
else if (leds->effectDimension == _2D) {
if (projectionDimension == _1D)
indexV = leds->XYZ(map1Dto2D((pixel - startPosAdjusted)/10));
if (projectionDimension == _1D) {
//verified
Coord3D mapped;
mapped.x = (pixelAdjusted.x + pixelAdjusted.y) % leds->size.x;
mapped.y = (pixelAdjusted.x + pixelAdjusted.y) / leds->size.x;
mapped.z = 0;
indexV = leds->XYZ(mapped);
}
else if (projectionDimension == _2D) {
Coord3D mapped = map2Dto2D(pixel - startPosAdjusted) + Coord3D{5,5,5}; // add 0.5 for rounding
if (leds->projectionNr == p_Multiply) {
Expand Down Expand Up @@ -339,7 +341,7 @@ void Fixture::projectAndMap() {
if (!leds->mappingTable[indexV].indexes) {
leds->mappingTable[indexV].indexes = new std::vector<unsigned16>;
}
leds->mappingTable[indexV].indexes->push_back(indexP); //add the current led in the right physMap
leds->mappingTable[indexV].indexes->push_back(indexP); //add the current led to indexes
}
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);
Expand Down Expand Up @@ -421,7 +423,7 @@ void Fixture::projectAndMap() {
stackUnsigned16 indexV = 0;
for (auto map:leds->mappingTable) {
if (map.indexes && map.indexes->size()) {
// USER_PRINTF("ledV %d mapping: #ledsP (%d):", indexV, physMap->size());
// USER_PRINTF("ledV %d mapping: #ledsP (%d):", indexV, indexes->size());

for (forUnsigned16 indexP:*map.indexes) {
// USER_PRINTF(" %d", indexP);
Expand All @@ -437,7 +439,7 @@ void Fixture::projectAndMap() {
}
}

USER_PRINTF("projectAndMap [%d] V:%d x %d x %d = %d (v:%d - p:%d)\n", rowNr, leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds, nrOfMappings, nrOfPixels);
USER_PRINTF("projectAndMap [%d] V:%d x %d x %d -> %d (v:%d - p:%d)\n", rowNr, leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds, nrOfMappings, nrOfPixels);

// mdl->setValueV("fxSize", rowNr, "%d x %d x %d = %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds);
char buf[32];
Expand Down
38 changes: 18 additions & 20 deletions src/App/LedLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ void fastled_fill_rainbow(struct CRGB * targetArray, int numToFill, unsigned8 in
// maps the virtual led to the physical led(s) and assign a color to it
void Leds::setPixelColor(unsigned16 indexV, CRGB color, unsigned8 blendAmount) {
if (indexV < mappingTable.size()) {
std::vector<unsigned16>* physMap = mappingTable[indexV].indexes;
if (physMap) {
for (forUnsigned16 indexP:*physMap) {
if (mappingTable[indexV].indexes) {
for (forUnsigned16 indexP:*mappingTable[indexV].indexes) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount==UINT8_MAX?fixture->globalBlend:blendAmount);
}
}
Expand All @@ -43,9 +42,8 @@ void Leds::setPixelColor(unsigned16 indexV, CRGB color, unsigned8 blendAmount) {

CRGB Leds::getPixelColor(unsigned16 indexV) {
if (indexV < mappingTable.size()) {
std::vector<unsigned16>* physMap = mappingTable[indexV].indexes;
if (physMap && physMap->size())
return fixture->ledsP[*physMap->begin()]; //any would do as they are all the same
if (mappingTable[indexV].indexes && mappingTable[indexV].indexes->size())
return fixture->ledsP[*mappingTable[indexV].indexes->begin()]; //any would do as they are all the same
else
return mappingTable[indexV].color;
}
Expand All @@ -58,35 +56,35 @@ CRGB Leds::getPixelColor(unsigned16 indexV) {
}

void Leds::fadeToBlackBy(unsigned8 fadeBy) {
if (projectionNr == p_None || p_Random) {
if (projectionNr == p_None || projectionNr == p_Random) {
fastled_fadeToBlackBy(fixture->ledsP, fixture->nrOfLeds, fadeBy);
} else {
for (auto map:mappingTable) {
if (map.indexes)
for (forUnsigned16 indexP:*map.indexes) {
CRGB oldValue = fixture->ledsP[indexP];
fixture->ledsP[indexP].nscale8(255-fadeBy); //this overrides the old value
fixture->ledsP[indexP] = blend(fixture->ledsP[indexP], oldValue, fixture->globalBlend); // we want to blend in the old value
}
for (forUnsigned16 indexP:*map.indexes) {
CRGB oldValue = fixture->ledsP[indexP];
fixture->ledsP[indexP].nscale8(255-fadeBy); //this overrides the old value
fixture->ledsP[indexP] = blend(fixture->ledsP[indexP], oldValue, fixture->globalBlend); // we want to blend in the old value
}
}
}
}

void Leds::fill_solid(const struct CRGB& color) {
if (projectionNr == p_None || p_Random) {
if (projectionNr == p_None || projectionNr == p_Random) {
fastled_fill_solid(fixture->ledsP, fixture->nrOfLeds, color);
} else {
for (auto map:mappingTable) {
if (map.indexes)
for (forUnsigned16 indexP:*map.indexes) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], fixture->globalBlend);
}
for (forUnsigned16 indexP:*map.indexes) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], fixture->globalBlend);
}
}
}
}

void Leds::fill_rainbow(unsigned8 initialhue, unsigned8 deltahue) {
if (projectionNr == p_None || p_Random) {
if (projectionNr == p_None || projectionNr == p_Random) {
fastled_fill_rainbow(fixture->ledsP, fixture->nrOfLeds, initialhue, deltahue);
} else {
CHSV hsv;
Expand All @@ -96,9 +94,9 @@ void Leds::fill_rainbow(unsigned8 initialhue, unsigned8 deltahue) {

for (auto map:mappingTable) {
if (map.indexes)
for (forUnsigned16 indexP:*map.indexes) {
fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], fixture->globalBlend);
}
for (forUnsigned16 indexP:*map.indexes) {
fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], fixture->globalBlend);
}
hsv.hue += deltahue;
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/App/LedLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,12 @@ static Coord3D spinXY(uint_fast16_t x, uint_fast16_t y, uint_fast16_t width, uin
}

struct PhysMap {
// uint8_t isPhys = pot_none;
// bool isPhys = false; // 1 byte
// union {
std::vector<unsigned16> * indexes;
CRGB color;
// };
};

// }; // 4 bytes
}; // expected to be 5 bytes but is 8 bytes!!!

class Leds {

Expand All @@ -164,11 +163,12 @@ class Leds {
unsigned16 XY(unsigned16 x, unsigned16 y) {
return XYZ(x, y, 0);
}

unsigned16 XYZ(Coord3D coord) {
return XYZ(coord.x, coord.y, coord.z);
}
unsigned16 XYZ(unsigned16 x, unsigned16 y, unsigned16 z) {

unsigned16 XYZ(unsigned16 x, unsigned16 y, unsigned16 z) {
if (projectionNr == p_Rotate) {
Coord3D result = spinXY(x,y, size.x, size.y, proSpeed);
return result.x + result.y * size.x + result.z * size.x * size.y;
Expand All @@ -182,11 +182,8 @@ class Leds {
bool doMap = false;

Leds(Fixture &fixture) {
USER_PRINTF("Leds[%d] constructor\n", UINT8_MAX);
// this->rowNr = rowNr;
USER_PRINTF("Leds[%d] constructor %d\n", UINT8_MAX, sizeof(PhysMap));
this->fixture = &fixture;
// this->fx = 13;
// this->projectionNr = 2;
}

~Leds() {
Expand All @@ -196,7 +193,6 @@ class Leds {
for (auto map:mappingTable) {
if (map.indexes) {
map.indexes->clear();
// free(physMap);
delete map.indexes;
}
}
Expand Down

0 comments on commit d25876e

Please sign in to comment.