Skip to content

Commit 3a6033c

Browse files
committed
setLight -> setRGB, requestMap
Scripts ===== - setLight -> setRGB Server ===== - Effects, Nodes: setLight -> setRGB - Editor: requestMapPhysical and requestMapVirtual
1 parent 45469a3 commit 3a6033c

File tree

11 files changed

+55
-62
lines changed

11 files changed

+55
-62
lines changed

misc/livescripts/E_lines.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ void loop() {
22
fadeToBlackBy(255);
33
int x = millis() / 100;
44
for (int y = 0; y < height; y++) {
5-
setLight(y*width+x%width, CRGB(255,0,0));
5+
setRGB(y*width+x%width, CRGB(255,0,0));
66
}
77
}

misc/livescripts/E_noise.sc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ void loop() {
1010
for (int y = 0; y < height; y++) {
1111
for (int x = 0; x < width; x++) {
1212
uint8_t lightHue8 = inoise8(x * scale, y * scale, now() / (16 - speed/16));
13-
// leds.setLightColor(leds.XY(x, y), ColorFromPalette(leds.palette, lightHue8));
14-
setLightPal(y*width+x, lightHue8, 255);
13+
// leds.setRGBColor(leds.XY(x, y), ColorFromPalette(leds.palette, lightHue8));
14+
setRGBPal(y*width+x, lightHue8, 255);
1515
}
1616
}
1717
}

misc/livescripts/E_octo.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void loop() {
3838
uint8_t radius = rMapRadius[x*height+y];
3939
uint16_t intensity = sin8(sin8((angle * 4 - radius*mapp) / 4 + t) + radius*mapp - 2*t + angle * branches);
4040

41-
setLight(y*width+x, hsv(2*t - radius*mapp, 255, intensity));
41+
setRGB(y*width+x, hsv(2*t - radius*mapp, 255, intensity));
4242
}
4343
}
4444
t = now() * speed / 32 / 25; //speed 0..8, 40 changes per second

misc/livescripts/E_random.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ void setup() {
22
printf("Run Live Script good morning\n");
33
}
44
void loop() {
5-
leds[random16(255)] = CRGB(0, 0, 255);
5+
setRGB(random16(255), CRGB(0, 0, 255));
66
}

src/MoonLight/Effects.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class DistortionWavesEffect: public Node {
173173
valueG = gamma8(cos8(valueG));
174174
valueB = gamma8(cos8(valueB));
175175

176-
layerV->setLight(pos, CRGB(valueR, valueG, valueB));
176+
layerV->setRGB(pos, CRGB(valueR, valueG, valueB));
177177
}
178178
}
179179
}
@@ -231,12 +231,12 @@ class FreqMatrixEffect: public Node {
231231
}
232232

233233
// shift the pixels one pixel up
234-
layerV->setLight(0, color);
234+
layerV->setRGB(0, color);
235235
for (uint8_t x = layerV->size.x - 1; x >= 0; x--) {
236236
if (x!=0) color = layerV->getLight<CRGB>(x-1);
237237
for (uint8_t y = 0; y < layerV->size.y; y++)
238238
for (uint8_t z = 0; z < layerV->size.z; z++)
239-
layerV->setLight({x,y,z}, color);
239+
layerV->setRGB({x,y,z}, color);
240240
}
241241
}
242242
}
@@ -345,11 +345,11 @@ class GEQEffect: public Node {
345345

346346
ledColor = ColorFromPalette(layerV->layerP->palette, (uint8_t)colorIndex);
347347

348-
layerV->setLight(intToCoord3D(pos.x, layerV->size.y - 1 - pos.y, 0), ledColor);
348+
layerV->setRGB(intToCoord3D(pos.x, layerV->size.y - 1 - pos.y, 0), ledColor);
349349
}
350350

351351
if ((ripple > 0) && (previousBarHeight[pos.x] > 0) && (previousBarHeight[pos.x] < layerV->size.y)) // WLEDMM avoid "overshooting" into other segments
352-
layerV->setLight(intToCoord3D(pos.x, layerV->size.y - previousBarHeight[pos.x], 0), (CRGB)CHSV( millis()/50, 255, 255)); // take millis()/50 color for the time being
352+
layerV->setRGB(intToCoord3D(pos.x, layerV->size.y - previousBarHeight[pos.x], 0), (CRGB)CHSV( millis()/50, 255, 255)); // take millis()/50 color for the time being
353353

