From 2af0386be33bd3cb107b4bee8f12ccbf8bd5d48c Mon Sep 17 00:00:00 2001 From: Ewoud Date: Tue, 5 Mar 2024 14:44:39 +0100 Subject: [PATCH] mapping: store color for pixels without a physical pixel LedEffects: set FunkyPlank name, dim and tags LedFixture - use mappingTable map - add map.indexes and push indexP LedLeds - define PhysMap and use in std::vector mappingTable; - sPC/gPC: use map, use map.color --- src/App/LedEffects.h | 6 +++--- src/App/LedFixture.cpp | 23 ++++++++++++----------- src/App/LedLeds.cpp | 36 ++++++++++++++++++++---------------- src/App/LedLeds.h | 19 ++++++++++++------- 4 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/App/LedEffects.h b/src/App/LedEffects.h index 1b973ac1..3ce3aac5 100644 --- a/src/App/LedEffects.h +++ b/src/App/LedEffects.h @@ -1143,9 +1143,9 @@ class DJLight:public Effect { class FunkyPlank:public Effect { public: - const char * name() { - return "Funky Plank 2D"; - } + const char * name() {return "Funky Plank";} + unsigned8 dim() {return _2D;} + const char * tags() {return "💡♫";} void setup(Leds &leds) { leds.fill_solid(CRGB::Black); diff --git a/src/App/LedFixture.cpp b/src/App/LedFixture.cpp index 44ed78ad..1ba5330d 100644 --- a/src/App/LedFixture.cpp +++ b/src/App/LedFixture.cpp @@ -44,10 +44,10 @@ void Fixture::projectAndMap() { if (leds->doMap) { USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, ledsList.size()); //vectors really gone now? - for (std::vector* physMap:leds->mappingTable) { - if (physMap) { - physMap->clear(); - delete physMap; + for (auto map:leds->mappingTable) { + if (map.indexes) { + map.indexes->clear(); + delete map.indexes; } } leds->mappingTable.clear(); @@ -332,13 +332,14 @@ void Fixture::projectAndMap() { 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()); - leds->mappingTable.push_back(nullptr); //abort() was called at PC 0x40191473 on core 1 std::allocator >&&) + leds->mappingTable.push_back(PhysMap()); //abort() was called at PC 0x40191473 on core 1 std::allocator >&&) } } //indexV is within the square - if (!leds->mappingTable[indexV]) - leds->mappingTable[indexV] = new std::vector; - leds->mappingTable[indexV]->push_back(indexP); //add the current led in the right physMap + 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 } 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); @@ -418,11 +419,11 @@ void Fixture::projectAndMap() { leds->nrOfLeds = leds->mappingTable.size(); stackUnsigned16 indexV = 0; - for (std::vector* physMap:leds->mappingTable) { - if (physMap && physMap->size()) { + for (auto map:leds->mappingTable) { + if (map.indexes && map.indexes->size()) { // USER_PRINTF("ledV %d mapping: #ledsP (%d):", indexV, physMap->size()); - for (forUnsigned16 indexP:*physMap) { + for (forUnsigned16 indexP:*map.indexes) { // USER_PRINTF(" %d", indexP); nrOfPixels++; } diff --git a/src/App/LedLeds.cpp b/src/App/LedLeds.cpp index bc2ca181..f7096cf0 100644 --- a/src/App/LedLeds.cpp +++ b/src/App/LedLeds.cpp @@ -25,13 +25,17 @@ 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]; - if (physMap) - for (forUnsigned16 indexP:*physMap) { - fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount==UINT8_MAX?fixture->globalBlend:blendAmount); + std::vector* physMap = mappingTable[indexV].indexes; + if (physMap) { + for (forUnsigned16 indexP:*physMap) { + fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount==UINT8_MAX?fixture->globalBlend:blendAmount); + } + } + else { + mappingTable[indexV].color = color; } } - else if (indexV < NUM_LEDS_Max)//no projection + else if (indexV < NUM_LEDS_Max) //no projection fixture->ledsP[projectionNr==p_Random?random(fixture->nrOfLeds):indexV] = color; else USER_PRINTF(" dev sPC V:%d >= %d", indexV, NUM_LEDS_Max); @@ -39,11 +43,11 @@ void Leds::setPixelColor(unsigned16 indexV, CRGB color, unsigned8 blendAmount) { CRGB Leds::getPixelColor(unsigned16 indexV) { if (indexV < mappingTable.size()) { - std::vector* physMap = mappingTable[indexV]; + std::vector* physMap = mappingTable[indexV].indexes; if (physMap && physMap->size()) return fixture->ledsP[*physMap->begin()]; //any would do as they are all the same else - return CRGB::Black; + return mappingTable[indexV].color; } else if (indexV < NUM_LEDS_Max) //no mapping return fixture->ledsP[indexV]; @@ -57,9 +61,9 @@ void Leds::fadeToBlackBy(unsigned8 fadeBy) { if (projectionNr == p_None || p_Random) { fastled_fadeToBlackBy(fixture->ledsP, fixture->nrOfLeds, fadeBy); } else { - for (std::vector* physMap:mappingTable) { - if (physMap) - for (forUnsigned16 indexP:*physMap) { + 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 @@ -72,9 +76,9 @@ void Leds::fill_solid(const struct CRGB& color) { if (projectionNr == p_None || p_Random) { fastled_fill_solid(fixture->ledsP, fixture->nrOfLeds, color); } else { - for (std::vector* physMap:mappingTable) { - if (physMap) - for (forUnsigned16 indexP:*physMap) { + for (auto map:mappingTable) { + if (map.indexes) + for (forUnsigned16 indexP:*map.indexes) { fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], fixture->globalBlend); } } @@ -90,9 +94,9 @@ void Leds::fill_rainbow(unsigned8 initialhue, unsigned8 deltahue) { hsv.val = 255; hsv.sat = 240; - for (std::vector* physMap:mappingTable) { - if (physMap) - for (forUnsigned16 indexP:*physMap) { + for (auto map:mappingTable) { + if (map.indexes) + 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 a55b331a..ee722d04 100644 --- a/src/App/LedLeds.h +++ b/src/App/LedLeds.h @@ -132,8 +132,13 @@ static Coord3D spinXY(uint_fast16_t x, uint_fast16_t y, uint_fast16_t width, uin else return Coord3D{(unsigned16)x3, (unsigned16)y3, 0}; } - - +struct PhysMap { + // uint8_t isPhys = pot_none; + // union { + std::vector * indexes; + CRGB color; + // }; +}; class Leds { @@ -154,7 +159,7 @@ class Leds { SharedData sharedData; - std::vector *> mappingTable; + std::vector mappingTable; unsigned16 XY(unsigned16 x, unsigned16 y) { return XYZ(x, y, 0); @@ -188,11 +193,11 @@ class Leds { USER_PRINTF("Leds[%d] destructor\n", UINT8_MAX); fadeToBlackBy(100); doMap = true; // so loop is not running while deleting - for (std::vector* physMap:mappingTable) { - if (physMap) { - physMap->clear(); + for (auto map:mappingTable) { + if (map.indexes) { + map.indexes->clear(); // free(physMap); - delete physMap; + delete map.indexes; } } mappingTable.clear();