29 {
31 FL_WARN(
"WLED: setState called with invalid JSON");
32 return;
33 }
34
35
36 if (wledState.
contains(
"on") && wledState[
"on"].is_bool()) {
37 bool newOn = wledState[
"on"] |
mWledOn;
41 }
42 }
43
44
46 if (wledState["bri"].is_int()) {
48
49 if (briInt < 0) {
50 FL_WARN(
"WLED: brightness " << briInt <<
" out of range, clamping to 0");
51 briInt = 0;
52 } else if (briInt > 255) {
53 FL_WARN(
"WLED: brightness " << briInt <<
" out of range, clamping to 255");
54 briInt = 255;
55 }
56 u8 newBri =
static_cast<u8>(briInt);
60 }
61 } else {
62 FL_WARN(
"WLED: 'bri' field has invalid type (expected int)");
63 }
64 }
65
66
67 if (wledState.
contains(
"transition")) {
68 if (wledState["transition"].is_int()) {
70
71 if (transInt < 0) {
72 FL_WARN(
"WLED: transition " << transInt <<
" out of range, clamping to 0");
73 transInt = 0;
74 } else if (transInt > 65535) {
75 FL_WARN(
"WLED: transition " << transInt <<
" out of range, clamping to 65535");
76 transInt = 65535;
77 }
78 u16 newTransition = static_cast<u16>(transInt);
82 }
83 } else {
84 FL_WARN(
"WLED: 'transition' field has invalid type (expected int)");
85 }
86 }
87
88
90 if (wledState["ps"].is_int()) {
92
93 if (psInt < -1) {
94 FL_WARN(
"WLED: preset " << psInt <<
" out of range, clamping to -1");
95 psInt = -1;
96 } else if (psInt > 250) {
97 FL_WARN(
"WLED: preset " << psInt <<
" out of range, clamping to 250");
98 psInt = 250;
99 }
100 i16 newPreset = static_cast<i16>(psInt);
104 }
105 } else {
106 FL_WARN(
"WLED: 'ps' field has invalid type (expected int)");
107 }
108 }
109
110
112 if (wledState["pl"].is_int()) {
114
115 if (plInt < -1) {
116 FL_WARN(
"WLED: playlist " << plInt <<
" out of range, clamping to -1");
117 plInt = -1;
118 } else if (plInt > 250) {
119 FL_WARN(
"WLED: playlist " << plInt <<
" out of range, clamping to 250");
120 plInt = 250;
121 }
122 i16 newPlaylist = static_cast<i16>(plInt);
126 }
127 } else {
128 FL_WARN(
"WLED: 'pl' field has invalid type (expected int)");
129 }
130 }
131
132
134 if (wledState["lor"].is_int()) {
136
137 if (lorInt < 0) {
138 FL_WARN(
"WLED: live override " << lorInt <<
" out of range, clamping to 0");
139 lorInt = 0;
140 } else if (lorInt > 2) {
141 FL_WARN(
"WLED: live override " << lorInt <<
" out of range, clamping to 2");
142 lorInt = 2;
143 }
144 u8 newLiveOverride =
static_cast<u8>(lorInt);
148 }
149 } else {
150 FL_WARN(
"WLED: 'lor' field has invalid type (expected int)");
151 }
152 }
153
154
155 if (wledState.
contains(
"mainseg")) {
156 if (wledState["mainseg"].is_int()) {
158
159 if (mainsegInt < 0) {
160 FL_WARN(
"WLED: main segment " << mainsegInt <<
" out of range, clamping to 0");
161 mainsegInt = 0;
162 } else if (mainsegInt > 255) {
163 FL_WARN(
"WLED: main segment " << mainsegInt <<
" out of range, clamping to 255");
164 mainsegInt = 255;
165 }
166 u8 newMainSegment =
static_cast<u8>(mainsegInt);
170 }
171 } else {
172 FL_WARN(
"WLED: 'mainseg' field has invalid type (expected int)");
173 }
174 }
175
176
178 if (wledState["nl"].is_object()) {
179 const fl::json& nl = wledState["nl"];
180
181
182 if (nl.
contains(
"on") && nl[
"on"].is_bool()) {
187 }
188 }
189
190
192 if (nl["dur"].is_int()) {
194
195 if (durInt < 1) {
196 FL_WARN(
"WLED: nl.dur " << durInt <<
" out of range, clamping to 1");
197 durInt = 1;
198 } else if (durInt > 255) {
199 FL_WARN(
"WLED: nl.dur " << durInt <<
" out of range, clamping to 255");
200 durInt = 255;
201 }
202 u8 newDur =
static_cast<u8>(durInt);
206 }
207 } else {
208 FL_WARN(
"WLED: 'nl.dur' field has invalid type (expected int)");
209 }
210 }
211
212
214 if (nl["mode"].is_int()) {
216
217 if (modeInt < 0) {
218 FL_WARN(
"WLED: nl.mode " << modeInt <<
" out of range, clamping to 0");
219 modeInt = 0;
220 } else if (modeInt > 3) {
221 FL_WARN(
"WLED: nl.mode " << modeInt <<
" out of range, clamping to 3");
222 modeInt = 3;
223 }
224 u8 newMode =
static_cast<u8>(modeInt);
228 }
229 } else {
230 FL_WARN(
"WLED: 'nl.mode' field has invalid type (expected int)");
231 }
232 }
233
234
236 if (nl["tbri"].is_int()) {
238
239 if (tbriInt < 0) {
240 FL_WARN(
"WLED: nl.tbri " << tbriInt <<
" out of range, clamping to 0");
241 tbriInt = 0;
242 } else if (tbriInt > 255) {
243 FL_WARN(
"WLED: nl.tbri " << tbriInt <<
" out of range, clamping to 255");
244 tbriInt = 255;
245 }
246 u8 newTbri =
static_cast<u8>(tbriInt);
250 }
251 } else {
252 FL_WARN(
"WLED: 'nl.tbri' field has invalid type (expected int)");
253 }
254 }
255 } else {
256 FL_WARN(
"WLED: 'nl' field has invalid type (expected object)");
257 }
258 }
259
260
262 if (wledState["udpn"].is_object()) {
263 const fl::json& udpn = wledState["udpn"];
264
265
266 if (udpn.
contains(
"send") && udpn[
"send"].is_bool()) {
267 bool newSend = udpn[
"send"] |
mUdpSend;
271 }
272 }
273
274
275 if (udpn.
contains(
"recv") && udpn[
"recv"].is_bool()) {
280 }
281 }
282 } else {
283 FL_WARN(
"WLED: 'udpn' field has invalid type (expected object)");
284 }
285 }
286
287
288 if (wledState.
contains(
"playlist")) {
289 if (wledState["playlist"].is_object()) {
290 const fl::json& pl = wledState["playlist"];
291
292
293 if (pl.
contains(
"ps") && pl[
"ps"].is_array()) {
295 for (
size_t i = 0; i < pl[
"ps"].
size(); i++) {
296 if (pl["ps"][i].is_int()) {
297 i64 psInt = pl[
"ps"][i] | -1;
298
299 if (psInt < -1) psInt = -1;
300 if (psInt > 250) psInt = 250;
302 }
303 }
305 }
306
307
308 if (pl.
contains(
"dur") && pl[
"dur"].is_array()) {
310 for (
size_t i = 0; i < pl[
"dur"].
size(); i++) {
311 if (pl["dur"][i].is_int()) {
312 i64 durInt = pl[
"dur"][i] | 0;
313 if (durInt < 0) durInt = 0;
314 if (durInt > 65535) durInt = 65535;
316 }
317 }
318 }
319
320
321 if (pl.
contains(
"transition") && pl[
"transition"].is_array()) {
323 for (
size_t i = 0; i < pl[
"transition"].
size(); i++) {
324 if (pl["transition"][i].is_int()) {
325 i64 transInt = pl[
"transition"][i] | 0;
326 if (transInt < 0) transInt = 0;
327 if (transInt > 65535) transInt = 65535;
329 }
330 }
331 }
332
333
334 if (pl.
contains(
"repeat") && pl[
"repeat"].is_int()) {
335 i64 repeatInt = pl[
"repeat"] | 0;
336 if (repeatInt < 0) repeatInt = 0;
337 if (repeatInt > 65535) repeatInt = 65535;
340 }
341
342
343 if (pl.
contains(
"end") && pl[
"end"].is_int()) {
344 i64 endInt = pl[
"end"] | -1;
345 if (endInt < -1) endInt = -1;
346 if (endInt > 250) endInt = 250;
349 }
350
351
352 if (pl.
contains(
"r") && pl[
"r"].is_bool()) {
355 }
356 } else {
357 FL_WARN(
"WLED: 'playlist' field has invalid type (expected object)");
358 }
359 }
360
361
363 if (wledState["seg"].is_array()) {
364 for (
size_t i = 0; i < wledState[
"seg"].
size(); i++) {
365 const fl::json& segJson = wledState["seg"][i];
367 FL_WARN(
"WLED: segment at index " << i <<
" is not an object");
368 continue;
369 }
370
371
373 if (segJson.
contains(
"id") && segJson[
"id"].is_int()) {
374 i64 idInt = segJson[
"id"] | 0;
375 if (idInt < 0) idInt = 0;
376 if (idInt > 255) idInt = 255;
377 segId =
static_cast<u8>(idInt);
378 } else {
379
380 segId =
static_cast<u8>(i);
381 }
382
383
384 WLEDSegment* seg = nullptr;
385 for (
size_t j = 0; j <
mSegments.size(); j++) {
388 break;
389 }
390 }
391 if (!seg) {
392
393 WLEDSegment newSeg;
394 newSeg.mId = segId;
397 }
398
399
401 }
402 } else {
403 FL_WARN(
"WLED: 'seg' field has invalid type (expected array)");
404 }
405 }
406}
fl::vector< u16 > mPlaylistDurations
fl::vector< u16 > mPlaylistTransitions
u8 mNightlightTargetBrightness
fl::vector< i16 > mPlaylistPresets
fl::vector< WLEDSegment > mSegments
bool is_object() const FL_NO_EXCEPT
size_t size() const FL_NO_EXCEPT
bool has_value() const FL_NO_EXCEPT
bool contains(size_t idx) const FL_NO_EXCEPT
void parseSegmentFields(const fl::json &segJson, WLEDSegment &seg) FL_NO_EXCEPT
Parse all fields from a segment JSON object into a WLEDSegment.