Skip to content

Commit

Permalink
Refactor 2DMatrix generator, add first 2D effect (Frizzkes2D)
Browse files Browse the repository at this point in the history
AppLedsV: 
- NUM_LEDS_Preview 4096
- projectionNr and ledFixNr as variables
- ledFixProjectAndMap without arguments

AppEffects
- add Frizzles2D (from WLED, modified, no sliders yet, only defaults)

AppModLedFixGen: 
- add width, height and depth to generated ledfix with user defined instead if fixed sizes (wip)
- replace 2DMatrix88 with 2DMatrix (using width and height), so we can make up to 64*64 panels (Hub75)
- Add generate button
- strcat dimension in the name (2DMatrix only yet)

AppModLeds
- Add Frizzles2D
- replace whd by dimensions text only
  • Loading branch information
ewoudwijma committed Jul 29, 2023
1 parent 118388b commit 847f9a9
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 110 deletions.
8 changes: 8 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
; @title StarMod
; @file platformio.ini
; @date 20230729
; @repo https://github.com/ewoudwijma/StarMod
; @Authors https://github.com/ewoudwijma/StarMod/commits/main
; @Copyright (c) 2023 Github StarMod Commit Authors
; @license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007

; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
Expand Down
24 changes: 23 additions & 1 deletion src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ class SphereMove3DEffect:public Effect {
}
}
}
}; // 3DSphereMove
}; // SphereMove3DEffect

class Frizzles2D:public Effect {
public:
const char * name() {
return "Frizzles2D";
}
void setup() {} //not implemented yet
void loop() {
fadeToBlackBy( ledsP, ledsV.nrOfLedsP, 16);
CRGBPalette16 palette = PartyColors_p;

for (size_t i = 8; i > 0; i--) {
uint8_t x = beatsin8(128/8 + i, 0, ledsV.width - 1);
uint8_t y = beatsin8(128/8 - i, 0, ledsV.height - 1);
CRGB color = ColorFromPalette(palette, beatsin8(12, 0, 255), 255);
ledsV[x + y * ledsV.width] = color;
}
// blur2d(ledsP, ledsV.width, ledsV.height, 255);
// SEGMENT.blur(SEGMENT.custom1>>3);

}
}; // Frizzles2D

static std::vector<Effect *> effects;
72 changes: 38 additions & 34 deletions src/App/AppLedsV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ uint16_t LedsV::width = 8;
uint16_t LedsV::height = 8;
uint16_t LedsV::depth = 1;

enum Projections
{
p_None,
p_Random,
p_DistanceFromPoint
};

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

