Skip to content

Commit

Permalink
Effects using beat16, AppModLedFixGen: generate planes (for 3DCube)
Browse files Browse the repository at this point in the history
AppEffects:
- set speed default to 60 (BPM: 1 per second)
- Running1D and Lines2D: add beat16 (instead of call) and use speed control
- GEQEffect: rename speed to fadeOut and use beat16 instead of call

AppLedsV:
- fix print->print format error
- add Coordinate struct

AppModLedFixGen
- nrOfPins: if less pins defined, repeat latest defined pin
- add plane3D (sideCube3D deprecated)
- %02d ->%d
- f_3DSideCube: use plane3D

SysModFiles, SysModModel, SysModSystem, SysModUI
- fix print->print format error

SysModPrint
- refactor print (temp?)
  • Loading branch information
ewowi committed Sep 21, 2023
1 parent d57bc98 commit 63950c0
Show file tree
Hide file tree
Showing 16 changed files with 1,338 additions and 1,189 deletions.
5 changes: 3 additions & 2 deletions data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function preview3D(node, leds) {
console.log("before", node);
renderer = new THREE.WebGLRenderer({canvas: node, antialias: true, alpha: true });
console.log("after", node);
// THREE.Object3D.DefaultUp = new THREE.Vector3(0,1,1);
renderer.setClearAlpha(0)
renderer.setClearColor( 0x000000, 0 );
// renderer.setSize( 300, 150);
Expand Down Expand Up @@ -203,8 +204,8 @@ function preview3D(node, leds) {
function previewBoard(node, leds) {
let ctx = node.getContext('2d');
//assuming 20 pins
let mW = 2; // matrix width
let mH = 10; // matrix height
let mW = 10; // matrix width
let mH = 2; // matrix height
let pPL = Math.min(node.width / mW, node.height / mH); // pixels per LED (width of circle)
let lOf = Math.floor((node.width - pPL*mW)/2); //left offeset (to center matrix)
let i = 4;
Expand Down
7 changes: 4 additions & 3 deletions data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
<title>StarMod by MoonModules</title>
<meta charset="utf-8">
<link rel="stylesheet" href="index.css">
<script src="app.js"></script>
<script src="index.js"></script>

<!-- tbd: add max-age=86400 to imports -->

<!-- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
Expand All @@ -23,9 +27,6 @@
}
}
</script>
<!-- tbd: add max-age=86400 to imports -->
<script src="app.js"></script>
<script src="index.js"></script>
</head>
<body onload="onLoad()">
<h1>StarMod by MoonModules</h1>
Expand Down
6 changes: 6 additions & 0 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function generateHTML(parentNode, json, rowNr = -1) {

let spanNode = cE("span");
spanNode.innerText= "🔍";
// spanNode.addEventListener('click', (event) => {toggleModal(newNode);});
pNode.appendChild(spanNode);

parentNode.appendChild(pNode);
Expand Down Expand Up @@ -644,6 +645,11 @@ function toggleModal(element) {

element.parentNode.replaceChild(modalPlaceHolder, element);

// let btn = cE("button");
// btn.innerText = "close";
// btn.addEventListener('click', (event) => {toggleModal(element);});
// gId('modalView').appendChild(btn);

gId('modalView').appendChild(element);
element.width = window.innerWidth;;
element.height = window.innerHeight;
Expand Down
41 changes: 21 additions & 20 deletions src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


static uint8_t gHue = 0; // rotating "base color" used by many of the patterns
static unsigned long call = 0;
static unsigned long step = 0;
static unsigned long call = 0; //for 3D effects (temporary)
static unsigned long step = 0; //for GEQ (temporary)

//should not contain variables/bytes to keep mem as small as possible!!
class Effect {
Expand Down Expand Up @@ -85,10 +85,10 @@ class SinelonEffect: public Effect {
// CRGB x = ledsV[pos];
}
bool controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 128, false);
ui->initSlider(parentVar, "speed", 60, false);
return true;
}
};
}; //Sinelon