354354
if (rippleTime && previousBarHeight[pos.x]>0) previousBarHeight[pos.x]--; //delay/ripple effect
355355

@@ -604,7 +604,7 @@ class RandomEffect: public Node {
604604

605605
void loop() override {
606606
layerV->fadeToBlackBy(70);
607-
layerV->setLight(random16(layerV->nrOfLights), CRGB(255, random8(), 0));
607+
layerV->setRGB(random16(layerV->nrOfLights), CRGB(255, random8(), 0));
608608
}
609609
};
610610

@@ -637,7 +637,7 @@ class RipplesEffect: public Node {
637637
float d = distance(layerV->size.x/2.0f, layerV->size.z/2.0f, 0.0f, (float)pos.x, (float)pos.z, 0.0f) / 9.899495f * layerV->size.y;
638638
pos.y = floor(layerV->size.y/2.0f * (1 + sinf(d/ripple_interval + time_interval))); //between 0 and layerV->size.y
639639

640-
layerV->setLight(pos, (CRGB)CHSV( millis()/50 + random8(64), 200, 255));
640+
layerV->setRGB(pos, (CRGB)CHSV( millis()/50 + random8(64), 200, 255));
641641
}
642642
}
643643
}
@@ -699,7 +699,7 @@ class SinusEffect: public Node {
699699
// Map the sine wave value to a color hue
700700
uint8_t hue = wave + hueOffset;
701701
// Set the LED color using the calculated hue
702-
layerV->setLight(i, (CRGB)CHSV(hue, 255, brightness));
702+
layerV->setRGB(i, (CRGB)CHSV(hue, 255, brightness));
703703
}
704704

705705
// Increment the phase to animate the wave
@@ -740,7 +740,7 @@ class SphereMoveEffect: public Node {
740740
float d = distance(pos.x, pos.y, pos.z, origin.x, origin.y, origin.z);
741741

742742
if (d>diameter && d<diameter + 1.0) {
743-
layerV->setLight(pos, (CRGB)CHSV( millis()/50 + random8(64), 200, 255));
743+
layerV->setRGB(pos, (CRGB)CHSV( millis()/50 + random8(64), 200, 255));
744744
}
745745
}
746746
}
@@ -772,7 +772,7 @@ class WaveEffect: public Node {
772772
}
773773

774774
void loop() override {
775-
layerV->fadeToBlackBy(fade);
775+
layerV->fadeToBlackBy(fade); //should only fade rgb ...
776776

777777
CRGB color = CHSV( millis()/50, 255, 255);
778778

@@ -794,10 +794,10 @@ class WaveEffect: public Node {
794794
//connect saw and square
795795
if (abs(prevPos - pos) > layerV->size.x / 2) {
796796
for (uint8_t x=0; x<layerV->size.x; x++)
797-
layerV->setLight({x, y, 0}, color);
797+
layerV->setRGB({x, y, 0}, color);
798798
}
799799

800-
layerV->setLight({pos, y, 0}, color); //= CRGB(255, random8(), 0);
800+
layerV->setRGB({pos, y, 0}, color); //= CRGB(255, random8(), 0);
801801
prevPos = pos;
802802
}
803803
}

src/MoonLight/ModuleEditor.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,17 @@ class ModuleEditor : public Module
228228
ESP_LOGD(TAG, "No newnode - remove! %d s:%d", updatedItem.index[0], layerP.layerV[0]->nodes.size());
229229
}
230230

231-
if (oldNode->hasModifier) {
232-
ESP_LOGD(TAG, "Modifier %s deleted -> remap layout", updatedItem.oldValue.c_str());
233-
layerP.layerV[0]->requestMapVirtual = true;
234-
}
235231
if (oldNode->hasLayout) {
236232
ESP_LOGD(TAG, "Layout %s deleted -> remap layout", updatedItem.oldValue.c_str());
237233
layerP.layerV[0]->requestMapPhysical = true;
234+
}
235+
236+
if (oldNode->hasModifier || oldNode->hasLayout) {
237+
ESP_LOGD(TAG, "Modifier %s deleted -> remap layout", updatedItem.oldValue.c_str());
238238
layerP.layerV[0]->requestMapVirtual = true;
239239
}
240240