if (files->seqNrToName(fileName, ledFixObject["value"])) {
if (files->seqNrToName(fileName, ledFixNr)) {
JsonRDWS jrdws(fileName); //open fileName for deserialize

mappingTableLedCounter = 0;
Expand All @@ -40,8 +47,7 @@ void LedsV::ledFixProjectAndMap(JsonObject ledFixObject, JsonObject projectionOb
jrdws.lookFor("depth", &depth);
jrdws.lookFor("nrOfLeds", &nrOfLedsP);

uint8_t projection = mdl->getValue("projection");
if (true || projectionObject["value"] != 0) { //not None
if (projectionNr > p_Random) { //0 and 1 (none, random have no mapping)
jrdws.lookFor("leds", [](std::vector<uint16_t> uint16CollectList) {
// print->print("funList ");
// for (uint16_t num:uint16CollectList)
Expand Down Expand Up @@ -78,47 +84,38 @@ void LedsV::ledFixProjectAndMap(JsonObject ledFixObject, JsonObject projectionOb
} //projection != 0
if (jrdws.deserialize()) { //find all the objects

if (true || projectionObject["value"] != 0) { //not None
if (projectionNr > p_Random) {
nrOfLedsV = mappingTable.size();

uint16_t x=0;
uint16_t y=0;
for (std::vector<uint16_t>physMap:mappingTable) {
print->print("led %d mapping: ", x);
for (uint16_t pos:physMap) {
print->print(" %d", pos);
y++;
}
print->print("\n");
x++;
}
// uint16_t x=0;
// uint16_t y=0;
// for (std::vector<uint16_t>physMap:mappingTable) {
// print->print("led %d mapping: ", x);
// for (uint16_t pos:physMap) {
// print->print(" %d", pos);
// y++;
// }
// print->print("\n");
// x++;
// }
}
else
nrOfLedsV = nrOfLedsP;

print->print("jrdws whd %d %d %d and P:%d V:%d\n", width, height, depth, nrOfLedsP, nrOfLedsV);

//at page refresh, done before these objects have been initialized...
mdl->setValueI("width", width);
// print->print("1.1\n");
mdl->setValueI("height", height);
// print->print("1.2\n");
mdl->setValueI("depth", depth);
// print->print("1.3\n");
mdl->setValueV("dimensions", "%dx%dx%d", ledsV.width, ledsV.height, ledsV.depth);
mdl->setValueV("nrOfLeds", "P:%d V:%d", nrOfLedsP, nrOfLedsV);

// print->print("1\n");

//send to pview a message to get file filename
JsonDocument *responseDoc = web->getResponseDoc();
responseDoc->clear(); //needed for deserializeJson?
JsonVariant responseVariant = responseDoc->as<JsonVariant>();
// print->print("2\n");

web->addResponse("pview", "file", fileName);
web->sendDataWs(responseVariant);
print->printJson("ledfix chFun send ws done", responseVariant); //during server startup this is not send to a client, so client refresh should also trigger this
// print->print("3\n");
} // if deserialize
} //if fileName
}
Expand All @@ -143,19 +140,26 @@ LedsV& LedsV::operator=(const CRGB color) {

// maps the virtual led to the physical led(s) and assign a color to it
void LedsV::setPixelColor(int indexV, CRGB color) {
// if (indexV > mappingTable.size()) return;
if (!mappingTable.size() || indexV >= mappingTable.size()) return;
for (uint16_t indexP:mappingTable[indexV]) {
if (indexP < NUM_LEDS_Preview)
ledsP[indexP] = color;
if (mappingTable.size()) {
if (indexV >= mappingTable.size()) return;
for (uint16_t indexP:mappingTable[indexV]) {
if (indexP < NUM_LEDS_Preview)
ledsP[indexP] = color;
}
}
else //no projection
ledsP[projectionNr==p_Random?random(nrOfLedsP):indexV] = color;
}

CRGB LedsV::getPixelColor(int indexV) {
if (!mappingTable.size() || indexV >= mappingTable.size()) return CRGB::Black;
if (!mappingTable[indexV].size() || mappingTable[indexV][0] > NUM_LEDS_Preview) return CRGB::Black;
if (mappingTable.size()) {
if (indexV >= mappingTable.size()) return CRGB::Black;
if (!mappingTable[indexV].size() || mappingTable[indexV][0] > NUM_LEDS_Preview) return CRGB::Black;

return ledsP[mappingTable[indexV][0]]; //any would do as they are all the same
return ledsP[mappingTable[indexV][0]]; //any would do as they are all the same
}
else //no projection
return ledsP[indexV];
}

// LedsV& operator+=(const CRGB color) {
Expand Down
14 changes: 12 additions & 2 deletions src/App/AppLedsV.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "ArduinoJson.h"

#define NUM_LEDS_FastLed 1024
#define NUM_LEDS_Preview 2000
#define NUM_LEDS_Preview 4096

//keep them global for the time being as FastLed effects refer to them and want to keep that code as unchanged as possible
//(so maybe move there?)
Expand All @@ -27,6 +27,13 @@ class LedsV {
public:
// CRGB *leds = nullptr;
CRGB ledsP[NUM_LEDS_Preview];
// if (!leds)
// leds = (CRGB*)calloc(nrOfLeds, sizeof(CRGB));
// else
// leds = (CRGB*)reallocarray(leds, nrOfLeds, sizeof(CRGB));
// if (leds) free(leds);
// leds = (CRGB*)malloc(nrOfLeds * sizeof(CRGB));
// leds = (CRGB*)reallocarray

static uint16_t nrOfLedsP; //amount of physical leds
static uint16_t nrOfLedsV; //amount of virtual leds (calculated by projection)
Expand All @@ -39,7 +46,10 @@ class LedsV {
static std::vector<std::vector<uint16_t>> mappingTable;
static uint16_t mappingTableLedCounter;

void ledFixProjectAndMap(JsonObject ledFixObject, JsonObject projectionObject);
uint8_t projectionNr = -1;
uint8_t ledFixNr = -1;

void ledFixProjectAndMap();

uint16_t indexVLocal = 0;

Expand Down
76 changes: 49 additions & 27 deletions src/App/AppModLedFixGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ class AppModLedFixGen:public Module {

parentObject = ui->initModule(parentObject, name);

ui->initText(parentObject, "width", nullptr, false, [](JsonObject object) { //uiFun
// web->addResponseV(object["id"], "comment", "Max %dK", 32);
});

ui->initText(parentObject, "height", nullptr, false, [](JsonObject object) { //uiFun
// web->addResponseV(object["id"], "comment", "Max %dK", 32);
});

ui->initText(parentObject, "depth", nullptr, false, [](JsonObject object) { //uiFun
// web->addResponseV(object["id"], "comment", "Max %dK", 32);
});

enum Fixtures
{
f_1DSpiral,
f_2DM88,
f_2DMatrix,
f_2DR24,
f_2DR35,
f_3DC885,
Expand All @@ -34,11 +46,11 @@ class AppModLedFixGen:public Module {
f_3DHumanSizedCube
};

ui->initSelect(parentObject, "ledFixGen", 3, false, [](JsonObject object) { //uiFun
ui->initSelect(parentObject, "ledFixGen", 0, false, [](JsonObject object) { //uiFun
web->addResponse(object["id"], "label", "Ledfix generator");
JsonArray select = web->addResponseA(object["id"], "select");
select.add("1DSpiral"); //0
select.add("2DMatrix88"); //1
select.add("2DMatrix"); //1
select.add("2DRing24"); //2
select.add("2DRing35"); //3
select.add("3DCube885"); //4
Expand All @@ -47,46 +59,59 @@ class AppModLedFixGen:public Module {
select.add("3DHumanSizedCube"); //7
}, [](JsonObject object) { //chFun

const char * name = "TT";
}); //ledFixGen

ui->initButton(parentObject, "generate", nullptr, [](JsonObject object) { //uiFun
// web->addResponse(object["id"], "comment", "All but model.json");
}, [](JsonObject object) {

uint8_t fix = mdl->getValue("ledFixGen").as<int>();

char name[32] = "TT";
uint16_t nrOfLeds = 64; //default
uint16_t diameter = 100; //in mm

uint16_t width = 0;
uint16_t height = 0;
uint16_t depth = 0;

uint8_t fix = object["value"];
switch (fix) {
case f_1DSpiral:
name = "1DSpiral";
strcpy(name, "1DSpiral");
nrOfLeds = 64;
break;
case f_2DM88:
name = "2DMatrix88";
nrOfLeds = 64;
case f_2DMatrix:
width = mdl->getValue("width");
height = mdl->getValue("height");
depth = 1;
nrOfLeds = width * height;
strcpy(name, "2DMatrix");
char post[10];
snprintf(post, sizeof(post), "%02d%02d", width, height);
strcat(name, post);
break;
case f_2DR24:
name = "2DRing24";
strcpy(name, "2DRing24");
nrOfLeds = 24;
break;
case f_2DR35:
name = "2DRing35";
strcpy(name, "2DRing35");
nrOfLeds = 35;
break;
case f_3DC885:
name = "3DCube885";
strcpy(name, "3DCube885");
nrOfLeds = 320;
break;
case f_3DC888:
name = "3DCube888";
strcpy(name, "3DCube888");
nrOfLeds = 512;
break;
case f_3DGlobe:
name = "3DGlobe";
strcpy(name, "3DGlobe");
nrOfLeds = 512;
break;
case f_3DHumanSizedCube:
name = "3DHumanSizedCube";
strcpy(name, "3DHumanSizedCube");
nrOfLeds = 2000;
break;
}
Expand Down Expand Up @@ -136,23 +161,20 @@ class AppModLedFixGen:public Module {
}
f.printf("]}]");
break;
case f_2DM88:
diameter = 8; //in cm

f.printf(",\"scale\":\"%s\"", "cm");
f.printf(",\"size\":%d", diameter);

width = 8;
height = 8;
depth = 1;
case f_2DMatrix:
f.printf(",\"width\":%d", width);
f.printf(",\"height\":%d", height);
f.printf(",\"depth\":%d", depth);

diameter = width; //in cm

f.printf(",\"scale\":\"%s\"", "cm");
f.printf(",\"size\":%d", diameter);

f.printf(",\"outputs\":[{\"pin\":10,\"leds\":[");
strcpy(sep,"");
for (uint8_t y = 0; y<8; y++)
for (uint16_t x = 0; x<8 ; x++) {
for (uint8_t y = 0; y<height; y++)
for (uint16_t x = 0; x<width ; x++) {
// width = max(width, x);
// height = max(height, y);
// depth = 1;
Expand Down Expand Up @@ -279,7 +301,7 @@ class AppModLedFixGen:public Module {

//reload ledfix select
ui->processUiFun("ledFix");
}); //ledFixGen
});

print->print("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed");
}
Expand Down
Loading

0 comments on commit 847f9a9

Please sign in to comment.