diff --git a/src/App/LedEffects.h b/src/App/LedEffects.h index 3ce3aac5..02e992fd 100644 --- a/src/App/LedEffects.h +++ b/src/App/LedEffects.h @@ -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; @@ -1145,7 +1145,7 @@ 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); @@ -1153,45 +1153,35 @@ class FunkyPlank:public Effect { 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) { diff --git a/src/App/LedFixture.cpp b/src/App/LedFixture.cpp index 1ba5330d..0541a05f 100644 --- a/src/App/LedFixture.cpp +++ b/src/App/LedFixture.cpp @@ -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; } @@ -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; @@ -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) { @@ -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); @@ -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) { @@ -339,7 +341,7 @@ void Fixture::projectAndMap() { if (!leds->mappingTable[indexV].indexes) { leds->mappingTable[indexV].indexes = new std::vector; } - 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); @@ -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); @@ -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]; diff --git a/src/App/LedLeds.cpp b/src/App/LedLeds.cpp index f7096cf0..85e4b060 100644 --- a/src/App/LedLeds.cpp +++ b/src/App/LedLeds.cpp @@ -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* 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); } } @@ -43,9 +42,8 @@ void Leds::setPixelColor(unsigned16 indexV, CRGB color, unsigned8 blendAmount) { CRGB Leds::getPixelColor(unsigned16 indexV) { if (indexV < mappingTable.size()) { - std::vector* 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; } @@ -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; @@ -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; } } diff --git a/src/App/LedLeds.h b/src/App/LedLeds.h index ee722d04..2e04e271 100644 --- a/src/App/LedLeds.h +++ b/src/App/LedLeds.h @@ -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 * indexes; CRGB color; - // }; -}; - + // }; // 4 bytes +}; // expected to be 5 bytes but is 8 bytes!!! class Leds { @@ -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; @@ -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() { @@ -196,7 +193,6 @@ class Leds { for (auto map:mappingTable) { if (map.indexes) { map.indexes->clear(); - // free(physMap); delete map.indexes; } }