Skip to content

Commit

Permalink
set for loops and stack variables to unsigned (WIP)
Browse files Browse the repository at this point in the history
create stackUnsigned8 16 and 32

all for experiments and temporary, defines will go away eventually and be replaced by the optimal type
  • Loading branch information
ewowi committed Mar 4, 2024
1 parent 40170ef commit 176b9e8
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 227 deletions.
184 changes: 92 additions & 92 deletions src/App/LedEffects.h

Large diffs are not rendered by default.

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

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

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

unsigned16 indexP = 0;
unsigned16 prevIndexP = 0;
unsigned16 currPin;
stackUnsigned16 indexP = 0;
stackUnsigned16 prevIndexP = 0;
unsigned16 currPin; //lookFor needs u16

//what to deserialize
starModJson.lookFor("width", &size.x);
Expand All @@ -78,7 +78,7 @@ void Fixture::projectAndMap() {
//lookFor leds array and for each item in array call lambdo to make a projection
starModJson.lookFor("leds", [this, &prevIndexP, &indexP, &currPin](std::vector<unsigned16> uint16CollectList) { //this will be called for each tuple of coordinates!
// USER_PRINTF("funList ");
// for (unsigned16 num:uint16CollectList)
// for (forUnsigned16 num:uint16CollectList)
// USER_PRINTF(" %d", num);
// USER_PRINTF("\n");

Expand All @@ -93,7 +93,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).*$
unsigned8 rowNr = 0;
stackUnsigned8 rowNr = 0;
for (Leds *leds: ledsList) {
if (leds->doMap) {

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

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

//calculate the indexV to add to current physical led to
unsigned16 indexV = UINT16_MAX;
stackUnsigned16 indexV = UINT16_MAX;
switch(leds->projectionNr) {
case p_None:
break;
Expand Down Expand Up @@ -289,8 +289,8 @@ void Fixture::projectAndMap() {
case _2D:
float minDistance = 10;
// USER_PRINTF("checking indexV %d\n", indexV);
for (unsigned16 y=0; y<size.y && minDistance > 0.5; y++)
for (unsigned16 x=0; x<size.x && minDistance > 0.5; x++) {
for (forUnsigned16 y=0; y<size.y && minDistance > 0.5; y++)
for (forUnsigned16 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 Down Expand Up @@ -367,9 +367,9 @@ void Fixture::projectAndMap() {
char * before;
before = after;
after = strtok(NULL, " ");
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: LedModEffects:loop uses this to assign to FastLed
stackUnsigned16 startLed = atoi(before);
stackUnsigned16 nrOfLeds = atoi(after) - atoi(before) + 1;
print->fFormat(details, sizeof(details)-1, "%d-%d", min(prevIndexP, startLed), max((stackUnsigned16)(indexP - 1), nrOfLeds)); //careful: LedModEffects:loop uses this to assign to FastLed
USER_PRINTF("pins extend leds %d: %s\n", currPin, details);
//tbd: more check

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

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

unsigned8 rowNr = 0;
stackUnsigned8 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());

unsigned16 nrOfMappings = 0;
unsigned16 nrOfPixels = 0;
stackUnsigned16 nrOfMappings = 0;
stackUnsigned16 nrOfPixels = 0;

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

Expand All @@ -417,12 +417,12 @@ void Fixture::projectAndMap() {

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

unsigned16 indexV = 0;
stackUnsigned16 indexV = 0;
for (std::vector<unsigned16>* physMap:leds->mappingTable) {
if (physMap && physMap->size()) {
// USER_PRINTF("ledV %d mapping: #ledsP (%d):", indexV, physMap->size());

for (unsigned16 indexP:*physMap) {
for (forUnsigned16 indexP:*physMap) {
// USER_PRINTF(" %d", indexP);
nrOfPixels++;
}
Expand Down
8 changes: 4 additions & 4 deletions src/App/LedLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void Leds::setPixelColor(unsigned16 indexV, CRGB color, unsigned8 blendAmount) {
if (indexV < mappingTable.size()) {
std::vector<unsigned16>* physMap = mappingTable[indexV];
if (physMap)
for (unsigned16 indexP:*physMap) {
for (forUnsigned16 indexP:*physMap) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount==UINT8_MAX?fixture->globalBlend:blendAmount);
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ void Leds::fadeToBlackBy(unsigned8 fadeBy) {
} else {
for (std::vector<unsigned16>* physMap:mappingTable) {
if (physMap)
for (unsigned16 indexP:*physMap) {
for (forUnsigned16 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 @@ -74,7 +74,7 @@ void Leds::fill_solid(const struct CRGB& color) {
} else {
for (std::vector<unsigned16>* physMap:mappingTable) {
if (physMap)
for (unsigned16 indexP:*physMap) {
for (forUnsigned16 indexP:*physMap) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], fixture->globalBlend);
}
}
Expand All @@ -92,7 +92,7 @@ void Leds::fill_rainbow(unsigned8 initialhue, unsigned8 deltahue) {

for (std::vector<unsigned16>* physMap:mappingTable) {
if (physMap)
for (unsigned16 indexP:*physMap) {
for (forUnsigned16 indexP:*physMap) {
fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], fixture->globalBlend);
}
hsv.hue += deltahue;
Expand Down
18 changes: 9 additions & 9 deletions src/App/LedLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,17 @@ class Leds {

void blurRows(unsigned8 width, unsigned8 height, fract8 blur_amount)
{
/* for( unsigned8 row = 0; row < height; row++) {
/* for (forUnsigned8 row = 0; row < height; row++) {
CRGB* rowbase = leds + (row * width);
blur1d( rowbase, width, blur_amount);
}
*/
// blur rows same as columns, for irregular matrix
unsigned8 keep = 255 - blur_amount;
unsigned8 seep = blur_amount >> 1;
for( unsigned8 row = 0; row < height; row++) {
stackUnsigned8 keep = 255 - blur_amount;
stackUnsigned8 seep = blur_amount >> 1;
for (forUnsigned8 row = 0; row < height; row++) {
CRGB carryover = CRGB::Black;
for( unsigned8 i = 0; i < width; i++) {
for (forUnsigned8 i = 0; i < width; i++) {
CRGB cur = getPixelColor(XY(i,row));
CRGB part = cur;
part.nscale8( seep);
Expand All @@ -285,11 +285,11 @@ class Leds {
void blurColumns(unsigned8 width, unsigned8 height, fract8 blur_amount)
{
// blur columns
unsigned8 keep = 255 - blur_amount;
unsigned8 seep = blur_amount >> 1;
for( unsigned8 col = 0; col < width; ++col) {
stackUnsigned8 keep = 255 - blur_amount;
stackUnsigned8 seep = blur_amount >> 1;
for (forUnsigned8 col = 0; col < width; ++col) {
CRGB carryover = CRGB::Black;
for( unsigned8 i = 0; i < height; ++i) {
for (forUnsigned8 i = 0; i < height; ++i) {
CRGB cur = getPixelColor(XY(col,i));
CRGB part = cur;
part.nscale8( seep);
Expand Down
20 changes: 10 additions & 10 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class LedModEffects:public SysModule {

currentVar = ui->initSelect(tableVar, "fx", 0, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
for (unsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++)
for (forUnsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++)
mdl->setValue(var, fixture.ledsList[rowNr]->fx, rowNr);
return true;
case f_UIFun: {
Expand Down Expand Up @@ -121,7 +121,7 @@ class LedModEffects:public SysModule {

currentVar = ui->initSelect(tableVar, "pro", 2, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
for (unsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++)
for (forUnsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++)
mdl->setValue(var, fixture.ledsList[rowNr]->projectionNr, rowNr);
return true;
case f_UIFun: {
Expand All @@ -147,7 +147,7 @@ class LedModEffects:public SysModule {
if (rowNr < fixture.ledsList.size()) {
fixture.ledsList[rowNr]->doMap = true;

unsigned8 proValue = mdl->getValue(var, rowNr);
stackUnsigned8 proValue = mdl->getValue(var, rowNr);
fixture.ledsList[rowNr]->projectionNr = proValue;

mdl->varPreDetails(var, rowNr); //set all positive var N orders to negative
Expand Down Expand Up @@ -194,7 +194,7 @@ class LedModEffects:public SysModule {

ui->initCoord3D(tableVar, "fxStart", {0,0,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
for (unsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++) {
for (forUnsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++) {
USER_PRINTF("fxStart[%d] valueFun %d,%d,%d\n", rowNr, fixture.ledsList[rowNr]->startPos.x, fixture.ledsList[rowNr]->startPos.y, fixture.ledsList[rowNr]->startPos.z);
mdl->setValue(var, fixture.ledsList[rowNr]->startPos, rowNr);
}
Expand Down Expand Up @@ -222,7 +222,7 @@ class LedModEffects:public SysModule {

ui->initCoord3D(tableVar, "fxEnd", {8,8,0}, 0, NUM_LEDS_Max, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_ValueFun:
for (unsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++) {
for (forUnsigned8 rowNr = 0; rowNr < fixture.ledsList.size(); rowNr++) {
USER_PRINTF("fxEnd[%d] valueFun %d,%d,%d\n", rowNr, fixture.ledsList[rowNr]->endPos.x, fixture.ledsList[rowNr]->endPos.y, fixture.ledsList[rowNr]->endPos.z);
mdl->setValue(var, fixture.ledsList[rowNr]->endPos, rowNr);
}
Expand All @@ -248,10 +248,10 @@ class LedModEffects:public SysModule {
default: return false;
}});

ui->initText(tableVar, "fxSize", nullptr, 32, true, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
ui->initText(tableVar, "fxSize", nullptr, 32, true, [this](JsonObject var, stackUnsigned8 rowNr, stackUnsigned8 funType) { switch (funType) { //varFun
case f_ValueFun: {
// for (std::vector<Leds *>::iterator leds=fixture.ledsList.begin(); leds!=fixture.ledsList.end(); ++leds) {
unsigned8 rowNr = 0;
stackUnsigned8 rowNr = 0;
for (Leds *leds: fixture.ledsList) {
char message[32];
print->fFormat(message, sizeof(message)-1, "%d x %d x %d = %d", leds->size.x, leds->size.y, leds->size.z, leds->nrOfLeds);
Expand Down Expand Up @@ -324,7 +324,7 @@ class LedModEffects:public SysModule {
// run the next frame of the effect
// vector iteration on classes is faster!!! (22 vs 30 fps !!!!)
// for (std::vector<Leds *>::iterator leds=fixture.ledsList.begin(); leds!=fixture.ledsList.end(); ++leds) {
unsigned8 rowNr = 0;
stackUnsigned8 rowNr = 0;
for (Leds *leds: fixture.ledsList) {
if (!leds->doMap) { // don't run effect while remapping
// USER_PRINTF(" %d %d,%d,%d - %d,%d,%d (%d,%d,%d)", leds->fx, leds->startPos.x, leds->startPos.y, leds->startPos.z, leds->endPos.x, leds->endPos.y, leds->endPos.z, leds->size.x, leds->size.y, leds->size.z );
Expand Down Expand Up @@ -393,8 +393,8 @@ class LedModEffects:public SysModule {
before = after;
after = strtok(NULL, " ");

unsigned16 startLed = atoi(before);
unsigned16 nrOfLeds = atoi(after) - atoi(before) + 1;
stackUnsigned16 startLed = atoi(before);
stackUnsigned16 nrOfLeds = atoi(after) - atoi(before) + 1;
USER_PRINTF("FastLED.addLeds new %d: %d-%d\n", pinNr, startLed, nrOfLeds);

//commented pins: error: static assertion failed: Invalid pin specified
Expand Down
4 changes: 2 additions & 2 deletions src/App/LedModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class LedModFixture:public SysModule {
ui->setLabel(var, "Brightness");
return true;
case f_ChangeFun: {
unsigned8 bri = var["value"];
stackUnsigned8 bri = var["value"];

unsigned8 result = mdl->getValue("on").as<bool>()?linearToLogarithm(var, bri):0;
stackUnsigned8 result = mdl->getValue("on").as<bool>()?linearToLogarithm(var, bri):0;

FastLED.setBrightness(result);

Expand Down
Loading

0 comments on commit 176b9e8

Please sign in to comment.