Skip to content

Commit

Permalink
Defines for unsigned8, unsigned16 and unsigned32
Browse files Browse the repository at this point in the history
Used to tune which types to use
  • Loading branch information
ewowi committed Mar 2, 2024
1 parent e77f88b commit d1b5bb2
Show file tree
Hide file tree
Showing 31 changed files with 589 additions and 563 deletions.
214 changes: 107 additions & 107 deletions src/App/AppEffects.h

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions src/App/AppFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ void Fixture::projectAndMap() {
StarModJson starModJson(fileName); //open fileName for deserialize

// for (std::vector<Leds *>::iterator leds=ledsList.begin(); leds!=ledsList.end() && leds->doMap; ++leds) {
uint8_t rowNr = 0;
unsigned8 rowNr = 0;
for (Leds *leds: ledsList) {
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<std::vector<uint16_t>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap)
for (std::vector<std::vector<unsigned16>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap)
physMap->clear();
leds->mappingTable.clear();
leds->sharedData.clear();
Expand All @@ -53,16 +53,16 @@ void Fixture::projectAndMap() {
}

//deallocate all led pins
uint8_t pinNr = 0;
unsigned8 pinNr = 0;
for (PinObject pinObject: pins->pinObjects) {
if (strcmp(pinObject.owner, "Leds") == 0)
pins->deallocatePin(pinNr, "Leds");
pinNr++;
}

uint16_t indexP = 0;
uint16_t prevIndexP = 0;
uint8_t currPin;
unsigned16 indexP = 0;
unsigned16 prevIndexP = 0;
unsigned16 currPin;

//what to deserialize
starModJson.lookFor("width", &size.x);
Expand All @@ -72,9 +72,9 @@ void Fixture::projectAndMap() {
starModJson.lookFor("pin", &currPin);

//lookFor leds array and for each item in array call lambdo to make a projection
starModJson.lookFor("leds", [this, &prevIndexP, &indexP, &currPin](std::vector<uint16_t> uint16CollectList) { //this will be called for each tuple of coordinates!
starModJson.lookFor("leds", [this, &prevIndexP, &indexP, &currPin](std::vector<unsigned16> uint16CollectList) { //this will be called for each tuple of coordinates!
// USER_PRINTF("funList ");
// for (uint16_t num:uint16CollectList)
// for (unsigned16 num:uint16CollectList)
// USER_PRINTF(" %d", num);
// USER_PRINTF("\n");

Expand All @@ -89,7 +89,7 @@ void Fixture::projectAndMap() {

//vector iterator needed to get the pointer to leds as we need to update leds, also vector iteration on classes is faster!!!
//search: ^(?=.*\bfor\b)(?=.*\b:\b).*$
uint8_t rowNr = 0;
unsigned8 rowNr = 0;
for (Leds *leds: ledsList) {
if (leds->doMap) {

Expand All @@ -99,7 +99,7 @@ void Fixture::projectAndMap() {
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;
unsigned8 projectionDimension = 0;
if (projSize.x > 1) projectionDimension++;
if (projSize.y > 1) projectionDimension++;
if (projSize.z > 1) projectionDimension++;
Expand All @@ -112,7 +112,7 @@ void Fixture::projectAndMap() {

// if (indexP == 0) //first
{
uint16_t maxDistance = distance(endPosAdjusted, startPosAdjusted) / 10;
unsigned16 maxDistance = distance(endPosAdjusted, startPosAdjusted) / 10;
// 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 Down Expand Up @@ -190,7 +190,7 @@ void Fixture::projectAndMap() {
Coord3D midPoint = (startPosAdjusted + endPosAdjusted) / 2;

//calculate the indexV to add to current physical led to
uint16_t indexV = UINT16_MAX;
unsigned16 indexV = UINT16_MAX;
switch(leds->projectionNr) {
case p_None:
break;
Expand Down Expand Up @@ -263,7 +263,7 @@ void Fixture::projectAndMap() {

USER_PRINTF(" %d,%d->%f,%f->%f,%f", pixel.x, pixel.y, sinf(pixel.x * TWO_PI / (float)(size.x-1)), cosf(pixel.x * TWO_PI / (float)(size.x-1)), xNew, yNew);

indexV = leds->XYZ({(uint16_t)xNew, (uint16_t)yNew, 0});
indexV = leds->XYZ({(unsigned16)xNew, (unsigned16)yNew, 0});
// USER_PRINTF("2D to 2D indexV %f %d %d x %d %d x %d\n", scale, indexV, x, y, size.x, size.y);
}
}
Expand All @@ -285,8 +285,8 @@ void Fixture::projectAndMap() {
case _2D:
float minDistance = 10;
// USER_PRINTF("checking indexV %d\n", indexV);
for (uint16_t y=0; y<size.y && minDistance > 0.5; y++)
for (uint16_t x=0; x<size.x && minDistance > 0.5; x++) {
for (unsigned16 y=0; y<size.y && minDistance > 0.5; y++)
for (unsigned16 x=0; x<size.x && minDistance > 0.5; x++) {

float xNew = sinf(x * TWO_PI / (float)(size.x-1)) * size.x;
float yNew = cosf(x * TWO_PI / (float)(size.x-1)) * size.y;
Expand All @@ -304,7 +304,7 @@ void Fixture::projectAndMap() {
// indexV = x+y*size.x;
// }

if (indexV == (uint8_t)xNew + (uint8_t)yNew * size.x) {
if (indexV == (unsigned8)xNew + (unsigned8)yNew * size.x) {
// USER_PRINTF(" found one %d => %d=%d+%d*%d (%f+%f*%d) [%f]\n", indexV, x+y*size.x, x,y, size.x, xNew, yNew, size.x, distance);
indexV = leds->XY(x, y);
minDistance = 0; // stop looking further
Expand All @@ -328,7 +328,7 @@ 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());
std::vector<uint16_t> physMap;
std::vector<unsigned16> physMap;
physMap.push_back(0);
leds->mappingTable.push_back(physMap); //abort() was called at PC 0x40191473 on core 1 std::allocator<unsigned short> >&&)
}
Expand Down Expand Up @@ -363,9 +363,9 @@ void Fixture::projectAndMap() {
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
unsigned16 startLed = atoi(before);
unsigned16 nrOfLeds = atoi(after) - atoi(before) + 1;
print->fFormat(details, sizeof(details)-1, "%d-%d", min(prevIndexP, startLed), max((unsigned16)(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

Expand All @@ -386,14 +386,14 @@ void Fixture::projectAndMap() {

if (starModJson.deserialize(false)) { //this will call above function parameter for each led

uint8_t rowNr = 0;
unsigned8 rowNr = 0;
// for (std::vector<Leds *>::iterator leds=ledsList.begin(); leds!=ledsList.end() && leds->doMap; ++leds) {
for (Leds *leds: ledsList) {
if (leds->doMap) {
USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, ledsList.size());

uint16_t nrOfMappings = 0;
uint16_t nrOfPixels = 0;
unsigned16 nrOfMappings = 0;
unsigned16 nrOfPixels = 0;

if (leds->projectionNr == p_Random || leds->projectionNr == p_None) {

Expand All @@ -406,19 +406,19 @@ void Fixture::projectAndMap() {
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;
std::vector<unsigned16> physMap;
physMap.push_back(0);
leds->mappingTable.push_back(physMap);
}

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

uint16_t indexV = 0;
for (std::vector<std::vector<uint16_t>>::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap) {
unsigned16 indexV = 0;
for (std::vector<std::vector<unsigned16>>::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap) {
if (physMap->size()) {
// USER_PRINTF("ledV %d mapping: #ledsP (%d):", indexV, physMap->size());

for (uint16_t indexP:*physMap) {
for (unsigned16 indexP:*physMap) {
// USER_PRINTF(" %d", indexP);
nrOfPixels++;
}
Expand Down
8 changes: 4 additions & 4 deletions src/App/AppFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Fixture {
// leds = (CRGB*)malloc(nrOfLeds * sizeof(CRGB));
// leds = (CRGB*)reallocarray

uint16_t nrOfLeds = 64; //amount of physical leds
uint8_t fixtureNr = -1;
unsigned16 nrOfLeds = 64; //amount of physical leds
unsigned8 fixtureNr = -1;
Coord3D size = {8,8,1};

std::vector<Leds *> ledsList; //virtual leds
Expand All @@ -50,15 +50,15 @@ class Fixture {
bool doMap = false;
bool doAllocPins = false;

uint8_t globalBlend = 128;
unsigned8 globalBlend = 128;

//load fixture json file, parse it and depending on the projection, create a mapping for it
void projectAndMap();

float distance(float x1, float y1, float z1, float x2, float y2, float z2) {
return sqrtf((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}
float distance(uint16_t x1, uint16_t y1, uint16_t z1, uint16_t x2, uint16_t y2, uint16_t z2) {
float distance(unsigned16 x1, unsigned16 y1, unsigned16 z1, unsigned16 x2, unsigned16 y2, unsigned16 z2) {
return distance(Coord3D{x1, y1, z1}, Coord3D{x2,y2,z2});
// return sqrtf((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}
Expand Down
26 changes: 13 additions & 13 deletions src/App/AppLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
#include "AppLeds.h"

//convenience functions to call fastled functions out of the Leds namespace (there naming conflict)
void fastled_fadeToBlackBy(CRGB* leds, uint16_t num_leds, uint8_t fadeBy) {
void fastled_fadeToBlackBy(CRGB* leds, unsigned16 num_leds, unsigned8 fadeBy) {
fadeToBlackBy(leds, num_leds, fadeBy);
}
void fastled_fill_solid( struct CRGB * targetArray, int numToFill, const struct CRGB& color) {
fill_solid(targetArray, numToFill, color);
}
void fastled_fill_rainbow(struct CRGB * targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue) {
void fastled_fill_rainbow(struct CRGB * targetArray, int numToFill, unsigned8 initialhue, unsigned8 deltahue) {
fill_rainbow(targetArray, numToFill, initialhue, deltahue);
}

// maps the virtual led to the physical led(s) and assign a color to it
void Leds::setPixelColor(uint16_t indexV, CRGB color, uint8_t blendAmount) {
void Leds::setPixelColor(unsigned16 indexV, CRGB color, unsigned8 blendAmount) {
if (mappingTable.size()) {
if (indexV >= mappingTable.size()) {
// USER_PRINTF(" dev sPC V:%d >= %d", indexV, mappingTable.size());
}
else {
for (uint16_t indexP:mappingTable[indexV]) {
for (unsigned16 indexP:mappingTable[indexV]) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount==UINT8_MAX?fixture->globalBlend:blendAmount);
}
}
Expand All @@ -40,7 +40,7 @@ void Leds::setPixelColor(uint16_t indexV, CRGB color, uint8_t blendAmount) {
USER_PRINTF(" dev sPC V:%d >= %d", indexV, NUM_LEDS_Max);
}

CRGB Leds::getPixelColor(uint16_t indexV) {
CRGB Leds::getPixelColor(unsigned16 indexV) {
if (mappingTable.size()) {
if (indexV >= mappingTable.size()) {
// USER_PRINTF(" dev gPC V %d >= %d", indexV, mappingTable.size());
Expand All @@ -63,12 +63,12 @@ CRGB Leds::getPixelColor(uint16_t indexV) {
}
}

void Leds::fadeToBlackBy(uint8_t fadeBy) {
void Leds::fadeToBlackBy(unsigned8 fadeBy) {
if (projectionNr == p_None || p_Random) {
fastled_fadeToBlackBy(fixture->ledsP, fixture->nrOfLeds, fadeBy);
} else {
for (std::vector<std::vector<uint16_t>>::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (uint16_t indexP:*physMap) {
for (std::vector<std::vector<unsigned16>>::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (unsigned16 indexP:*physMap) {
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 @@ -81,15 +81,15 @@ 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<std::vector<uint16_t>>::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (uint16_t indexP:*physMap) {
for (std::vector<std::vector<unsigned16>>::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (unsigned16 indexP:*physMap) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], fixture->globalBlend);
}
}
}
}

void Leds::fill_rainbow(uint8_t initialhue, uint8_t deltahue) {
void Leds::fill_rainbow(unsigned8 initialhue, unsigned8 deltahue) {
if (projectionNr == p_None || p_Random) {
fastled_fill_rainbow(fixture->ledsP, fixture->nrOfLeds, initialhue, deltahue);
} else {
Expand All @@ -98,8 +98,8 @@ void Leds::fill_rainbow(uint8_t initialhue, uint8_t deltahue) {
hsv.val = 255;
hsv.sat = 240;

for (std::vector<std::vector<uint16_t>> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (uint16_t indexP:*physMap) {
for (std::vector<std::vector<unsigned16>> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (unsigned16 indexP:*physMap) {
fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], fixture->globalBlend);
}
hsv.hue += deltahue;
Expand Down
Loading

0 comments on commit d1b5bb2

Please sign in to comment.