Skip to content

Commit

Permalink
Merge branch 'main' into FunkyPlank
Browse files Browse the repository at this point in the history
  • Loading branch information
netmindz committed Mar 4, 2024
2 parents 30b9513 + 40170ef commit e9a151a
Show file tree
Hide file tree
Showing 14 changed files with 1,506 additions and 1,418 deletions.
4 changes: 4 additions & 0 deletions data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// @license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
// @license For non GPL-v3 usage, commercial licenses must be purchased. Contact [email protected]

function appName() {
return "Led";
}

function userFun(data) {
let buffer = new Uint8Array(data);
if (buffer[0]==1 && jsonValues.pview) {
Expand Down
4 changes: 2 additions & 2 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function makeWS() {
else
changeHTMLView("vApp"); //default

gId("vApp").value = "Leds"; //tbd: should be set by server
gId("vApp").value = appName(); //tbd: should be set by server

//send request for uiFun
flushUIFunCommands();
Expand Down Expand Up @@ -221,7 +221,7 @@ function createHTML(json, parentNode = null, rowNr = UINT8_MAX) {
let helpNode = cE("a");
helpNode.innerText = "ⓘ";
helpNode.style="float: right;"
let initCapVarType = variable.type=="appmod"?"AppMod":variable.type=="usermod"?"UserMod":"SysMod";
let initCapVarType = variable.type=="appmod"?appName() + "Mod":variable.type=="usermod"?"UserMod":"SysMod";
helpNode.setAttribute('href', "https://ewowi.github.io/StarDocs/" + initCapVarType + "/" + initCapVarType + initCap(variable.id));
hgroupNode.appendChild(helpNode);

Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ build_flags =

; Compiler warnings FastLed:
; In file included from .pio/libdeps/esp32dev/FastLED/src/FastLED.h:75,
; from src/App/AppLeds.h:11,
; from src/App/AppModEffects.h:13,
; from src/App/LedLeds.h:11,
; from src/App/LedModEffects.h:13,
; from src/main.cpp:25:
; .pio/libdeps/esp32dev/FastLED/src/fastspi.h:157:23: note: #pragma message: No hardware SPI pins defined. All SPI access will default to bitbanged output
; # pragma message "No hardware SPI pins defined. All SPI access will default to bitbanged output"
Expand Down
85 changes: 83 additions & 2 deletions src/App/AppEffects.h → src/App/LedEffects.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
@title StarMod
@file AppEffects.h
@file LedEffects.h
@date 20240228
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
Expand Down Expand Up @@ -1048,6 +1048,87 @@ class FreqMatrix:public Effect {
}
};


class DJLight:public Effect {
public:

const char * name() {
return "DJLight 1D";
}

void setup(Leds &leds) {
leds.fill_solid(CRGB::Black);
}

void loop(Leds &leds) {

const int mid = leds.nrOfLeds / 2;

unsigned8 *aux0 = leds.sharedData.bind(aux0);

uint8_t *fftResult = wledAudioMod->fftResults;
float volumeSmth = wledAudioMod->volumeSmth;

unsigned8 speed = mdl->getValue("speed");
bool candyFactory = mdl->getValue("candyFactory").as<bool>();
unsigned8 fade = mdl->getValue("fade");


unsigned8 secondHand = (speed < 255) ? (micros()/(256-speed)/500 % 16) : 0;
if((speed > 254) || (*aux0 != secondHand)) { // WLEDMM allow run run at full speed
*aux0 = secondHand;

CRGB color = CRGB(0,0,0);
// color = CRGB(fftResult[15]/2, fftResult[5]/2, fftResult[0]/2); // formula from 0.13.x (10Khz): R = 3880-5120, G=240-340, B=60-100
if (!candyFactory) {
color = CRGB(fftResult[12]/2, fftResult[3]/2, fftResult[1]/2); // formula for 0.14.x (22Khz): R = 3015-3704, G=216-301, B=86-129
} else {
// candy factory: an attempt to get more colors
color = CRGB(fftResult[11]/2 + fftResult[12]/4 + fftResult[14]/4, // red : 2412-3704 + 4479-7106
fftResult[4]/2 + fftResult[3]/4, // green: 216-430
fftResult[0]/4 + fftResult[1]/4 + fftResult[2]/4); // blue: 46-216
if ((color.getLuma() < 96) && (volumeSmth >= 1.5f)) { // enhance "almost dark" pixels with yellow, based on not-yet-used channels
unsigned yello_g = (fftResult[5] + fftResult[6] + fftResult[7]) / 3;
unsigned yello_r = (fftResult[7] + fftResult[8] + fftResult[9] + fftResult[10]) / 4;
color.green += (uint8_t) yello_g / 2;
color.red += (uint8_t) yello_r / 2;
}
}

if (volumeSmth < 1.0f) color = CRGB(0,0,0); // silence = black

// make colors less "pastel", by turning up color saturation in HSV space
if (color.getLuma() > 32) { // don't change "dark" pixels
CHSV hsvColor = rgb2hsv_approximate(color);
hsvColor.v = min(max(hsvColor.v, (uint8_t)48), (uint8_t)204); // 48 < brightness < 204
if (candyFactory)
hsvColor.s = max(hsvColor.s, (uint8_t)204); // candy factory mode: strongly turn up color saturation (> 192)
else
hsvColor.s = max(hsvColor.s, (uint8_t)108); // normal mode: turn up color saturation to avoid pastels
color = hsvColor;
}
//if (color.getLuma() > 12) color.maximizeBrightness(); // for testing

//SEGMENT.setPixelColor(mid, color.fadeToBlackBy(map(fftResult[4], 0, 255, 255, 4))); // 0.13.x fade -> 180hz-260hz
uint8_t fadeVal = map(fftResult[3], 0, 255, 255, 4); // 0.14.x fade -> 216hz-301hz
if (candyFactory) fadeVal = constrain(fadeVal, 0, 176); // "candy factory" mode - avoid complete fade-out
leds.setPixelColor(mid, color.fadeToBlackBy(fadeVal));

for (int i = leds.nrOfLeds - 1; i > mid; i--) leds.setPixelColor(i, leds.getPixelColor(i-1)); // move to the left
for (int i = 0; i < mid; i++) leds.setPixelColor(i, leds.getPixelColor(i+1)); // move to the right

leds.fadeToBlackBy(fade);

}
}

void controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 255);
ui->initCheckBox(parentVar, "candyFactory", true);
ui->initSlider(parentVar, "fade", 4, 0, 10);
}
};

class FunkyPlank:public Effect {
public:
const char * name() {
Expand Down Expand Up @@ -1108,7 +1189,6 @@ class FunkyPlank:public Effect {
};



#endif // End Audio Effects

class Effects {
Expand Down Expand Up @@ -1141,6 +1221,7 @@ class Effects {
effects.push_back(new GEQEffect);
effects.push_back(new AudioRings);
effects.push_back(new FreqMatrix);
effects.push_back(new DJLight);
effects.push_back(new FunkyPlank);
#endif
}
Expand Down
29 changes: 16 additions & 13 deletions src/App/AppFixture.cpp → src/App/LedFixture.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
@title StarMod
@file AppFixture.cpp
@file LedFixture.cpp
@date 20240228
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
Expand All @@ -9,7 +9,7 @@
@license For non GPL-v3 usage, commercial licenses must be purchased. Contact [email protected]
*/

#include "AppFixture.h"
#include "LedFixture.h"

#include "../Sys/SysModFiles.h"
#include "../Sys/SysStarModJson.h"
Expand Down Expand Up @@ -44,8 +44,12 @@ void Fixture::projectAndMap() {
if (leds->doMap) {
USER_PRINTF("Leds pre [%d] f:%d p:%d s:%d\n", rowNr, leds->fx, leds->projectionNr, ledsList.size());
//vectors really gone now?
for (std::vector<std::vector<unsigned16>> ::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap)
physMap->clear();
for (std::vector<unsigned16>* physMap:leds->mappingTable) {
if (physMap) {
physMap->clear();
delete physMap;
}
}
leds->mappingTable.clear();
leds->sharedData.clear();
}
Expand Down Expand Up @@ -328,14 +332,13 @@ void Fixture::projectAndMap() {
if (indexV >= leds->mappingTable.size()) {
for (size_t i = leds->mappingTable.size(); i <= indexV; i++) {
// USER_PRINTF("mapping %d,%d,%d add physMap before %d %d\n", pixel.y, pixel.y, pixel.z, indexV, leds->mappingTable.size());
std::vector<unsigned16> physMap;
if (i != indexV)
physMap.push_back(0);
leds->mappingTable.push_back(physMap); //abort() was called at PC 0x40191473 on core 1 std::allocator<unsigned short> >&&)
leds->mappingTable.push_back(nullptr); //abort() was called at PC 0x40191473 on core 1 std::allocator<unsigned short> >&&)
}
}
//indexV is within the square
leds->mappingTable[indexV].push_back(indexP); //add the current led in the right physMap
if (!leds->mappingTable[indexV])
leds->mappingTable[indexV] = new std::vector<unsigned16>;
leds->mappingTable[indexV]->push_back(indexP); //add the current led in the right physMap
}
else
USER_PRINTF("dev post [%d] indexP too high %d>=%d or %d (p:%d m:%d) p:%d,%d,%d\n", rowNr, indexP, nrOfLeds, NUM_LEDS_Max, leds->mappingTable.size(), indexP, pixel.x, pixel.y, pixel.z);
Expand Down Expand Up @@ -366,7 +369,7 @@ void Fixture::projectAndMap() {
after = strtok(NULL, " ");
unsigned16 startLed = atoi(before);
unsigned16 nrOfLeds = atoi(after) - atoi(before) + 1;
print->fFormat(details, sizeof(details)-1, "%d-%d", min(prevIndexP, startLed), max((unsigned16)(indexP - 1), nrOfLeds)); //careful: AppModEffects:loop uses this to assign to FastLed
print->fFormat(details, sizeof(details)-1, "%d-%d", min(prevIndexP, startLed), max((unsigned16)(indexP - 1), nrOfLeds)); //careful: LedModEffects:loop uses this to assign to FastLed
USER_PRINTF("pins extend leds %d: %s\n", currPin, details);
//tbd: more check

Expand All @@ -375,7 +378,7 @@ void Fixture::projectAndMap() {
}
else {//allocate new pin
//tbd: check if free
print->fFormat(details, sizeof(details)-1, "%d-%d", prevIndexP, indexP - 1); //careful: AppModEffects:loop uses this to assign to FastLed
print->fFormat(details, sizeof(details)-1, "%d-%d", prevIndexP, indexP - 1); //careful: LedModEffects:loop uses this to assign to FastLed
USER_PRINTF("pins %d: %s\n", currPin, details);
pins->allocatePin(currPin, "Leds", details);
}
Expand Down Expand Up @@ -415,8 +418,8 @@ void Fixture::projectAndMap() {
leds->nrOfLeds = leds->mappingTable.size();

unsigned16 indexV = 0;
for (std::vector<std::vector<unsigned16>>::iterator physMap=leds->mappingTable.begin(); physMap!=leds->mappingTable.end(); ++physMap) {
if (physMap->size()) {
for (std::vector<unsigned16>* physMap:leds->mappingTable) {
if (physMap && physMap->size()) {
// USER_PRINTF("ledV %d mapping: #ledsP (%d):", indexV, physMap->size());

for (unsigned16 indexP:*physMap) {
Expand Down
4 changes: 2 additions & 2 deletions src/App/AppFixture.h → src/App/LedFixture.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
@title StarMod
@file AppFixture.h
@file LedFixture.h
@date 20240228
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
Expand All @@ -13,7 +13,7 @@

#include "../Sys/SysModModel.h" //for Coord3D

#include "AppLeds.h"
#include "LedLeds.h"

#define NUM_LEDS_Max 4096

Expand Down
43 changes: 18 additions & 25 deletions src/App/AppLeds.cpp → src/App/LedLeds.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
@title StarMod
@file AppModEffects.cpp
@file LedLeds.cpp
@date 20240226
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
Expand All @@ -9,7 +9,7 @@
@license For non GPL-v3 usage, commercial licenses must be purchased. Contact [email protected]
*/

#include "AppLeds.h"
#include "LedLeds.h"

//convenience functions to call fastled functions out of the Leds namespace (there naming conflict)
void fastled_fadeToBlackBy(CRGB* leds, unsigned16 num_leds, unsigned8 fadeBy) {
Expand All @@ -24,14 +24,11 @@ void fastled_fill_rainbow(struct CRGB * targetArray, int numToFill, unsigned8 in

// maps the virtual led to the physical led(s) and assign a color to it
void Leds::setPixelColor(unsigned16 indexV, CRGB color, unsigned8 blendAmount) {
if (mappingTable.size()) {
if (indexV >= mappingTable.size()) {
// USER_PRINTF(" dev sPC V:%d >= %d", indexV, mappingTable.size());
}
else {
for (unsigned16 indexP:mappingTable[indexV]) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount==UINT8_MAX?fixture->globalBlend:blendAmount);
}
if (indexV < mappingTable.size()) {
std::vector<unsigned16>* physMap = mappingTable[indexV];
if (physMap)
for (unsigned16 indexP:*physMap) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], blendAmount==UINT8_MAX?fixture->globalBlend:blendAmount);
}
}
else if (indexV < NUM_LEDS_Max)//no projection
Expand All @@ -41,19 +38,12 @@ void Leds::setPixelColor(unsigned16 indexV, CRGB color, unsigned8 blendAmount) {
}

CRGB Leds::getPixelColor(unsigned16 indexV) {
if (mappingTable.size()) {
if (indexV >= mappingTable.size()) {
// USER_PRINTF(" dev gPC V %d >= %d", indexV, mappingTable.size());
if (indexV < mappingTable.size()) {
std::vector<unsigned16>* physMap = mappingTable[indexV];
if (physMap && physMap->size())
return fixture->ledsP[*physMap->begin()]; //any would do as they are all the same
else
return CRGB::Black;
}
else if (!mappingTable[indexV].size()) //if no physMap // Core 1 panic'ed (LoadProhibited). Exception was unhandled. - std::vector<unsigned short, std::allocator<unsigned short> >::size()
// by blurrows CRGB cur = getPixelColor(XY(i,row));? XY(i,row) = 0
{
USER_PRINTF(" dev gPC P:%d >= %d", mappingTable[indexV][0], NUM_LEDS_Max);
return CRGB::Black;
}
else
return fixture->ledsP[mappingTable[indexV][0]]; //any would do as they are all the same
}
else if (indexV < NUM_LEDS_Max) //no mapping
return fixture->ledsP[indexV];
Expand All @@ -67,7 +57,8 @@ void Leds::fadeToBlackBy(unsigned8 fadeBy) {
if (projectionNr == p_None || p_Random) {
fastled_fadeToBlackBy(fixture->ledsP, fixture->nrOfLeds, fadeBy);
} else {
for (std::vector<std::vector<unsigned16>>::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (std::vector<unsigned16>* physMap:mappingTable) {
if (physMap)
for (unsigned16 indexP:*physMap) {
CRGB oldValue = fixture->ledsP[indexP];
fixture->ledsP[indexP].nscale8(255-fadeBy); //this overrides the old value
Expand All @@ -81,7 +72,8 @@ void Leds::fill_solid(const struct CRGB& color) {
if (projectionNr == p_None || p_Random) {
fastled_fill_solid(fixture->ledsP, fixture->nrOfLeds, color);
} else {
for (std::vector<std::vector<unsigned16>>::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (std::vector<unsigned16>* physMap:mappingTable) {
if (physMap)
for (unsigned16 indexP:*physMap) {
fixture->ledsP[indexP] = blend(color, fixture->ledsP[indexP], fixture->globalBlend);
}
Expand All @@ -98,7 +90,8 @@ void Leds::fill_rainbow(unsigned8 initialhue, unsigned8 deltahue) {
hsv.val = 255;
hsv.sat = 240;

for (std::vector<std::vector<unsigned16>> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap) {
for (std::vector<unsigned16>* physMap:mappingTable) {
if (physMap)
for (unsigned16 indexP:*physMap) {
fixture->ledsP[indexP] = blend(hsv, fixture->ledsP[indexP], fixture->globalBlend);
}
Expand Down
15 changes: 10 additions & 5 deletions src/App/AppLeds.h → src/App/LedLeds.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
@title StarMod
@file AppLeds.h
@file LedLeds.h
@date 20240227
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
Expand All @@ -20,7 +20,7 @@
// #define FASTLED_I2S_MAX_CONTROLLERS 8 // 8 LED pins should be enough (default = 24)
#include "FastLED.h"

#include "AppFixture.h"
#include "LedFixture.h"

#include "../data/font/console_font_4x6.h"
#include "../data/font/console_font_5x8.h"
Expand Down Expand Up @@ -154,7 +154,7 @@ class Leds {

SharedData sharedData;

std::vector<std::vector<unsigned16>> mappingTable;
std::vector<std::vector<unsigned16> *> mappingTable;

unsigned16 XY(unsigned16 x, unsigned16 y) {
return XYZ(x, y, 0);
Expand Down Expand Up @@ -188,8 +188,13 @@ class Leds {
USER_PRINTF("Leds[%d] destructor\n", UINT8_MAX);
fadeToBlackBy(100);
doMap = true; // so loop is not running while deleting
for (std::vector<std::vector<unsigned16>> ::iterator physMap=mappingTable.begin(); physMap!=mappingTable.end(); ++physMap)
physMap->clear();
for (std::vector<unsigned16>* physMap:mappingTable) {
if (physMap) {
physMap->clear();
// free(physMap);
delete physMap;
}
}
mappingTable.clear();
}

Expand Down
Loading

0 comments on commit e9a151a

Please sign in to comment.