Skip to content

Commit

Permalink
Add mid/centrePoint, projection refactor, Preset projection (all)
Browse files Browse the repository at this point in the history
app.js / index.htm: add Set MidPoint to canvas buttons

LedEffects: use fill_solid no blend

LedFixture: projectAndMap: refactor
- use fill_solid no blend
- use Coord3D{0,0,0} for first
- add support for p_Preset (WIP!!)
- rename projSize to sizeAdjusted
- multiply and centerpoint projection for all xDxD cases (WIP)
- combine switch case xDxD for size (first) and pixel
- make 2D2D post processing for distance more readable

LedsLeds
- projections: add p_Preset (WIP), remove fun
- XYZ, also rotate with p_Preset

LedModEffects
- projection: add p_Preset
- canvasData: process mid point
- fill_solid: add noBlend parameter for one time calls (not in loop)
  • Loading branch information
ewowi committed Mar 7, 2024
1 parent 05b9056 commit 0714c08
Show file tree
Hide file tree
Showing 11 changed files with 1,587 additions and 1,587 deletions.
7 changes: 7 additions & 0 deletions data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ function preview3D(canvasNode, buffer) {

gId("canvasButton1").innerText = "Set Start position";
gId("canvasButton2").innerText = "Set End position";
gId("canvasButton3").innerText = "Set Mid position";

//process canvas button click
gId("canvasButton1").addEventListener("click", function(){
Expand All @@ -205,6 +206,12 @@ function preview3D(canvasNode, buffer) {
requestJson(command);
gId("canvasMenu").style.display = "none";
}, false);
gId("canvasButton3").addEventListener("click", function(){
var command = {};
command["canvasData"] = "mid:" + gId("canvasData").innerText;
requestJson(command);
gId("canvasMenu").style.display = "none";
}, false);

} //new

Expand Down
2 changes: 1 addition & 1 deletion data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h2><div id="instanceName"></div></h2>
<div id="canvasMenu" style="position:absolute;display:none"> <!--;background-color:#b60f62-->
<p><button id="canvasButton1"></button></p>
<p><button id="canvasButton2"></button></p>
<p><button id="canvasButton3">Add Effect</button></p>
<p><button id="canvasButton3"></button></p>
<span id="canvasData" hidden="true"></span>
</div>
</body>
Expand Down
3 changes: 0 additions & 3 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {
}
else
labelNode.innerText = initCap(variable.id); // the default when not overridden by uiFun
// if (variable.id == "proSplit" && parentNode.className == "ndiv") {
// // findParent(model, variable.id);
// }

divNode = cE("div");
divNode.id = variable.id + (rowNr != UINT8_MAX?"#" + rowNr:"") + "_d";
Expand Down
4 changes: 2 additions & 2 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ class DJLight:public Effect {
const char * tags() {return "💡♫";}

void setup(Leds &leds) {
leds.fill_solid(CRGB::Black);
leds.fill_solid(CRGB::Black, true); //no blend
}

void loop(Leds &leds) {
Expand Down Expand Up @@ -1148,7 +1148,7 @@ class FunkyPlank:public Effect {
const char * tags() {return "💡💫♫";}

void setup(Leds &leds) {
leds.fill_solid(CRGB::Black);
leds.fill_solid(CRGB::Black, true); //no blend
}

void loop(Leds &leds) {
Expand Down
361 changes: 168 additions & 193 deletions src/App/LedFixture.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/App/LedLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ void Leds::fadeToBlackBy(unsigned8 fadeBy) {
}
}

void Leds::fill_solid(const struct CRGB& color) {
void Leds::fill_solid(const struct CRGB& color, bool noBlend) {
if (projectionNr == p_None || projectionNr == p_Random) {
fastled_fill_solid(fixture->ledsP, fixture->nrOfLeds, color);
} else {
for (auto map:mappingTable) {
if (map.indexes)
for (forUnsigned16 indexP:*map.indexes) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], fixture->globalBlend);
fixture->ledsP[indexP] = noBlend?color:blend(color, fixture->ledsP[indexP], fixture->globalBlend);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/App/LedLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ enum Projections
p_Multiply,
p_Rotate,
p_DistanceFromPoint,
p_Preset,
p_None,
p_Random,
p_Fun,
p_Reverse,
p_Mirror,
p_Kaleidoscope,
Expand Down Expand Up @@ -154,7 +154,7 @@ class Leds {
unsigned8 projectionNr = -1;
unsigned8 effectDimension = -1;
Coord3D startPos = {0,0,0}, endPos = {UINT16_MAX,UINT16_MAX,UINT16_MAX}; //default
unsigned8 proSpeed = 128;
unsigned8 proRSpeed = 128;

SharedData sharedData;

Expand All @@ -169,8 +169,8 @@ class Leds {
}

unsigned16 XYZ(unsigned16 x, unsigned16 y, unsigned16 z) {
if (projectionNr == p_Rotate) {
Coord3D result = spinXY(x,y, size.x, size.y, proSpeed);
if (projectionNr == p_Rotate || projectionNr == p_Preset) {
Coord3D result = spinXY(x,y, size.x, size.y, proRSpeed);
return result.x + result.y * size.x + result.z * size.x * size.y;
}
else
Expand Down Expand Up @@ -249,7 +249,7 @@ class Leds {
void addPixelColor(Coord3D pixel, CRGB color) {setPixelColor(pixel, getPixelColor(pixel) + color);}

void fadeToBlackBy(unsigned8 fadeBy = 255);
void fill_solid(const struct CRGB& color);
void fill_solid(const struct CRGB& color, bool noBlend = false);
void fill_rainbow(unsigned8 initialhue, unsigned8 deltahue);
void blur2d(fract8 blur_amount)
{
Expand Down
71 changes: 42 additions & 29 deletions src/App/LedModEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ class LedModEffects:public SysModule {
options.add("Default");
options.add("Multiply");
options.add("Rotate");
options.add("Distance from point");
options.add("Distance from point ⌛");
options.add("Preset (WIP)");
options.add("None");
options.add("Random");
options.add("Fun");
options.add("Mirror WIP");
options.add("Reverse WIP");
options.add("Kaleidoscope WIP");
Expand All @@ -156,32 +156,39 @@ class LedModEffects:public SysModule {
fixture.ledsList[rowNr]->projectionNr = proValue;

mdl->varPreDetails(var, rowNr); //set all positive var N orders to negative
if (proValue == p_DistanceFromPoint) {
ui->initCoord3D(var, "proPoint", Coord3D{8,8,8}, 0, NUM_LEDS_Max);
// , [](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
// case f_ValueFun:
// mdl->setValue(var, eff->fixture.size);
// return true;
// case f_UIFun:
// ui->setLabel(var, "Size");
// return true;
// default: return false;
// }});
if (proValue == p_DistanceFromPoint || proValue == p_Preset) {
ui->initCoord3D(var, "proCenter", Coord3D{8,8,8}, 0, NUM_LEDS_Max, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "Center");
return true;
case f_ChangeFun:
//initiate projectAndMap
fixture.ledsList[rowNr]->doMap = true;
fixture.doMap = true;
// ui->setLabel(var, "Size");
return true;
default: return false;
}});
}
if (proValue == p_Multiply) {
ui->initCoord3D(var, "proSplit", Coord3D{2,2,1}, 0, 10, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
if (proValue == p_Multiply || proValue == p_Preset) {
ui->initCoord3D(var, "proMulti", Coord3D{2,2,1}, 0, 10, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "Multiply");
return true;
case f_ChangeFun:
fixture.ledsList[rowNr]->doMap = true;
fixture.doMap = true;
return true;
default: return false;
}});
}
if (proValue == p_Rotate) {
ui->initCoord3D(var, "proCenter", Coord3D{8,8,8}, 0, NUM_LEDS_Max);
ui->initSlider(var, "proSpeed", 128, 1, 255, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
if (proValue == p_Rotate || proValue == p_Preset) {
ui->initSlider(var, "proRSpeed", 128, 1, 255, false, [this](JsonObject var, unsigned8 rowNr, unsigned8 funType) { switch (funType) { //varFun
case f_UIFun:
ui->setLabel(var, "Rotation speed");
return true;
case f_ChangeFun:
fixture.ledsList[rowNr]->proSpeed = mdl->getValue(var, rowNr);
fixture.ledsList[rowNr]->proRSpeed = mdl->getValue(var, rowNr);
return true;
default: return false;
}});
Expand Down Expand Up @@ -358,21 +365,27 @@ class LedModEffects:public SysModule {

char * token = strtok((char *)canvasData, ":");
bool isStart = strcmp(token, "start") == 0;
bool isEnd = strcmp(token, "end") == 0;

Coord3D midCoord; //placeHolder for mid

Coord3D *startOrEndPos = isStart? &fixture.ledsList[0]->startPos: &fixture.ledsList[0]->endPos;
Coord3D *newCoord = isStart? &fixture.ledsList[0]->startPos: isEnd? &fixture.ledsList[0]->endPos : &midCoord;

token = strtok(NULL, ",");
if (token != NULL) startOrEndPos->x = atoi(token) / 10; else startOrEndPos->x = 0; //should never happen
token = strtok(NULL, ",");
if (token != NULL) startOrEndPos->y = atoi(token) / 10; else startOrEndPos->y = 0;
token = strtok(NULL, ",");
if (token != NULL) startOrEndPos->z = atoi(token) / 10; else startOrEndPos->z = 0;
if (newCoord) {
token = strtok(NULL, ",");
if (token != NULL) newCoord->x = atoi(token) / 10; else newCoord->x = 0; //should never happen
token = strtok(NULL, ",");
if (token != NULL) newCoord->y = atoi(token) / 10; else newCoord->y = 0;
token = strtok(NULL, ",");
if (token != NULL) newCoord->z = atoi(token) / 10; else newCoord->z = 0;

mdl->setValue(isStart?"fxStart":"fxEnd", *startOrEndPos, 0); //assuming row 0 for the moment
mdl->setValue(isStart?"fxStart":isEnd?"fxEnd":"proCenter", *newCoord, 0); //assuming row 0 for the moment

fixture.ledsList[0]->doMap = true; //recalc projection
fixture.doMap = true;
}

var.remove("canvasData"); //convasdata has been processed
fixture.ledsList[0]->doMap = true; //recalc projection
fixture.doMap = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/App/LedModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LedModFixture:public SysModule {
// ui->setComment(var, "Click to enlarge");
return true;
case f_LoopFun: {
var["interval"] = max(eff->fixture.nrOfLeds * web->ws->count()/200, 16U)*10; //interval in ms * 10, not too fast //from cs to ms
var["interval"] = max(eff->fixture.nrOfLeds * web->ws->count()/80, 16U)*10; //interval in ms * 10, not too fast //from cs to ms

web->sendDataWs([this](AsyncWebSocketMessageBuffer * wsBuf) {
byte* buffer;
Expand Down
Loading

0 comments on commit 0714c08

Please sign in to comment.