Skip to content

Commit 8d00e4d

Browse files
committed
Save some tiny amounts of RAM
- use `-D WLED_SAVE_RAM`
1 parent 8688777 commit 8d00e4d

File tree

8 files changed

+196
-56
lines changed

8 files changed

+196
-56
lines changed

wled00/FX.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,9 @@ class WS2812FX { // 96 bytes
720720
#ifndef WLED_DISABLE_2D
721721
panels(1),
722722
#endif
723+
autoSegments(false),
724+
correctWB(false),
725+
cctFromRgb(false),
723726
// semi-private (just obscured) used in effect functions through macros
724727
_colors_t{0,0,0},
725728
_virtualSegmentLength(0),
@@ -908,6 +911,12 @@ class WS2812FX { // 96 bytes
908911
void loadCustomPalettes(void); // loads custom palettes from JSON
909912
std::vector<CRGBPalette16> customPalettes; // TODO: move custom palettes out of WS2812FX class
910913

914+
struct {
915+
bool autoSegments : 1;
916+
bool correctWB : 1;
917+
bool cctFromRgb : 1;
918+
};
919+
911920
// using public variables to reduce code size increase due to inline function getSegment() (with bounds checking)
912921
// and color transitions
913922
uint32_t _colors_t[3]; // color used for effect (includes transition)

wled00/FX_fcn.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,9 +1028,9 @@ void Segment::refreshLightCapabilities() {
10281028
if (bus->getStart() + bus->getLength() <= segStartIdx) continue;
10291029

10301030
//uint8_t type = bus->getType();
1031-
if (bus->hasRGB() || (cctFromRgb && bus->hasCCT())) capabilities |= SEG_CAPABILITY_RGB;
1032-
if (!cctFromRgb && bus->hasCCT()) capabilities |= SEG_CAPABILITY_CCT;
1033-
if (correctWB && (bus->hasRGB() || bus->hasCCT())) capabilities |= SEG_CAPABILITY_CCT; //white balance correction (CCT slider)
1031+
if (bus->hasRGB() || (strip.cctFromRgb && bus->hasCCT())) capabilities |= SEG_CAPABILITY_RGB;
1032+
if (!strip.cctFromRgb && bus->hasCCT()) capabilities |= SEG_CAPABILITY_CCT;
1033+
if (strip.correctWB && (bus->hasRGB() || bus->hasCCT())) capabilities |= SEG_CAPABILITY_CCT; //white balance correction (CCT slider)
10341034
if (bus->hasWhite()) {
10351035
unsigned aWM = Bus::getGlobalAWMode() == AW_GLOBAL_DISABLED ? bus->getAutoWhiteMode() : Bus::getGlobalAWMode();
10361036
bool whiteSlider = (aWM == RGBW_MODE_DUAL || aWM == RGBW_MODE_MANUAL_ONLY); // white slider allowed

wled00/cfg.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
2020

2121
//long vid = doc[F("vid")]; // 2010020
2222

23-
#ifdef WLED_USE_ETHERNET
23+
#ifdef WLED_USE_ETHERNET
2424
JsonObject ethernet = doc[F("eth")];
2525
CJSON(ethernetType, ethernet["type"]);
2626
// NOTE: Ethernet configuration takes priority over other use of pins
2727
WLED::instance().initEthernet();
28-
#endif
28+
#endif
2929

3030
JsonObject id = doc["id"];
3131
getStringFromJson(cmDNS, id[F("mdns")], 33);
3232
getStringFromJson(serverDescription, id[F("name")], 33);
33+
#ifndef WLED_DISABLE_ALEXA
3334
getStringFromJson(alexaInvocationName, id[F("inv")], 33);
35+
#endif
3436
CJSON(simplifiedUI, id[F("sui")]);
3537

3638
JsonObject nw = doc["nw"];
@@ -109,8 +111,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
109111
uint16_t ablMilliampsMax = hw_led[F("maxpwr")] | BusManager::ablMilliampsMax();
110112
BusManager::setMilliampsMax(ablMilliampsMax);
111113
Bus::setGlobalAWMode(hw_led[F("rgbwm")] | AW_GLOBAL_DISABLED);
112-
CJSON(correctWB, hw_led["cct"]);
113-
CJSON(cctFromRgb, hw_led[F("cr")]);
114+
CJSON(strip.correctWB, hw_led["cct"]);
115+
CJSON(strip.cctFromRgb, hw_led[F("cr")]);
114116
CJSON(cctICused, hw_led[F("ic")]);
115117
CJSON(strip.cctBlending, hw_led[F("cb")]);
116118
Bus::setCCTBlend(strip.cctBlending);
@@ -431,7 +433,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
431433
JsonObject light = doc[F("light")];
432434
CJSON(briMultiplier, light[F("scale-bri")]);
433435
CJSON(strip.paletteBlend, light[F("pal-mode")]);
434-
CJSON(autoSegments, light[F("aseg")]);
436+
CJSON(strip.autoSegments, light[F("aseg")]);
435437

436438
CJSON(gammaCorrectVal, light["gc"]["val"]); // default 2.8
437439
float light_gc_bri = light["gc"]["bri"];
@@ -530,12 +532,12 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
530532
CJSON(arlsDisableGammaCorrection, if_live[F("no-gc")]); // false
531533
CJSON(arlsOffset, if_live[F("offset")]); // 0
532534

535+
#ifndef WLED_DISABLE_ALEXA
533536
CJSON(alexaEnabled, interfaces["va"][F("alexa")]); // false
534-
535537
CJSON(macroAlexaOn, interfaces["va"]["macros"][0]);
536538
CJSON(macroAlexaOff, interfaces["va"]["macros"][1]);
537-
538539
CJSON(alexaNumPresets, interfaces["va"]["p"]);
540+
#endif
539541

540542
#ifndef WLED_DISABLE_MQTT
541543
JsonObject if_mqtt = interfaces["mqtt"];
@@ -739,7 +741,9 @@ void serializeConfig() {
739741
JsonObject id = root.createNestedObject("id");
740742
id[F("mdns")] = cmDNS;
741743
id[F("name")] = serverDescription;
744+
#ifndef WLED_DISABLE_ALEXA
742745
id[F("inv")] = alexaInvocationName;
746+
#endif
743747
id[F("sui")] = simplifiedUI;
744748

745749
JsonObject nw = root.createNestedObject("nw");
@@ -818,8 +822,8 @@ void serializeConfig() {
818822
hw_led[F("total")] = strip.getLengthTotal(); //provided for compatibility on downgrade and per-output ABL
819823
hw_led[F("maxpwr")] = BusManager::ablMilliampsMax();
820824
hw_led[F("ledma")] = 0; // no longer used
821-
hw_led["cct"] = correctWB;
822-
hw_led[F("cr")] = cctFromRgb;
825+
hw_led["cct"] = strip.correctWB;
826+
hw_led[F("cr")] = strip.cctFromRgb;
823827
hw_led[F("ic")] = cctICused;
824828
hw_led[F("cb")] = strip.cctBlending;
825829
hw_led["fps"] = strip.getTargetFps();
@@ -931,7 +935,7 @@ void serializeConfig() {
931935
JsonObject light = root.createNestedObject(F("light"));
932936
light[F("scale-bri")] = briMultiplier;
933937
light[F("pal-mode")] = strip.paletteBlend;
934-
light[F("aseg")] = autoSegments;
938+
light[F("aseg")] = strip.autoSegments;
935939

936940
JsonObject light_gc = light.createNestedObject("gc");
937941
light_gc["bri"] = (gammaCorrectBri) ? gammaCorrectVal : 1.0f; // keep compatibility

wled00/e131.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ void handleDDPPacket(e131_packet_t* p) {
5656
//E1.31 and Art-Net protocol support
5757
void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
5858

59-
unsigned uni = 0, dmxChannels = 0;
59+
int uni = 0, dmxChannels = 0;
6060
uint8_t* e131_data = nullptr;
61-
unsigned seq = 0, mde = REALTIME_MODE_E131;
61+
int seq = 0, mde = REALTIME_MODE_E131;
6262

6363
if (protocol == P_ARTNET)
6464
{
@@ -179,7 +179,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
179179
if (uni != e131Universe || availDMXLen < 2) return;
180180

181181
// limit max. selectable preset to 250, even though DMX max. val is 255
182-
unsigned dmxValPreset = (e131_data[dataOffset+1] > 250 ? 250 : e131_data[dataOffset+1]);
182+
int dmxValPreset = (e131_data[dataOffset+1] > 250 ? 250 : e131_data[dataOffset+1]);
183183

184184
// only apply preset if value changed
185185
if (dmxValPreset != 0 && dmxValPreset != currentPreset &&
@@ -254,7 +254,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
254254
// Set segment opacity or global brightness
255255
if (isSegmentMode) {
256256
if (e131_data[dataOffset] != seg.opacity) seg.setOpacity(e131_data[dataOffset]);
257-
} else if ( id == strip.getSegmentsNum()-1 ) {
257+
} else if ( id == strip.getSegmentsNum()-1U ) {
258258
if (bri != e131_data[dataOffset]) {
259259
bri = e131_data[dataOffset];
260260
strip.setBrightness(bri, true);

wled00/json.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
3737
Segment prev = seg; //make a backup so we can tell if something changed (calling copy constructor)
3838
//DEBUG_PRINTF_P(PSTR("-- Duplicate segment: %p (%p)\n"), &prev, prev.data);
3939

40-
unsigned start = elem["start"] | seg.start;
40+
int start = elem["start"] | seg.start;
4141
if (stop < 0) {
4242
int len = elem["len"];
4343
stop = (len > 0) ? start + len : seg.stop;
4444
}
4545
// 2D segments
46-
unsigned startY = elem["startY"] | seg.startY;
47-
unsigned stopY = elem["stopY"] | seg.stopY;
46+
int startY = elem["startY"] | seg.startY;
47+
int stopY = elem["stopY"] | seg.stopY;
4848

4949
//repeat, multiplies segment until all LEDs are used, or max segments reached
5050
bool repeat = elem["rpt"] | false;
@@ -105,7 +105,7 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
105105
uint8_t set = elem[F("set")] | seg.set;
106106
seg.set = constrain(set, 0, 3);
107107

108-
unsigned len = 1;
108+
int len = 1;
109109
if (stop > start) len = stop - start;
110110
int offset = elem[F("of")] | INT32_MAX;
111111
if (offset != INT32_MAX) {

wled00/set.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
130130
unsigned ablMilliampsMax = request->arg(F("MA")).toInt();
131131
BusManager::setMilliampsMax(ablMilliampsMax);
132132

133-
autoSegments = request->hasArg(F("MS"));
134-
correctWB = request->hasArg(F("CCT"));
135-
cctFromRgb = request->hasArg(F("CR"));
133+
strip.autoSegments = request->hasArg(F("MS"));
134+
strip.correctWB = request->hasArg(F("CCT"));
135+
strip.cctFromRgb = request->hasArg(F("CR"));
136136
cctICused = request->hasArg(F("IC"));
137137
strip.cctBlending = request->arg(F("CB")).toInt();
138138
Bus::setCCTBlend(strip.cctBlending);
@@ -421,10 +421,12 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
421421
t = request->arg(F("WO")).toInt();
422422
if (t >= -255 && t <= 255) arlsOffset = t;
423423

424+
#ifndef WLED_DISABLE_ALEXA
424425
alexaEnabled = request->hasArg(F("AL"));
425426
strlcpy(alexaInvocationName, request->arg(F("AI")).c_str(), 33);
426427
t = request->arg(F("AP")).toInt();
427428
if (t >= 0 && t <= 9) alexaNumPresets = t;
429+
#endif
428430

429431
#ifndef WLED_DISABLE_MQTT
430432
mqttEnabled = request->hasArg(F("MQ"));

0 commit comments

Comments
 (0)