Skip to content

Commit

Permalink
Tune DNA effect, add phases, same on different sizes, use Speed_Flags
Browse files Browse the repository at this point in the history
pio.ini: set Speed_Flags

LedEffects: tune DNA

LedFixture and LedLeds and LedModEffects
- rename ledsList with projections
- replace auto with PhysMap
- add mirrors (WIP)

SysModModel: Coord3D/= : protect for /div0
  • Loading branch information
ewowi committed Mar 16, 2024
1 parent 7f43f94 commit e90be75
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 90 deletions.
23 changes: 12 additions & 11 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ lib_deps =
https://github.com/netmindz/WLED-sync#48cb28f11632b217f9ccd9f72149373919c28af5 ; sourceIP


[Speed_Flags]
build_flags =
-O2 ;; optimize for performance instead of size
;-ffast-math ;; gives a few (2-5) percent speedup on ESP32-S3, but causes slight slowdown on classic ESP32
-mtarget-align -free -fipa-pta ;; these are very useful, too
-fno-jump-tables -fno-tree-switch-conversion ;; needed
-freorder-blocks -Wwrite-strings -fstrict-volatile-bitfields ;; needed
build_unflags =
-Os ;; to disable standard optimization for size

[env]
framework = arduino
Expand All @@ -81,8 +90,11 @@ board_build.partitions = tools/WLED_ESP32_4MB_256KB_FS.csv ;; 1.8MB firmware,
board_build.filesystem = littlefs
board_build.f_flash = 80000000L ; use full 80MHz speed for flash (default = 40Mhz) - this is a fixed override from the board specs applicable for all env!!!
board_build.flash_mode = dio ; (dio = dual i/o; more compatible than qio = quad i/o)
build_unflags =
${Speed_Flags.build_unflags}
build_flags =
${starmod.build_flags}
${Speed_Flags.build_flags}
-DCONFIG_ASYNC_TCP_USE_WDT=0
-DLFS_THREADSAFE ;; enables use of semaphores in LittleFS driver
${STARMOD_APPMOD_LEDS.build_flags}
Expand All @@ -96,16 +108,6 @@ lib_deps =
; ${STARMOD_USERMOD_HA.lib_deps}
${STARMOD_USERMOD_WLEDAUDIO.lib_deps}

[Speed_Flags]
build_flags =
-O2 ;; optimize for performance instead of size
;-ffast-math ;; gives a few (2-5) percent speedup on ESP32-S3, but causes slight slowdown on classic ESP32
-mtarget-align -free -fipa-pta ;; these are very useful, too
-fno-jump-tables -fno-tree-switch-conversion ;; needed
-freorder-blocks -Wwrite-strings -fstrict-volatile-bitfields ;; needed
build_unflags =
-Os ;; to disable standard optimization for size


[env:esp32dev]
board = esp32dev ;https://github.com/platformio/platform-espressif32/blob/develop/boards/esp32dev.json
Expand All @@ -114,7 +116,6 @@ platform = [email protected] ;using platformio/framework-arduinoespressif32 @ ~3
upload_speed = 1500000
build_flags =
${env.build_flags}
; ${Speed_Flags.build_flags}
-DCONFIG_IDF_TARGET_ESP32=1
-DARDUINO_USB_CDC_ON_BOOT=0 ;; Make sure that the right HardwareSerial driver is picked in arduino-esp32 (needed on "classic ESP32")

