Replace setOption/getOption
This commit is contained in:
parent
638178556f
commit
6fd8a5a084
16
wled00/FX.h
16
wled00/FX.h
@ -344,7 +344,7 @@ typedef enum mapping1D2D {
|
||||
M12_Block = 3
|
||||
} mapping1D2D_t;
|
||||
|
||||
// segment, 68 (92 in memory) bytes
|
||||
// segment, 72 bytes
|
||||
typedef struct Segment {
|
||||
public:
|
||||
uint16_t start; // start index / start X coordinate 2D (left)
|
||||
@ -368,11 +368,15 @@ typedef struct Segment {
|
||||
bool reverse_y : 1; // 8 : reversed Y (2D)
|
||||
bool mirror_y : 1; // 9 : mirrored Y (2D)
|
||||
bool transpose : 1; // 10 : transposed (2D, swapped X & Y)
|
||||
uint8_t map1D2D : 2; // 11-12 : mapping for 1D effect on 2D (0-strip, 1-expand vertically, 2-circular, 3-rectangular)
|
||||
uint8_t soundSim : 3; // 13-15 : 0-7 sound simulation types
|
||||
uint8_t map1D2D : 3; // 11-13 : mapping for 1D effect on 2D (0-use as strip, 1-expand vertically, 2-circular/arc, 3-rectangular/corner, ...)
|
||||
uint8_t soundSim : 2; // 14-15 : 0-3 sound simulation types
|
||||
};
|
||||
};
|
||||
uint8_t grouping, spacing;
|
||||
//struct {
|
||||
// uint8_t grouping : 4; // maximum 15 pixels in a group
|
||||
// uint8_t spacing : 4; // maximum 15 pixels per gap
|
||||
//};
|
||||
uint8_t opacity;
|
||||
uint32_t colors[NUM_COLORS];
|
||||
uint8_t cct; //0==1900K, 255==10091K
|
||||
@ -383,8 +387,8 @@ typedef struct Segment {
|
||||
bool check2 : 1; // checkmark 2
|
||||
bool check3 : 1; // checkmark 3
|
||||
};
|
||||
uint16_t startY; // start Y coodrinate 2D (top)
|
||||
uint16_t stopY; // stop Y coordinate 2D (bottom)
|
||||
uint8_t startY; // start Y coodrinate 2D (top); there should be no more than 255 rows
|
||||
uint8_t stopY; // stop Y coordinate 2D (bottom); there should be no more than 255 rows
|
||||
char *name;
|
||||
|
||||
// runtime data
|
||||
@ -627,7 +631,7 @@ typedef struct Segment {
|
||||
void wu_pixel(uint32_t x, uint32_t y, CRGB c) {}
|
||||
#endif
|
||||
} segment;
|
||||
//static int i = sizeof(Segment);
|
||||
//static int segSize = sizeof(Segment);
|
||||
|
||||
// main "strip" class
|
||||
class WS2812FX { // 96 bytes
|
||||
|
@ -1106,7 +1106,7 @@ void WS2812FX::setBrightness(uint8_t b, bool direct) {
|
||||
_brightness = b;
|
||||
if (_brightness == 0) { //unfreeze all segments on power off
|
||||
for (segment &seg : _segments) {
|
||||
seg.setOption(SEG_OPTION_FREEZE, false);
|
||||
seg.freeze = false;
|
||||
}
|
||||
}
|
||||
if (direct) {
|
||||
@ -1319,7 +1319,7 @@ void WS2812FX::makeAutoSegments(bool forceReset) {
|
||||
_segments.clear();
|
||||
for (size_t i = 0; i < s; i++) {
|
||||
Segment seg = Segment(segStarts[i], segStops[i]);
|
||||
seg.setOption(SEG_OPTION_SELECTED, true);
|
||||
seg.selected = true;
|
||||
_segments.push_back(seg);
|
||||
}
|
||||
_mainSegment = 0;
|
||||
|
@ -197,10 +197,10 @@ void handleAnalog(uint8_t b)
|
||||
// otherwise use "double press" for segment selection
|
||||
Segment& seg = strip.getSegment(macroDoublePress[b]);
|
||||
if (aRead == 0) {
|
||||
seg.setOption(SEG_OPTION_ON, 0); // off
|
||||
seg.on = false; // off
|
||||
} else {
|
||||
seg.setOpacity(aRead);
|
||||
seg.setOption(SEG_OPTION_ON, 1);
|
||||
seg.on = true;
|
||||
}
|
||||
// this will notify clients of update (websockets,mqtt,etc)
|
||||
updateInterfaces(CALL_MODE_BUTTON);
|
||||
|
@ -84,8 +84,8 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
|
||||
if ((spc>0 && spc!=seg.spacing) || seg.map1D2D!=map1D2D) seg.fill(BLACK); // clear spacing gaps
|
||||
|
||||
seg.map1D2D = map1D2D & 0x03;
|
||||
seg.soundSim = soundSim & 0x07;
|
||||
seg.map1D2D = map1D2D & 0x07;
|
||||
seg.soundSim = soundSim & 0x03;
|
||||
|
||||
uint16_t len = 1;
|
||||
if (stop > start) len = stop - start;
|
||||
@ -102,15 +102,15 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
byte segbri = seg.opacity;
|
||||
if (getVal(elem["bri"], &segbri)) {
|
||||
if (segbri > 0) seg.setOpacity(segbri);
|
||||
seg.setOption(SEG_OPTION_ON, segbri);
|
||||
seg.on = segbri;
|
||||
}
|
||||
|
||||
bool on = elem["on"] | seg.getOption(SEG_OPTION_ON);
|
||||
bool on = elem["on"] | seg.on;
|
||||
if (elem["on"].is<const char*>() && elem["on"].as<const char*>()[0] == 't') on = !on;
|
||||
seg.setOption(SEG_OPTION_ON, on);
|
||||
bool frz = elem["frz"] | seg.getOption(SEG_OPTION_FREEZE);
|
||||
if (elem["frz"].is<const char*>() && elem["frz"].as<const char*>()[0] == 't') frz = !seg.getOption(SEG_OPTION_FREEZE);
|
||||
seg.setOption(SEG_OPTION_FREEZE, frz);
|
||||
seg.on = on;
|
||||
bool frz = elem["frz"] | seg.freeze;
|
||||
if (elem["frz"].is<const char*>() && elem["frz"].as<const char*>()[0] == 't') frz = !seg.freeze;
|
||||
seg.freeze = frz;
|
||||
|
||||
seg.setCCT(elem["cct"] | seg.cct);
|
||||
|
||||
@ -162,13 +162,13 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
}
|
||||
#endif
|
||||
|
||||
seg.setOption(SEG_OPTION_SELECTED, elem["sel"] | seg.getOption(SEG_OPTION_SELECTED));
|
||||
seg.setOption(SEG_OPTION_REVERSED, elem["rev"] | seg.getOption(SEG_OPTION_REVERSED));
|
||||
seg.setOption(SEG_OPTION_MIRROR , elem[F("mi")] | seg.getOption(SEG_OPTION_MIRROR ));
|
||||
seg.selected = elem["sel"] | seg.selected;
|
||||
seg.reverse = elem["rev"] | seg.reverse;
|
||||
seg.mirror = elem[F("mi")] | seg.mirror;
|
||||
#ifndef WLED_DISABLE_2D
|
||||
seg.setOption(SEG_OPTION_REVERSED_Y, elem[F("rY")] | seg.getOption(SEG_OPTION_REVERSED_Y));
|
||||
seg.setOption(SEG_OPTION_MIRROR_Y , elem[F("mY")] | seg.getOption(SEG_OPTION_MIRROR_Y ));
|
||||
seg.setOption(SEG_OPTION_TRANSPOSED, elem[F("tp")] | seg.getOption(SEG_OPTION_TRANSPOSED));
|
||||
seg.reverse_y = elem[F("rY")] | seg.reverse_y;
|
||||
seg.mirror_y = elem[F("mY")] | seg.mirror_y;
|
||||
seg.transpose = elem[F("tp")] | seg.transpose;
|
||||
#endif
|
||||
|
||||
byte fx = seg.mode;
|
||||
@ -193,8 +193,8 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
sOpt = extractModeDefaults(fx, SET_F("c1")); if (sOpt >= 0) seg.custom1 = sOpt;
|
||||
sOpt = extractModeDefaults(fx, SET_F("c2")); if (sOpt >= 0) seg.custom2 = sOpt;
|
||||
sOpt = extractModeDefaults(fx, SET_F("c3")); if (sOpt >= 0) seg.custom3 = sOpt;
|
||||
sOpt = extractModeDefaults(fx, SET_F("mp12")); if (sOpt >= 0) seg.map1D2D = sOpt & 0x03;
|
||||
sOpt = extractModeDefaults(fx, SET_F("ssim")); if (sOpt >= 0) seg.soundSim = sOpt & 0x07;
|
||||
sOpt = extractModeDefaults(fx, SET_F("mp12")); if (sOpt >= 0) seg.map1D2D = sOpt & 0x07;
|
||||
sOpt = extractModeDefaults(fx, SET_F("ssim")); if (sOpt >= 0) seg.soundSim = sOpt & 0x03;
|
||||
sOpt = extractModeDefaults(fx, "rev"); if (sOpt >= 0) seg.reverse = (bool)sOpt;
|
||||
sOpt = extractModeDefaults(fx, SET_F("mi")); if (sOpt >= 0) seg.mirror = (bool)sOpt; // NOTE: setting this option is a risky business
|
||||
sOpt = extractModeDefaults(fx, SET_F("rY")); if (sOpt >= 0) seg.reverse_y = (bool)sOpt;
|
||||
@ -238,8 +238,8 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
strip.setBrightness(scaledBri(bri), true);
|
||||
|
||||
// freeze and init to black
|
||||
if (!seg.getOption(SEG_OPTION_FREEZE)) {
|
||||
seg.setOption(SEG_OPTION_FREEZE, true);
|
||||
if (!seg.freeze) {
|
||||
seg.freeze = true;
|
||||
seg.fill(BLACK);
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
|
||||
}
|
||||
// send UDP if not in preset and something changed that is not just selection
|
||||
// send UDP if something changed that is not just selection or segment power/opacity
|
||||
if ((seg.differs(prev) & 0x7E) && seg.getOption(SEG_OPTION_ON)==prev.getOption(SEG_OPTION_ON)) stateChanged = true;
|
||||
if ((seg.differs(prev) & 0x7E) && seg.on == prev.on) stateChanged = true;
|
||||
}
|
||||
|
||||
// deserializes WLED state (fileDoc points to doc object if called from web server)
|
||||
@ -315,10 +315,10 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
|
||||
|
||||
if (bri && !onBefore) { // unfreeze all segments when turning on
|
||||
for (size_t s=0; s < strip.getSegmentsNum(); s++) {
|
||||
strip.getSegment(s).setOption(SEG_OPTION_FREEZE, false);
|
||||
strip.getSegment(s).freeze = false;
|
||||
}
|
||||
if (realtimeMode && !realtimeOverride && useMainSegmentOnly) { // keep live segment frozen if live
|
||||
strip.getMainSegment().setOption(SEG_OPTION_FREEZE, true);
|
||||
strip.getMainSegment().freeze = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,7 +371,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
|
||||
realtimeOverride = root[F("lor")] | realtimeOverride;
|
||||
if (realtimeOverride > 2) realtimeOverride = REALTIME_OVERRIDE_ALWAYS;
|
||||
if (realtimeMode && useMainSegmentOnly) {
|
||||
strip.getMainSegment().setOption(SEG_OPTION_FREEZE, !realtimeOverride);
|
||||
strip.getMainSegment().freeze = !realtimeOverride;
|
||||
}
|
||||
|
||||
if (root.containsKey("live")) {
|
||||
@ -475,8 +475,8 @@ void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset, b
|
||||
root["grp"] = seg.grouping;
|
||||
root[F("spc")] = seg.spacing;
|
||||
root[F("of")] = seg.offset;
|
||||
root["on"] = seg.getOption(SEG_OPTION_ON);
|
||||
root["frz"] = seg.getOption(SEG_OPTION_FREEZE);
|
||||
root["on"] = seg.on;
|
||||
root["frz"] = seg.freeze;
|
||||
byte segbri = seg.opacity;
|
||||
root["bri"] = (segbri) ? segbri : 255;
|
||||
root["cct"] = seg.cct;
|
||||
@ -509,12 +509,12 @@ void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset, b
|
||||
root[F("c2")] = seg.custom2;
|
||||
root[F("c3")] = seg.custom3;
|
||||
root[F("sel")] = seg.isSelected();
|
||||
root["rev"] = seg.getOption(SEG_OPTION_REVERSED);
|
||||
root[F("mi")] = seg.getOption(SEG_OPTION_MIRROR);
|
||||
root["rev"] = seg.reverse;
|
||||
root[F("mi")] = seg.mirror;
|
||||
if (strip.isMatrix) {
|
||||
root[F("rY")] = seg.getOption(SEG_OPTION_REVERSED_Y);
|
||||
root[F("mY")] = seg.getOption(SEG_OPTION_MIRROR_Y);
|
||||
root[F("tp")] = seg.getOption(SEG_OPTION_TRANSPOSED);
|
||||
root[F("rY")] = seg.reverse_y;
|
||||
root[F("mY")] = seg.mirror_y;
|
||||
root[F("tp")] = seg.transpose;
|
||||
}
|
||||
root[F("o1")] = seg.check1;
|
||||
root[F("o2")] = seg.check2;
|
||||
|
@ -665,8 +665,8 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
||||
pos = req.indexOf(F("SV=")); //segment selected
|
||||
if (pos > 0) {
|
||||
byte t = getNumVal(&req, pos);
|
||||
if (t == 2) for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) strip.getSegment(i).setOption(SEG_OPTION_SELECTED, 0); // unselect other segments
|
||||
selseg.setOption(SEG_OPTION_SELECTED, t);
|
||||
if (t == 2) for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) strip.getSegment(i).selected = false; // unselect other segments
|
||||
selseg.selected = t;
|
||||
}
|
||||
|
||||
// temporary values, write directly to segments, globals are updated by setValuesFromFirstSelectedSeg()
|
||||
@ -705,15 +705,15 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
||||
strip.setSegment(selectedSeg, startI, stopI, grpI, spcI, UINT16_MAX, startY, stopY);
|
||||
|
||||
pos = req.indexOf(F("RV=")); //Segment reverse
|
||||
if (pos > 0) selseg.setOption(SEG_OPTION_REVERSED, req.charAt(pos+3) != '0');
|
||||
if (pos > 0) selseg.reverse = req.charAt(pos+3) != '0';
|
||||
|
||||
pos = req.indexOf(F("MI=")); //Segment mirror
|
||||
if (pos > 0) selseg.setOption(SEG_OPTION_MIRROR, req.charAt(pos+3) != '0');
|
||||
if (pos > 0) selseg.mirror = req.charAt(pos+3) != '0';
|
||||
|
||||
pos = req.indexOf(F("SB=")); //Segment brightness/opacity
|
||||
if (pos > 0) {
|
||||
byte segbri = getNumVal(&req, pos);
|
||||
selseg.setOption(SEG_OPTION_ON, segbri);
|
||||
selseg.on = segbri;
|
||||
if (segbri) {
|
||||
selseg.setOpacity(segbri);
|
||||
}
|
||||
@ -722,9 +722,9 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
||||
pos = req.indexOf(F("SW=")); //segment power
|
||||
if (pos > 0) {
|
||||
switch (getNumVal(&req, pos)) {
|
||||
case 0: selseg.setOption(SEG_OPTION_ON, false); break;
|
||||
case 1: selseg.setOption(SEG_OPTION_ON, true); break;
|
||||
default: selseg.setOption(SEG_OPTION_ON, !selseg.getOption(SEG_OPTION_ON)); break;
|
||||
case 0: selseg.on = false; break;
|
||||
case 1: selseg.on = true; break;
|
||||
default: selseg.on = !selseg.on; break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -981,7 +981,7 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
||||
realtimeOverride = getNumVal(&req, pos);
|
||||
if (realtimeOverride > 2) realtimeOverride = REALTIME_OVERRIDE_ALWAYS;
|
||||
if (realtimeMode && useMainSegmentOnly) {
|
||||
strip.getMainSegment().setOption(SEG_OPTION_FREEZE, !realtimeOverride);
|
||||
strip.getMainSegment().freeze = !realtimeOverride;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ void realtimeLock(uint32_t timeoutMs, byte md)
|
||||
Segment& mainseg = strip.getMainSegment();
|
||||
start = mainseg.start;
|
||||
stop = mainseg.stop;
|
||||
mainseg.setOption(SEG_OPTION_FREEZE, true);
|
||||
mainseg.freeze = true;
|
||||
} else {
|
||||
start = 0;
|
||||
stop = strip.getLengthTotal();
|
||||
@ -159,7 +159,7 @@ void realtimeLock(uint32_t timeoutMs, byte md)
|
||||
// if WLED was off and using main segment only, freeze non-main segments so they stay off
|
||||
if (useMainSegmentOnly && bri == 0) {
|
||||
for (size_t s=0; s < strip.getSegmentsNum(); s++) {
|
||||
strip.getSegment(s).setOption(SEG_OPTION_FREEZE, true);
|
||||
strip.getSegment(s).freeze = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -186,7 +186,7 @@ void exitRealtime() {
|
||||
realtimeMode = REALTIME_MODE_INACTIVE; // inform UI immediately
|
||||
realtimeIP[0] = 0;
|
||||
if (useMainSegmentOnly) { // unfreeze live segment again
|
||||
strip.getMainSegment().setOption(SEG_OPTION_FREEZE, false);
|
||||
strip.getMainSegment().freeze = false;
|
||||
}
|
||||
updateInterfaces(CALL_MODE_WS_SEND);
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ void deEEP() {
|
||||
for (byte j = 0; j < strip.getMaxSegments(); j++)
|
||||
{
|
||||
strip.getSegment(j).opacity = 255;
|
||||
strip.getSegment(j).setOption(SEG_OPTION_ON, 1);
|
||||
strip.getSegment(j).on = true;
|
||||
}
|
||||
}
|
||||
serializeState(pObj, true, false, true);
|
||||
|
Loading…
Reference in New Issue
Block a user