Skip to content

Commit

Permalink
Refactor LedFixGen, add Wall2D, str sizeof()-1
Browse files Browse the repository at this point in the history
General
- chars 2, 4, 8, 16, 32, ... bytes 
- strncpy etc with sizeof()-1

App.js: factor is fixed 10 (from mm to cm)

AppLedsV: 
- remove factor
- factor fixed 10
- if multiple leds to same pin, extend detail of pin

AppModLedFixGen
- remove factor -> fixed 10
- move stuff to GenFix class
- remove assign
- add open / close functions for header and pin
- add write2D/3D
- add 2DWall
- calculate whd and nrofleds and write to begin of file (using temp.json, better solution welcome) 

AppModLeds: fps default to 120
  • Loading branch information
ewowi committed Aug 14, 2023
1 parent 5863f99 commit 7389054
Show file tree
Hide file tree
Showing 15 changed files with 799 additions and 691 deletions.
6 changes: 3 additions & 3 deletions data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function userFun(userFunId, data) {
//replace the canvas: in case we switch from 2D to 3D as they cannot be reused between them
if (jsonValues.pview.new)
{
console.log("replace the canvas!")
console.log("replace the canvas!", jsonValues.pview);
let canvasNode = cE("canvas");
canvasNode.width = pviewNode.width;
canvasNode.height = pviewNode.height;
Expand Down Expand Up @@ -51,7 +51,7 @@ function userFun(userFunId, data) {
function preview2D(node, leds) {
let ctx = node.getContext('2d');
let i = 4;
let factor = jsonValues.pview.factor;
let factor = 10;//fixed value: from mm to cm
ctx.clearRect(0, 0, node.width, node.height);
if (jsonValues.pview) {
let pPL = Math.min(node.width / jsonValues.pview.width, node.height / jsonValues.pview.height); // pixels per LED (width of circle)
Expand Down Expand Up @@ -90,7 +90,7 @@ function preview3D(node, leds) {
// let mH = leds[1];
// let mD = leds[2];

let factor = jsonValues.pview.factor;
let factor = 10;//fixed value: from mm to cm
let d = 5 / factor; //distanceLED;

if (!renderer || (jsonValues.pview && jsonValues.pview.new)) { //init 3D
Expand Down
60 changes: 43 additions & 17 deletions src/App/AppLedsV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ uint16_t LedsV::nrOfLedsV = 64; //amount of virtual leds (calculated by project
uint16_t LedsV::widthP = 8;
uint16_t LedsV::heightP = 8;
uint16_t LedsV::depthP = 1;
uint16_t LedsV::factorP = 8;
uint16_t LedsV::widthV = 8;
uint16_t LedsV::heightV = 8;
uint16_t LedsV::depthV = 1;
Expand All @@ -35,12 +34,16 @@ uint8_t LedsV::fxDimension = -1;

//load ledfix json file, parse it and depending on the projection, create a mapping for it
void LedsV::ledFixProjectAndMap() {
char fileName[30] = "";
char fileName[32] = "";

if (files->seqNrToName(fileName, ledFixNr)) {
JsonRDWS jrdws(fileName); //open fileName for deserialize

mappingTableLedCounter = 0;

//vectors really gone now?
for (std::vector<uint16_t> physMap: mappingTable)
physMap.clear();
mappingTable.clear();

//deallocate all led pins
Expand All @@ -60,7 +63,6 @@ void LedsV::ledFixProjectAndMap() {
jrdws.lookFor("width", &widthP);
jrdws.lookFor("height", &heightP);
jrdws.lookFor("depth", &depthP);
jrdws.lookFor("factor", &factorP);
jrdws.lookFor("nrOfLeds", &nrOfLedsP);
jrdws.lookFor("pin", &currPin);

Expand All @@ -75,11 +77,11 @@ void LedsV::ledFixProjectAndMap() {

if (ledFixDimension>=1 && ledFixDimension<=3) { //we only comprehend 1D, 2D, 3D

uint16_t x = uint16CollectList[0] / LedsV::factorP;
uint16_t y = (ledFixDimension>=2)?(uint16CollectList[1] / LedsV::factorP) : 1;
uint16_t z = (ledFixDimension>=3)?(uint16CollectList[2] / LedsV::factorP): 1;
uint16_t x = uint16CollectList[0] / 10;
uint16_t y = (ledFixDimension>=2)?uint16CollectList[1] / 10 : 1;
uint16_t z = (ledFixDimension>=3)?uint16CollectList[2] / 10 : 1;

// print->print("projectionNr p:%d f:%d s:%d\n", LedsV::projectionNr, LedsV::fxDimension, ledFixDimension);
// print->print("projectionNr p:%d f:%d s:%d, %d-%d-%d %d-%d-%d\n", LedsV::projectionNr, LedsV::fxDimension, ledFixDimension, x, y, z, uint16CollectList[0], uint16CollectList[1], uint16CollectList[2]);
if (LedsV::projectionNr == p_DistanceFromPoint || LedsV::projectionNr == p_DistanceFromCentre) {
uint16_t bucket;// = -1;
if (LedsV::fxDimension == 1) { //if effect is 1D
Expand All @@ -90,17 +92,19 @@ void LedsV::ledFixProjectAndMap() {
pointY = 0;
pointZ = 0;
} else {
pointX = LedsV::factorP * LedsV::widthP / 2;
pointY = LedsV::factorP * LedsV::heightP / 2;
pointZ = LedsV::factorP * LedsV::depthP / 2;
pointX = LedsV::widthP / 2;
pointY = LedsV::heightP / 2;
pointZ = LedsV::depthP / 2;
}

if (ledFixDimension == 1) //ledfix is 1D
bucket = x;
else if (ledFixDimension == 2) //ledfix is 2D
bucket = distance(x,y,0,pointX,pointY,0) / LedsV::factorP;
else if (ledFixDimension == 2) {//ledfix is 2D
bucket = distance(x,y,0,pointX,pointY,0);
// print->print("bucket %d-%d %d-%d %d\n", x,y, pointX, pointY, bucket);
}
else if (ledFixDimension == 3) //ledfix is 3D
bucket = distance(x,y,z,pointX, pointY, pointZ) / LedsV::factorP;
bucket = distance(x,y,z,pointX, pointY, pointZ);

}
else if (LedsV::fxDimension == 2) { //effect is 2D
Expand Down Expand Up @@ -142,11 +146,33 @@ void LedsV::ledFixProjectAndMap() {
// delay(1); //feed the watchdog
mappingTableLedCounter++;
} //if 1D-3D
else {
else { // end of leds array

//check if pin already allocated, if so, extend range in details
PinObject pinObject = SysModPins::pinObjects[currPin];
char details[32] = "";
print->fFormat(details, sizeof(details), "%d-%d", prevLeds, mappingTableLedCounter - 1); //careful: AppModLeds:loop uses this to assign to FastLed
print->print("pins %d: %s (%d)\n", currPin, details);
pins->allocatePin(currPin, "Leds", details);
if (strcmp(pinObject.owner, "Leds") == 0) { //if owner

char * after = strtok((char *)pinObject.details, "-");
if (after != NULL ) {
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(prevLeds, startLed), max((uint16_t)(mappingTableLedCounter - 1), nrOfLeds)); //careful: AppModLeds:loop uses this to assign to FastLed
print->print("pins extend leds %d: %s (%d)\n", currPin, details);
//tbd: more check

strncpy(SysModPins::pinObjects[currPin].details, details, sizeof(PinObject::details)-1);
}
}
else {//allocate new pin
//tbd: check if free
print->fFormat(details, sizeof(details)-1, "%d-%d", prevLeds, mappingTableLedCounter - 1); //careful: AppModLeds:loop uses this to assign to FastLed
print->print("pins %d: %s (%d)\n", currPin, details);
pins->allocatePin(currPin, "Leds", details);
}

prevLeds = mappingTableLedCounter;
}
Expand Down
1 change: 0 additions & 1 deletion src/App/AppLedsV.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class LedsV {
static uint16_t widthP;
static uint16_t heightP;
static uint16_t depthP;
static uint16_t factorP;
static uint16_t widthV;
static uint16_t heightV;
static uint16_t depthV;
Expand Down
Loading

0 comments on commit 7389054

Please sign in to comment.