//https://www.perfectcircuit.com/signal/difference-between-waveforms
class RunningEffect: public Effect {
Expand All @@ -101,16 +101,13 @@ class RunningEffect: public Effect {
Effect::loop();
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( ledsP, LedsV::nrOfLedsP, mdl->getValue("fade").as<int>()); //physical leds
// int pos0 = (call-1)%ledsV.nrOfLeds;
// leds[pos0] = CHSV( 0,0,0);
int pos = map(beat16( mdl->getValue("speed").as<int>()), 0, uint16_t(-1), 0, LedsV::nrOfLedsV-1 );
int pos2 = map(beat16( mdl->getValue("speed").as<int>(), 1000), 0, uint16_t(-1), 0, LedsV::nrOfLedsV-1 );
// int pos = call%LedsV::nrOfLedsV; //Virtual leds
ledsV[LedsV::nrOfLedsV -1 - pos] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value
ledsV[LedsV::nrOfLedsV -1 - pos2] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value
int pos = map(beat16( mdl->getValue("speed").as<int>()), 0, uint16_t(-1), 0, LedsV::nrOfLedsV-1 ); //instead of call%LedsV::nrOfLedsV
// int pos2 = map(beat16( mdl->getValue("speed").as<int>(), 1000), 0, uint16_t(-1), 0, LedsV::nrOfLedsV-1 ); //one second later
ledsV[pos] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value
// ledsV[LedsV::nrOfLedsV -1 - pos2] = CHSV( gHue, 255, 192); //make sure the right physical leds get their value
}
bool controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 128, false, [](JsonObject var) { //uiFun
ui->initSlider(parentVar, "speed", 60, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "comment", "in BPM!");
});
ui->initSlider(parentVar, "fade", 128, false);
Expand Down Expand Up @@ -277,7 +274,7 @@ class Frizzles2D: public Effect {
blur2d(ledsP, LedsV::widthP, LedsV::heightP, mdl->getValue("blur")); //this is tricky as FastLed is not aware of our virtual
}
bool controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 128, false);
ui->initSlider(parentVar, "speed", 60, false);
ui->initSlider(parentVar, "intensity", 128, false);
ui->initSlider(parentVar, "blur", 128, false);
return true;
Expand All @@ -298,19 +295,21 @@ class Lines2D: public Effect {
CRGBPalette16 palette = PartyColors_p;

if (mdl->getValue("Vertical").as<bool>()) {
size_t x = call%LedsV::widthV;
size_t x = map(beat16( mdl->getValue("speed").as<int>()), 0, uint16_t(-1), 0, LedsV::widthV-1 ); //instead of call%width

for (size_t y = 0; y < LedsV::heightV; y++) {
ledsV[x + y * LedsV::widthV] = CHSV( gHue, 255, 192);
}
} else {
size_t y = call%LedsV::heightV;
size_t y = map(beat16( mdl->getValue("speed").as<int>()), 0, uint16_t(-1), 0, LedsV::heightV-1 ); //instead of call%height
for (size_t x = 0; x < LedsV::widthV; x++) {
ledsV[x + y * LedsV::widthV] = CHSV( gHue, 255, 192);
}
}
}

bool controls(JsonObject parentVar) {
ui->initSlider(parentVar, "speed", 60, false);
ui->initCheckBox(parentVar, "Vertical", false, false);
return true;
}
Expand Down Expand Up @@ -525,7 +524,7 @@ class GEQEffect:public Effect {
uint8_t samplePeak = *(uint8_t*)um_data->u_data[3];
#endif

uint8_t speed = mdl->getValue("speed");
uint8_t fadeOut = mdl->getValue("fadeOut");
uint8_t intensity = mdl->getValue("intensity");
bool colorBars = mdl->getValue("colorBars");
bool smoothBars = mdl->getValue("smoothBars");
Expand All @@ -536,8 +535,10 @@ class GEQEffect:public Effect {
rippleTime = true;
}

int fadeoutDelay = (256 - speed) / 64;
if ((fadeoutDelay <= 1 ) || ((call % fadeoutDelay) == 0)) fadeToBlackBy( ledsP, LedsV::nrOfLedsP, speed);
int fadeoutDelay = (256 - fadeOut) / 64; //256..1 -> 4..0
size_t beat = map(beat16( fadeOut), 0, uint16_t(-1), 0, fadeoutDelay-1 ); // instead of call%fadeOutDelay

if ((fadeoutDelay <= 1 ) || (beat == 0)) fadeToBlackBy( ledsP, LedsV::nrOfLedsP, fadeOut);

uint16_t lastBandHeight = 0; // WLEDMM: for smoothing out bars

Expand Down Expand Up @@ -595,14 +596,14 @@ class GEQEffect:public Effect {
}

bool controls(JsonObject parentVar) {
ui->initNumber(parentVar, "speed", 255, false);
ui->initNumber(parentVar, "fadeOut", 255, false);
ui->initNumber(parentVar, "intensity", 255, false);
ui->initCheckBox(parentVar, "colorBars", false, false); //
ui->initCheckBox(parentVar, "smoothBars", false, false);

// Nice an effect can register it's own DMX channel, but not a fan of repeating the range and type of the param

e131mod->patchChannel(3, "speed", 255); // TODO: add constant for name
e131mod->patchChannel(3, "fadeOut", 255); // TODO: add constant for name
e131mod->patchChannel(4, "intensity", 255);

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/App/AppLedsV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void LedsV::ledFixProjectAndMap() {
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);
print->print("pins extend leds %d: %s\n", currPin, details);
//tbd: more check

strncpy(SysModPins::pinObjects[currPin].details, details, sizeof(PinObject::details)-1);
Expand All @@ -182,7 +182,7 @@ void LedsV::ledFixProjectAndMap() {
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);
print->print("pins %d: %s\n", currPin, details);
pins->allocatePin(currPin, "Leds", details);
}

Expand Down
6 changes: 6 additions & 0 deletions src/App/AppLedsV.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ enum Projections
count
};

struct Coordinate {
uint16_t x;
uint16_t y;
uint16_t z;
};

class LedsV {

public:
Expand Down
Loading

0 comments on commit 63950c0

Please sign in to comment.