Expand Down
16 changes: 11 additions & 5 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,28 +879,34 @@ class Lines: public Effect {
class DNA: public Effect {
const char * name() {return "DNA";}
unsigned8 dim() {return _2D;}
const char * tags() {return "💡";}
const char * tags() {return "💡💫";}

void loop(Leds &leds) {

CRGBPalette16 pal = getPalette();
stackUnsigned8 speed = mdl->getValue("speed");
stackUnsigned8 blur = mdl->getValue("blur");
stackUnsigned8 phases = mdl->getValue("phases");

leds.fadeToBlackBy(64);

for (int i = 0; i < leds.size.x; i++) {
leds.setPixelColor(leds.XY(i, beatsin8(speed, 0, leds.size.y-1, 0, i*4 )), ColorFromPalette(pal, i*5+now/17, beatsin8(5, 55, 255, 0, i*10), LINEARBLEND));
leds.setPixelColor(leds.XY(i, beatsin8(speed, 0, leds.size.y-1, 0, i*4+128)), ColorFromPalette(pal, i*5+128+now/17, beatsin8(5, 55, 255, 0, i*10+128), LINEARBLEND));
//256 is a complete phase
// half a phase is dna is 128
uint8_t phase = leds.size.x * i / 8;
//32: 4 * i
//16: 8 * i
phase = i * 127 / (leds.size.x-1) * phases / 64;
leds.setPixelColor(leds.XY(i, beatsin8(speed, 0, leds.size.y-1, 0, phase )), ColorFromPalette(pal, i*5+now/17, beatsin8(5, 55, 255, 0, i*10), LINEARBLEND));
leds.setPixelColor(leds.XY(i, beatsin8(speed, 0, leds.size.y-1, 0, phase+128)), ColorFromPalette(pal, i*5+128+now/17, beatsin8(5, 55, 255, 0, i*10+128), LINEARBLEND));
}
leds.blur2d(blur);

}

void controls(JsonObject parentVar) {
addPalette(parentVar, 4);
ui->initSlider(parentVar, "speed", 16, 0, 32);
ui->initSlider(parentVar, "blur", 128);
ui->initSlider(parentVar, "phases", 64);
}
}; // DNA

Expand Down
35 changes: 23 additions & 12 deletions src/App/LedFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ void Fixture::projectAndMap() {

// reset leds
stackUnsigned8 rowNr = 0;
for (Leds *leds: ledsList) {
for (Leds *leds: projections) {
if (leds->doMap) {
leds->fill_solid(CRGB::Black, true); //no blend

USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, ledsList.size());
USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, projections.size());
leds->size = Coord3D{0,0,0};
//vectors really gone now?
for (auto map:leds->mappingTable) {
for (PhysMap &map:leds->mappingTable) {
if (map.indexes) {
map.indexes->clear();
delete map.indexes;
Expand Down Expand Up @@ -78,7 +78,7 @@ void Fixture::projectAndMap() {
// USER_PRINTF("led %d,%d,%d start %d,%d,%d end %d,%d,%d\n",x,y,z, startPos.x, startPos.y, startPos.z, endPos.x, endPos.y, endPos.z);

stackUnsigned8 rowNr = 0;
for (Leds *leds: ledsList) {
for (Leds *leds: projections) {
if (leds->doMap) { //add pixel in leds mappingtable

//set start and endPos between bounderies of fixture
Expand Down Expand Up @@ -107,12 +107,15 @@ void Fixture::projectAndMap() {
else
proCenter = Coord3D{0,0,0};

Coord3D mirrors = Coord3D{0,0,0}; // no mirrors
if (leds->projectionNr == p_Multiply || leds->projectionNr == p_Preset1) {
Coord3D proMulti;
proMulti = mdl->getValue("proMulti", rowNr);
//promultu can be 0,0,0 but /= protects from /div0
sizeAdjusted /= proMulti; sizeAdjusted = sizeAdjusted.maximum(Coord3D{1,1,1}); //size min 1,1,1
proCenter /= proMulti;
pixelAdjusted = pixelAdjusted%sizeAdjusted;
mirrors = pixelAdjusted / sizeAdjusted;
pixelAdjusted = pixelAdjusted%sizeAdjusted; // pixel % size
// USER_PRINTF("Multiply %d,%d,%d\n", leds->size.x, leds->size.y, leds->size.z);
}

Expand All @@ -127,7 +130,7 @@ void Fixture::projectAndMap() {

Coord3D mapped;
switch (leds->effectDimension) {
case _1D: //1DxD
case _1D: //effectDimension 1DxD
if (leds->size == Coord3D{0,0,0}) { // first
leds->size.x = sizeAdjusted.distance(proCenter);
leds->size.y = 1;
Expand All @@ -138,6 +141,11 @@ void Fixture::projectAndMap() {
mapped.y = 0;
mapped.z = 0;

//reversed
if (mirrors.x %2 != 0) mapped.x = leds->size.x - 1 - mapped.x; // x mirrored
if (mirrors.y %2 != 0) mapped.y = leds->size.y - 1 - mapped.y; // y mirrored
if (mirrors.z %2 != 0) mapped.z = leds->size.z - 1 - mapped.z; // z mirrored

indexV = leds->XYZNoSpin(mapped);
break;
case _2D: //effectDimension
Expand All @@ -148,12 +156,15 @@ void Fixture::projectAndMap() {
leds->size.y = sizeAdjusted.x * sizeAdjusted.y * sizeAdjusted.z / leds->size.x;
leds->size.z = 1;
}
mapped.x = (pixelAdjusted.x + pixelAdjusted.y + pixelAdjusted.z) % leds->size.x;
mapped.y = (pixelAdjusted.x + pixelAdjusted.y + pixelAdjusted.z) / leds->size.x;
mapped.x = (pixelAdjusted.x + pixelAdjusted.y + pixelAdjusted.z) % leds->size.x; // only one > 0
mapped.y = (pixelAdjusted.x + pixelAdjusted.y + pixelAdjusted.z) / leds->size.x; // all rows next to each other
mapped.z = 0;
if (mirrors.x %2 != 0) mapped.x = leds->size.x - 1 - mapped.x; // x mirrored
if (mirrors.y %2 != 0) mapped.y = leds->size.y - 1 - mapped.y; // y mirrored
indexV = leds->XYZNoSpin(mapped);
break;
case _2D: //2D2D
//find the 2 axis
if (leds->size == Coord3D{0,0,0}) { // first
if (sizeAdjusted.x > 1) {
leds->size.x = sizeAdjusted.x;
Expand Down Expand Up @@ -304,7 +315,7 @@ void Fixture::projectAndMap() {
} //if x,y,z between start and endpos
} //leds->doMap
rowNr++;
} //ledsList
} //projections
indexP++; //also increase if no buffer created
} //if 1D-3D pixel
else { // end of leds array
Expand Down Expand Up @@ -346,9 +357,9 @@ void Fixture::projectAndMap() {
//after processing each led
stackUnsigned8 rowNr = 0;

for (Leds *leds: ledsList) {
for (Leds *leds: projections) {
if (leds->doMap) {
USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, ledsList.size());
USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, projections.size());

stackUnsigned16 nrOfMappings = 0;
stackUnsigned16 nrOfPixels = 0;
Expand All @@ -373,7 +384,7 @@ void Fixture::projectAndMap() {

//debug info + summary values
stackUnsigned16 indexV = 0;
for (auto map:leds->mappingTable) {
for (PhysMap &map:leds->mappingTable) {
if (map.indexes && map.indexes->size()) {
// if (nrOfMappings < 10 || map.indexes->size() - indexV < 10) //first 10 and last 10
// if (nrOfMappings%(leds->nrOfLeds/10+1) == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/App/LedFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Fixture {
unsigned8 fixtureNr = -1;
Coord3D size = {8,8,1};

std::vector<Leds *> ledsList; //virtual leds
std::vector<Leds *> projections; //virtual leds

Coord3D head = {0,0,0};

Expand Down
6 changes: 3 additions & 3 deletions src/App/LedLeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void Leds::fadeToBlackBy(unsigned8 fadeBy) {
if (projectionNr == p_None || projectionNr == p_Random) {
fastled_fadeToBlackBy(fixture->ledsP, fixture->nrOfLeds, fadeBy);
} else {
for (auto map:mappingTable) {
for (PhysMap &map:mappingTable) {
if (map.indexes)
for (forUnsigned16 indexP:*map.indexes) {
CRGB oldValue = fixture->ledsP[indexP];
Expand All @@ -74,7 +74,7 @@ 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) {
for (PhysMap &map:mappingTable) {
if (map.indexes)
for (forUnsigned16 indexP:*map.indexes) {
fixture->ledsP[indexP] = noBlend?color:blend(color, fixture->ledsP[indexP], fixture->globalBlend);
Expand All @@ -92,7 +92,7 @@ void Leds::fill_rainbow(unsigned8 initialhue, unsigned8 deltahue) {
hsv.val = 255;
hsv.sat = 240;

for (auto map:mappingTable) {
for (PhysMap &map:mappingTable) {
if (map.indexes)
for (forUnsigned16 indexP:*map.indexes) {
fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], fixture->globalBlend);
Expand Down
2 changes: 1 addition & 1 deletion src/App/LedLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class Leds {
USER_PRINTF("Leds[%d] destructor\n", UINT8_MAX);
fadeToBlackBy(100);
doMap = true; // so loop is not running while deleting
for (auto map:mappingTable) {
for (PhysMap &map:mappingTable) {
if (map.indexes) {
map.indexes->clear();
delete map.indexes;
Expand Down
Loading

0 comments on commit e90be75

Please sign in to comment.