Skip to content

Commit

Permalink
add ledsV.blur2D . Frizzles2D working fine now
Browse files Browse the repository at this point in the history
pio.ini: comment build_type=debug (less flash)

AppEffects.h: replace blur2D by ledsV.blur2D

AppLedsV:
- rename NUM_LEDS_Preview to NUM_LEDS_Max
- add addPixelColor
- add blur2D, blurRows, blurColumns
  • Loading branch information
ewowi committed Jan 23, 2024
1 parent d17d9e1 commit fe6eb91
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ 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)
board_build.flash_mode = dio ; (dio = dual i/o; more compatible than qio = quad i/o)
build_type = debug
; build_type = debug ;increases flash size!
build_flags =
-DCONFIG_IDF_TARGET_ESP32=1
-DCONFIG_ASYNC_TCP_USE_WDT=0
Expand Down Expand Up @@ -91,7 +91,7 @@ monitor_speed = 115200
monitor_filters = esp32_exception_decoder
board_build.partitions = tools/WLED_ESP32_4MB_256KB_FS.csv ;; 1.8MB firmware, 256KB filesystem (esptool erase_flash needed when changing from "standard WLED" partitions)
board_build.filesystem = littlefs
build_type = debug
; build_type = debug ;increases flash size!
build_unflags =
; -DARDUINO_USB_CDC_ON_BOOT=1 ;; un-comment if you want to use a "real" serial-to-USB moddule
build_flags =
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class Frizzles2D: public Effect {
CRGB color = ColorFromPalette(palette, beatsin8(12, 0, 255), 255);
ledsV[XY(x,y)] = color;
}
blur2d(ledsV.ledsPhysical, ledsV.widthP, ledsV.heightP, mdl->getValue("blur")); //this is tricky as FastLed is not aware of our virtual
ledsV.blur2d(ledsV.widthV, ledsV.heightV, mdl->getValue("blur"));
}
bool controls(JsonObject parentVar) {
addPalette(parentVar);
Expand Down
13 changes: 9 additions & 4 deletions src/App/AppLedsV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ void LedsV::fixtureProjectAndMap() {

if (bucket != UINT16_MAX) { //can be nulled by inverse mapping
//add physical tables if not present
if (bucket >= NUM_LEDS_Preview) {
USER_PRINTF("mapping add physMap %d>=%d (%d) too big %d\n", bucket, NUM_LEDS_Preview, mappingTable.size(), UINT16_MAX);
if (bucket >= NUM_LEDS_Max) {
USER_PRINTF("mapping add physMap %d>=%d (%d) too big %d\n", bucket, NUM_LEDS_Max, mappingTable.size(), UINT16_MAX);
}
else {
//create new physMaps if needed
Expand Down Expand Up @@ -343,7 +343,7 @@ void LedsV::setPixelColor(int indexV, CRGB color) {
if (mappingTable.size()) {
if (indexV >= mappingTable.size()) return;
for (uint16_t indexP:mappingTable[indexV]) {
if (indexP < NUM_LEDS_Preview)
if (indexP < NUM_LEDS_Max)
ledsPhysical[indexP] = color;
}
}
Expand All @@ -354,14 +354,19 @@ void LedsV::setPixelColor(int indexV, CRGB color) {
CRGB LedsV::getPixelColor(int indexV) {
if (mappingTable.size()) {
if (indexV >= mappingTable.size()) return CRGB::Black;
if (!mappingTable[indexV].size() || mappingTable[indexV][0] > NUM_LEDS_Preview) return CRGB::Black;
if (!mappingTable[indexV].size() || mappingTable[indexV][0] > NUM_LEDS_Max) return CRGB::Black;

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

void LedsV::addPixelColor(int indexV, CRGB color) {
setPixelColor(indexV, getPixelColor(indexV) + color);
}


// LedsV& operator+=(const CRGB color) {
// setPixelColor(indexVLocal, getPixelColor(indexVLocal) + color);
// return *this;
Expand Down
60 changes: 58 additions & 2 deletions src/App/AppLedsV.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "ArduinoJson.h"
#include "../Sys/SysModModel.h" //for Coord3D

#define NUM_LEDS_Preview 4096
#define NUM_LEDS_Max 4096

enum Projections
{
Expand All @@ -42,7 +42,7 @@ class LedsV {

public:
// CRGB *leds = nullptr;
CRGB ledsPhysical[NUM_LEDS_Preview];
CRGB ledsPhysical[NUM_LEDS_Max];
// if (!leds)
// leds = (CRGB*)calloc(nrOfLeds, sizeof(CRGB));
// else
Expand Down Expand Up @@ -103,6 +103,8 @@ class LedsV {

CRGB getPixelColor(int indexV);

void addPixelColor(int indexV, CRGB color);

LedsV& operator+=(const CRGB color) {
setPixelColor(indexVLocal, getPixelColor(indexVLocal) + color);
return *this;
Expand Down Expand Up @@ -152,6 +154,60 @@ class LedsV {
hsv.hue += deltahue;
}
}

void blur2d(uint8_t width, uint8_t height, fract8 blur_amount)
{
blurRows(width, height, blur_amount);
blurColumns(width, height, blur_amount);
}

void blurRows(uint8_t width, uint8_t height, fract8 blur_amount)
{
/* for( uint8_t row = 0; row < height; row++) {
CRGB* rowbase = leds + (row * width);
blur1d( rowbase, width, blur_amount);
}
*/
// blur rows same as columns, for irregular matrix
uint8_t keep = 255 - blur_amount;
uint8_t seep = blur_amount >> 1;
for( uint8_t row = 0; row < height; row++) {
CRGB carryover = CRGB::Black;
for( uint8_t i = 0; i < width; i++) {
CRGB cur = getPixelColor(XY(i,row));
CRGB part = cur;
part.nscale8( seep);
cur.nscale8( keep);
cur += carryover;
if( i) addPixelColor(XY(i-1,row), part);
setPixelColor(XY(i,row), cur);
carryover = part;
}
}
}

// blurColumns: perform a blur1d on each column of a rectangular matrix
void blurColumns(uint8_t width, uint8_t height, fract8 blur_amount)
{
// blur columns
uint8_t keep = 255 - blur_amount;
uint8_t seep = blur_amount >> 1;
for( uint8_t col = 0; col < width; ++col) {
CRGB carryover = CRGB::Black;
for( uint8_t i = 0; i < height; ++i) {
CRGB cur = getPixelColor(XY(col,i));
CRGB part = cur;
part.nscale8( seep);
cur.nscale8( keep);
cur += carryover;
if( i) addPixelColor(XY(col,i-1), part);
setPixelColor(XY(col,i), cur);
carryover = part;
}
}
}


private:
std::vector<std::vector<uint16_t>> mappingTable;
uint16_t mappingTableLedCounter;
Expand Down
4 changes: 2 additions & 2 deletions src/App/AppModFixtureGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,10 @@ class AppModFixtureGen:public SysModule {
uint8_t value = var["value"];

if (value == f_1DSpiral) {
ui->initNumber(parentVar, "ledCount", 64, 1, NUM_LEDS_Preview);
ui->initNumber(parentVar, "ledCount", 64, 1, NUM_LEDS_Max);
}
else if (value == f_2DRing) {
ui->initNumber(parentVar, "ledCount", 24, 1, NUM_LEDS_Preview);
ui->initNumber(parentVar, "ledCount", 24, 1, NUM_LEDS_Max);
}
else if (value == f_2DRings241) {
ui->initCheckBox(parentVar, "in2out", true);
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class AppModLeds:public SysModule {
char details[32] = "";
print->fFormat(details, sizeof(details)-1, "P:%d V:%d", ledsV.nrOfLedsP, ledsV.nrOfLedsV);
web->addResponse(var["id"], "value", details);
web->addResponseV(var["id"], "comment", "Max %d", NUM_LEDS_Preview);
web->addResponseV(var["id"], "comment", "Max %d", NUM_LEDS_Max);
});

ui->initNumber(parentVar, "fps", fps, 1, 999, false, [](JsonObject var) { //uiFun
Expand Down

0 comments on commit fe6eb91

Please sign in to comment.