Skip to content

Commit

Permalink
Checkerboard & Spacing Projection
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon502 committed Aug 14, 2024
1 parent cf9de68 commit de7a7a5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/App/LedLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum ProjectionsE
p_Kaleidoscope,
p_Scrolling,
p_Acceleration,
p_Checkerboard,
p_count // keep as last entry
};

Expand Down
1 change: 1 addition & 0 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class LedModEffects:public SysModule {
fixture.projections.push_back(new KaleidoscopeProjection);
fixture.projections.push_back(new ScrollingProjection);
fixture.projections.push_back(new AccelerationProjection);
fixture.projections.push_back(new CheckerboardProjection);

#ifdef STARLIGHT_CLOCKLESS_LED_DRIVER
#if !(CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2)
Expand Down
92 changes: 92 additions & 0 deletions src/App/LedProjections.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,38 @@ class SpacingProjection: public Projection {
const char * name() {return "Spacing WIP";}
const char * tags() {return "💡";}

void setup(LedsLayer &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted, Coord3D &mapped, uint16_t &indexV) {
adjustSizeAndPixel(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted);
DefaultProjection dp;
dp.setup(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted, mapped, indexV);
}

void adjustSizeAndPixel(LedsLayer &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) {
// UI Variables
leds.projectionData.begin();
Coord3D spacing = leds.projectionData.read<Coord3D>();

// ppf ("pixel: %d,%d,%d -> ", pixelAdjusted.x, pixelAdjusted.y, pixelAdjusted.z);
spacing = spacing.maximum(Coord3D{0, 0, 0}) + Coord3D{1,1,1}; // {1, 1, 1} is the minimum value

if (pixelAdjusted % spacing == Coord3D{0,0,0}) pixelAdjusted /= spacing;
else pixelAdjusted = Coord3D{UINT16_MAX, UINT16_MAX, UINT16_MAX};

// ppf ("%d,%d,%d\n", pixelAdjusted.x, pixelAdjusted.y, pixelAdjusted.z);

sizeAdjusted = (sizeAdjusted + spacing - Coord3D{1,1,1}) / spacing; // round up
midPosAdjusted /= spacing;
}

void controls(LedsLayer &leds, JsonObject parentVar) {
leds.projectionData.reset();
Coord3D *spacing = leds.projectionData.write<Coord3D>({1,1,1});
ui->initCoord3D(parentVar, "Spacing", spacing, 0, 100, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onChange:
leds.fixture->layers[rowNr]->triggerMapping();
return true;
default: return false;
}});
}
}; //SpacingProjection

Expand Down Expand Up @@ -770,6 +801,67 @@ class AccelerationProjection: public Projection {
}
}; //Acceleration

class CheckerboardProjection: public Projection {
const char * name() {return "Checkerboard";}
const char * tags() {return "💫";}

void setup(LedsLayer &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted, Coord3D &mapped, uint16_t &indexV) {
leds.projectionData.begin();
Coord3D size = leds.projectionData.read<Coord3D>();
bool invert = leds.projectionData.read<bool>();
bool group = leds.projectionData.read<bool>();
adjustSizeAndPixel(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted);
if (group) {GroupingProjection gp; gp.setup(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted, mapped, indexV);}
else {DefaultProjection dp; dp.setup(leds, sizeAdjusted, pixelAdjusted, midPosAdjusted, mapped, indexV);}
}

void adjustSizeAndPixel(LedsLayer &leds, Coord3D &sizeAdjusted, Coord3D &pixelAdjusted, Coord3D &midPosAdjusted) {
// UI Variables
leds.projectionData.begin();
Coord3D size = leds.projectionData.read<Coord3D>();
bool invert = leds.projectionData.read<bool>();

// ppf ("pixel: %d,%d,%d -> ", pixelAdjusted.x, pixelAdjusted.y, pixelAdjusted.z);
size = size.maximum(Coord3D{1, 1, 1}); // {1, 1, 1} is the minimum value

Coord3D check = pixelAdjusted / size;
if ((check.x + check.y + check.z) % 2 == 0) {
if (invert) pixelAdjusted = {UINT16_MAX, UINT16_MAX, UINT16_MAX};
}
else {
if (!invert) pixelAdjusted = {UINT16_MAX, UINT16_MAX, UINT16_MAX};
}

// ppf ("%d,%d,%d", pixelAdjusted.x, pixelAdjusted.y, pixelAdjusted.z);
// ppf (" Check: %d,%d,%d Even: %d\n", check.x, check.y, check.z, (check.x + check.y + check.z) % 2 == 0);
}

void controls(LedsLayer &leds, JsonObject parentVar) {
leds.projectionData.reset();
Coord3D *size = leds.projectionData.write<Coord3D>({3,3,3});
bool *invert = leds.projectionData.write<bool>(false);
bool *group = leds.projectionData.write<bool>(false);
ui->initCoord3D(parentVar, "Square Size", size, 0, 100, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onChange:
leds.fixture->layers[rowNr]->triggerMapping();
return true;
default: return false;
}});
ui->initCheckBox(parentVar, "Invert", invert, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onChange:
leds.fixture->layers[rowNr]->triggerMapping();
return true;
default: return false;
}});
ui->initCheckBox(parentVar, "Group", group, false, [&leds](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case onChange:
leds.fixture->layers[rowNr]->triggerMapping();
return true;
default: return false;
}});
}
}; //CheckerboardProjection

class TestProjection: public Projection {
const char * name() {return "Test";}
const char * tags() {return "💡";}
Expand Down

0 comments on commit de7a7a5

Please sign in to comment.