241-
// delay(100); //let loopTask finish the current loop before removing the node
242-
// layerP.removeNode(oldNode); //remove the node from the layer, which will also remove the controls
241+
layerP.removeNode(oldNode);
243242
}
244243

245244
#if FT_ENABLED(FT_LIVESCRIPT)
@@ -264,13 +263,12 @@ class ModuleEditor : public Module
264263
if (nodeClass != nullptr) {
265264
nodeClass->on = updatedItem.value.as<bool>(); //set nodeclass on/off
266265
ESP_LOGD(TAG, " nodeclass m:%d l:%d", nodeClass->hasModifier, nodeClass->hasLayout);
267-
if (nodeClass->hasModifier) { //nodeClass->on && //if class has modifier, run the layout (if on) - which uses all the modifiers ...
268-
ESP_LOGD(TAG, "Modifier on/off -> remap layout %s", nodeState["nodeName"].as<String>().c_str());
269-
layerP.layerV[0]->requestMapVirtual = true;
270-
}
271266
if (nodeClass->hasLayout) {
272267
ESP_LOGD(TAG, "Layout on/off -> remap layout %s (on:%d)", nodeState["nodeName"].as<String>().c_str(), nodeClass->on);
273268
layerP.layerV[0]->requestMapPhysical = true;
269+
}
270+
if (nodeClass->hasModifier || nodeClass->hasLayout) { //nodeClass->on && //if class has modifier, run the layout (if on) - which uses all the modifiers ...
271+
ESP_LOGD(TAG, "Modifier on/off -> remap layout %s", nodeState["nodeName"].as<String>().c_str());
274272
layerP.layerV[0]->requestMapVirtual = true;
275273
}
276274
}

src/MoonLight/ModuleLiveScripts.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ class ModuleLiveScripts : public Module
9898

9999
JsonDocument newData; //to only send updatedData
100100
JsonArray scripts = newData["scripts"].to<JsonArray>(); //to: remove old array
101-
LiveScriptNode node;
102-
node.getScriptsJson(scripts);
101+
LiveScriptNode::getScriptsJson(scripts);
103102

