Replace setOption/getOption

This commit is contained in:
Blaz Kristan 2022-08-19 21:14:49 +02:00
parent f7652bd2ef
commit 44a4b11d36
8 changed files with 85 additions and 81 deletions

View File

@ -75,7 +75,7 @@ int8_t tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec) {
*/
uint16_t mode_static(void) {
SEGMENT.fill(SEGCOLOR(0));
return /*(SEGMENT.getOption(SEG_OPTION_TRANSITIONAL)) ? FRAMETIME :*/ 350; //update faster if in transition
return 350;
}
static const char _data_FX_MODE_STATIC[] PROGMEM = "Solid";
@ -3986,7 +3986,7 @@ uint16_t mode_flow(void)
{
uint8_t colorIndex = (i * 255 / zoneLen) - counter;
uint16_t led = (z & 0x01) ? i : (zoneLen -1) -i;
if (SEGMENT.getOption(SEG_OPTION_REVERSED)) led = (zoneLen -1) -led;
if (SEGMENT.reverse) led = (zoneLen -1) -led;
SEGMENT.setPixelColor(pos + led, SEGMENT.color_from_palette(colorIndex, false, true, 255));
}
}
@ -4927,7 +4927,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
SEGENV.aux1 = SEGENV.aux0;
SEGENV.aux0 = crc;
return (SEGMENT.getOption(SEG_OPTION_TRANSITIONAL)) ? FRAMETIME : FRAMETIME_FIXED * (128-(SEGMENT.speed>>1)); // update only when appropriate time passes (in 42 FPS slots)
return FRAMETIME_FIXED * (128-(SEGMENT.speed>>1)); // update only when appropriate time passes (in 42 FPS slots)
} // mode_2Dgameoflife()
static const char _data_FX_MODE_2DGAMEOFLIFE[] PROGMEM = "Game Of Life@!,;!,!;!;2d";

View File

@ -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)
@ -357,34 +357,38 @@ typedef struct Segment {
union {
uint16_t options; //bit pattern: msb first: [transposed mirrorY reverseY] transitional (tbd) paused needspixelstate mirrored on reverse selected
struct {
bool selected : 1; // 0 : selected
bool reverse : 1; // 1 : reversed
bool on : 1; // 2 : is On
bool mirror : 1; // 3 : mirrored
bool pxs : 1; // 4 : indicates that the effect does not use FRAMETIME or needs getPixelColor (?)
bool freeze : 1; // 5 : paused/frozen
bool reset : 1; // 6 : indicates that Segment runtime requires reset
bool transitional: 1; // 7 : transitional (there is transition occuring)
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
bool selected : 1; // 0 : selected
bool reverse : 1; // 1 : reversed
bool on : 1; // 2 : is On
bool mirror : 1; // 3 : mirrored
bool pxs : 1; // 4 : indicates that the effect does not use FRAMETIME or needs getPixelColor (?)
bool freeze : 1; // 5 : paused/frozen
bool reset : 1; // 6 : indicates that Segment runtime requires reset
bool transitional: 1; // 7 : transitional (there is transition occuring)
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 : 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
uint8_t custom1, custom2; // custom FX parameters/sliders
uint8_t cct; //0==1900K, 255==10091K
uint8_t custom1, custom2; // custom FX parameters/sliders
struct {
uint8_t custom3 : 5; // reduced range slider (0-31)
bool check1 : 1; // checkmark 1
bool check2 : 1; // checkmark 2
bool check3 : 1; // checkmark 3
uint8_t custom3 : 5; // reduced range slider (0-31)
bool check1 : 1; // checkmark 1
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

View File

@ -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;

View File

@ -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);

View File

@ -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")) {
@ -472,14 +472,14 @@ void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset, b
}
}
if (!forPreset) root["len"] = seg.stop - seg.start;
root["grp"] = seg.grouping;
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);
byte segbri = seg.opacity;
root["bri"] = (segbri) ? segbri : 255;
root["cct"] = seg.cct;
root[F("of")] = seg.offset;
root["on"] = seg.on;
root["frz"] = seg.freeze;
byte segbri = seg.opacity;
root["bri"] = (segbri) ? segbri : 255;
root["cct"] = seg.cct;
if (segmentBounds && seg.name != nullptr) root["n"] = reinterpret_cast<const char *>(seg.name); //not good practice, but decreases required JSON buffer
@ -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;

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -414,10 +414,10 @@ void deEEP() {
for (byte j = 0; j < numChannels; j++) colX.add(EEPROM.read(memloc + j));
}
segObj["fx"] = EEPROM.read(i+10);
segObj[F("sx")] = EEPROM.read(i+11);
segObj[F("ix")] = EEPROM.read(i+16);
segObj["pal"] = EEPROM.read(i+17);
segObj["fx"] = EEPROM.read(i+10);
segObj[F("sx")] = EEPROM.read(i+11);
segObj[F("ix")] = EEPROM.read(i+16);
segObj["pal"] = EEPROM.read(i+17);
} else {
Segment* seg = strip.getSegments();
memcpy(seg, EEPROM.getDataPtr() +i+2, 240);
@ -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);