Skip to content

Commit

Permalink
mapping: store color for pixels without a physical pixel
Browse files Browse the repository at this point in the history
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<PhysMap> mappingTable;
- sPC/gPC: use map, use map.color
  • Loading branch information
ewowi committed Mar 5, 2024
1 parent fbe785a commit 2af0386
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 12 additions & 11 deletions src/App/LedFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned16>* 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();
Expand Down Expand Up @@ -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<unsigned short> >&&)
leds->mappingTable.push_back(PhysMap()); //abort() was called at PC 0x40191473 on core 1 std::allocator<unsigned short> >&&)
}
}
//indexV is within the square
if (!leds->mappingTable[indexV])
leds->mappingTable[indexV] = new std::vector<unsigned16>;
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<unsigned16>;
}
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);
Expand Down Expand Up @@ -418,11 +419,11 @@ void Fixture::projectAndMap() {
leds->nrOfLeds = leds->mappingTable.size();

stackUnsigned16 indexV = 0;
for (std::vector<unsigned16>* 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++;
}
Expand Down
36 changes: 20 additions & 16 deletions src/App/LedLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,29 @@ 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];
if (physMap)
for (forUnsigned16 indexP:*physMap) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount==UINT8_MAX?fixture->globalBlend:blendAmount);
std::vector<unsigned16>* 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);
}

CRGB Leds::getPixelColor(unsigned16 indexV) {
if (indexV < mappingTable.size()) {
std::vector<unsigned16>* physMap = mappingTable[indexV];
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
else
return CRGB::Black;
return mappingTable[indexV].color;
}
else if (indexV < NUM_LEDS_Max) //no mapping
return fixture->ledsP[indexV];
Expand All @@ -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<unsigned16>* 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
Expand All @@ -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<unsigned16>* 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);
}
}
Expand All @@ -90,9 +94,9 @@ void Leds::fill_rainbow(unsigned8 initialhue, unsigned8 deltahue) {
hsv.val = 255;
hsv.sat = 240;

for (std::vector<unsigned16>* 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;
Expand Down
19 changes: 12 additions & 7 deletions src/App/LedLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned16> * indexes;
CRGB color;
// };
};


class Leds {
Expand All @@ -154,7 +159,7 @@ class Leds {

SharedData sharedData;

std::vector<std::vector<unsigned16> *> mappingTable;
std::vector<PhysMap> mappingTable;

unsigned16 XY(unsigned16 x, unsigned16 y) {
return XYZ(x, y, 0);
Expand Down Expand Up @@ -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<unsigned16>* 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();
Expand Down

0 comments on commit 2af0386

Please sign in to comment.