104103
//only if changed
105104
if (_state.data["scripts"] != newData["scripts"]) {

src/MoonLight/Nodes.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ static void _modifyLayout() {gNode->modifyLayout();}
7171
// static void _modifyXYZ() {gNode->modifyXYZ();}//need &position parameter
7272

7373
void _fadeToBlackBy(uint8_t fadeValue) { gNode->layerV->fadeToBlackBy(fadeValue);}
74-
static void _setLight(uint16_t indexV, CRGB color) {gNode->layerV->setLight(indexV, color);}
75-
static void _setLightPal(uint16_t indexV, uint8_t index, uint8_t brightness) { gNode->layerV->setLight(indexV, ColorFromPalette(PartyColors_p, index, brightness));}
74+
static void _setRGB(uint16_t indexV, CRGB color) {gNode->layerV->setRGB(indexV, color);}
75+
static void _setRGBPal(uint16_t indexV, uint8_t index, uint8_t brightness) { gNode->layerV->setRGB(indexV, ColorFromPalette(PartyColors_p, index, brightness));}
7676

7777
static float _time(float j) {
7878
float myVal = millis();
@@ -133,13 +133,15 @@ void LiveScriptNode::setup() {
133133
return;
134134
}
135135

136+
//make sure types in below functions are correct !!! otherwise livescript will crash
137+
136138
//generic functions
137139
addExternal("uint32_t millis()", (void *)millis);
138140
addExternal("uint32_t now()", (void *)millis); //todo: synchronized time (sys->now)
139141
addExternal("uint16_t random16(uint16_t)", (void *)(uint16_t (*)(uint16_t))random16);
140-
addExternal( "void delay(uint8_t)", (void *)delay);
141-
addExternal( "void pinMode(int,int)", (void *)pinMode);
142-
addExternal( "void digitalWrite(int,int)", (void *)digitalWrite);
142+
addExternal( "void delay(uint32_t)", (void *)delay);
143+
addExternal( "void pinMode(uint8_t,uint8_t)", (void *)pinMode);
144+
addExternal( "void digitalWrite(uint8_t,uint8_t)", (void *)digitalWrite);
143145

144146
//trigonometric functions
145147
addExternal( "float sin(float)", (void *)(float (*)(float))sin);
@@ -171,12 +173,12 @@ void LiveScriptNode::setup() {
171173

172174
addExternal( "void fadeToBlackBy(uint8_t)", (void *)_fadeToBlackBy);
173175
addExternal( "CRGB* leds", (void *)layerV->layerP->lights.leds);
174-
addExternal( "void setLight(uint16_t,CRGB)", (void *)_setLight);
175-
addExternal( "void setLightPal(uint16_t,uint8_t,uint8_t)", (void *)_setLightPal);
176-
addExternal("uint16_t width", &layerV->size.x);
177-
addExternal("uint16_t height", &layerV->size.y);
178-
addExternal("uint16_t depth", &layerV->size.z);
179-
addExternal("bool on", &on);
176+
addExternal( "void setRGB(uint16_t,CRGB)", (void *)_setRGB);
177+
addExternal( "void setRGBPal(uint16_t,uint8_t,uint8_t)", (void *)_setRGBPal);
178+
addExternal( "uint8_t width", &layerV->size.x);
179+
addExternal( "uint8_t height", &layerV->size.y);
180+
addExternal( "uint8_t depth", &layerV->size.z);
181+
addExternal( "bool on", &on);
180182

181183
for (asm_external el: external_links) {
182184
ESP_LOGD(TAG, "elink %s %s %d", el.shortname.c_str(), el.name.c_str(), el.type);
@@ -202,10 +204,8 @@ void LiveScriptNode::addLayout() {
202204
}
203205

204206
LiveScriptNode::~LiveScriptNode() {
205-
if (animation != nullptr) { //in case not defined
206-
ESP_LOGD(TAG, "%s", animation);
207-
scriptRuntime.kill(animation);
208-
}
207+
ESP_LOGD(TAG, "%s", animation);
208+
scriptRuntime.kill(animation);
209209
}
210210

211211
// LiveScriptNode functions

src/MoonLight/Nodes.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,8 @@ class Node {
130130
virtual ~Node() {
131131
//delete any allocated memory
132132

133-
if (hasModifier) {
134-
// ESP_LOGD(TAG, "Modifier deleted -> remap layout %s", nodeState["nodeName"].as<String>().c_str());
135-
layerV->requestMapVirtual = true;
136-
}
137-
if (hasLayout) {
138-
layerV->requestMapPhysical = true; //request mapPhysical to update the layout
139-
layerV->requestMapVirtual = true; //request mapVirtual to update the layout
140-
}
133+
ESP_LOGD(TAG, "Node destructor %d %d", hasLayout, hasModifier);
134+
141135
}
142136

143137
};
@@ -173,7 +167,7 @@ class LiveScriptNode: public Node {
173167
void kill();
174168
void free();
175169
void killAndDelete();
176-
void getScriptsJson(JsonArray scripts);
170+
static void getScriptsJson(JsonArray scripts);
177171

178172
};
179173

src/MoonLight/PhysicalLayer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,17 @@ PhysicalLayer::PhysicalLayer() {
196196
layerV[0]->nodes[index] = node; //add the node to the layer
197197
}
198198

199-
ESP_LOGD(TAG, "%s (s:%d)", name, layerV[0]->nodes.size());
199+
ESP_LOGD(TAG, "%s (s:%d p:%p)", name, layerV[0]->nodes.size(), node);
200200

201201
return node;
202202
}
203203

204204
void PhysicalLayer::removeNode(Node *node) {
205-
ESP_LOGD(TAG, "remove node (s:%d)", layerV[0]->nodes.size());
205+
ESP_LOGD(TAG, "remove node (s:%d p:%p)", layerV[0]->nodes.size(), node);
206206
// node->destructor(); //now ˜destructor is called in Node destructor
207-
//delete node; //causing assert failed: multi_heap_free multi_heap_poisoning.c:259 (head != NULL) ATM
207+
// delete node; //causing assert failed: multi_heap_free multi_heap_poisoning.c:259 (head != NULL) ATM
208+
// //can cause a crash if it has addControl ... (e.g. panel layout)
209+
208210
// layerV[0]->nodes[index] = nullptr;
209211
}
210212

0 commit comments

Comments
 (0)