26 {
28 FL_WARN(
"WLED: setState called with invalid JSON");
29 return;
30 }
31
32
33 if (wledState.
contains(
"on") && wledState[
"on"].is_bool()) {
34 bool newOn = wledState[
"on"] |
mWledOn;
38 }
39 }
40
41
43 if (wledState["bri"].is_int()) {
45
46 if (briInt < 0) {
47 FL_WARN(
"WLED: brightness " << briInt <<
" out of range, clamping to 0");
48 briInt = 0;
49 } else if (briInt > 255) {
50 FL_WARN(
"WLED: brightness " << briInt <<
" out of range, clamping to 255");
51 briInt = 255;
52 }
53 u8 newBri =
static_cast<u8>(briInt);
57 }
58 } else {
59 FL_WARN(
"WLED: 'bri' field has invalid type (expected int)");
60 }
61 }
62
63
64 if (wledState.
contains(
"transition")) {
65 if (wledState["transition"].is_int()) {
67
68 if (transInt < 0) {
69 FL_WARN(
"WLED: transition " << transInt <<
" out of range, clamping to 0");
70 transInt = 0;
71 } else if (transInt > 65535) {
72 FL_WARN(
"WLED: transition " << transInt <<
" out of range, clamping to 65535");
73 transInt = 65535;
74 }
75 u16 newTransition = static_cast<u16>(transInt);
79 }
80 } else {
81 FL_WARN(
"WLED: 'transition' field has invalid type (expected int)");
82 }
83 }
84
85
87 if (wledState["ps"].is_int()) {
89
90 if (psInt < -1) {
91 FL_WARN(
"WLED: preset " << psInt <<
" out of range, clamping to -1");
92 psInt = -1;
93 } else if (psInt > 250) {
94 FL_WARN(
"WLED: preset " << psInt <<
" out of range, clamping to 250");
95 psInt = 250;
96 }
97 i16 newPreset = static_cast<i16>(psInt);
101 }
102 } else {
103 FL_WARN(
"WLED: 'ps' field has invalid type (expected int)");
104 }
105 }
106
107
109 if (wledState["pl"].is_int()) {
111
112 if (plInt < -1) {
113 FL_WARN(
"WLED: playlist " << plInt <<
" out of range, clamping to -1");
114 plInt = -1;
115 } else if (plInt > 250) {
116 FL_WARN(
"WLED: playlist " << plInt <<
" out of range, clamping to 250");
117 plInt = 250;
118 }
119 i16 newPlaylist = static_cast<i16>(plInt);
123 }
124 } else {
125 FL_WARN(
"WLED: 'pl' field has invalid type (expected int)");
126 }
127 }
128
129
131 if (wledState["lor"].is_int()) {
133
134 if (lorInt < 0) {
135 FL_WARN(
"WLED: live override " << lorInt <<
" out of range, clamping to 0");
136 lorInt = 0;
137 } else if (lorInt > 2) {
138 FL_WARN(
"WLED: live override " << lorInt <<
" out of range, clamping to 2");
139 lorInt = 2;
140 }
141 u8 newLiveOverride =
static_cast<u8>(lorInt);
145 }
146 } else {
147 FL_WARN(
"WLED: 'lor' field has invalid type (expected int)");
148 }
149 }
150
151
152 if (wledState.
contains(
"mainseg")) {
153 if (wledState["mainseg"].is_int()) {
155
156 if (mainsegInt < 0) {
157 FL_WARN(
"WLED: main segment " << mainsegInt <<
" out of range, clamping to 0");
158 mainsegInt = 0;
159 } else if (mainsegInt > 255) {
160 FL_WARN(
"WLED: main segment " << mainsegInt <<
" out of range, clamping to 255");
161 mainsegInt = 255;
162 }
163 u8 newMainSegment =
static_cast<u8>(mainsegInt);
167 }
168 } else {
169 FL_WARN(
"WLED: 'mainseg' field has invalid type (expected int)");
170 }
171 }
172
173
175 if (wledState["nl"].is_object()) {
176 const fl::json& nl = wledState["nl"];
177
178
179 if (nl.
contains(
"on") && nl[
"on"].is_bool()) {
184 }
185 }
186
187
189 if (nl["dur"].is_int()) {
191
192 if (durInt < 1) {
193 FL_WARN(
"WLED: nl.dur " << durInt <<
" out of range, clamping to 1");
194 durInt = 1;
195 } else if (durInt > 255) {
196 FL_WARN(
"WLED: nl.dur " << durInt <<
" out of range, clamping to 255");
197 durInt = 255;
198 }
199 u8 newDur =
static_cast<u8>(durInt);
203 }
204 } else {
205 FL_WARN(
"WLED: 'nl.dur' field has invalid type (expected int)");
206 }
207 }
208
209
211 if (nl["mode"].is_int()) {
213
214 if (modeInt < 0) {
215 FL_WARN(
"WLED: nl.mode " << modeInt <<
" out of range, clamping to 0");
216 modeInt = 0;
217 } else if (modeInt > 3) {
218 FL_WARN(
"WLED: nl.mode " << modeInt <<
" out of range, clamping to 3");
219 modeInt = 3;
220 }
221 u8 newMode =
static_cast<u8>(modeInt);
225 }
226 } else {
227 FL_WARN(
"WLED: 'nl.mode' field has invalid type (expected int)");
228 }
229 }
230
231
233 if (nl["tbri"].is_int()) {
235
236 if (tbriInt < 0) {
237 FL_WARN(
"WLED: nl.tbri " << tbriInt <<
" out of range, clamping to 0");
238 tbriInt = 0;
239 } else if (tbriInt > 255) {
240 FL_WARN(
"WLED: nl.tbri " << tbriInt <<
" out of range, clamping to 255");
241 tbriInt = 255;
242 }
243 u8 newTbri =
static_cast<u8>(tbriInt);
247 }
248 } else {
249 FL_WARN(
"WLED: 'nl.tbri' field has invalid type (expected int)");
250 }
251 }
252 } else {
253 FL_WARN(
"WLED: 'nl' field has invalid type (expected object)");
254 }
255 }
256
257
259 if (wledState["udpn"].is_object()) {
260 const fl::json& udpn = wledState["udpn"];
261
262
263 if (udpn.
contains(
"send") && udpn[
"send"].is_bool()) {
264 bool newSend = udpn[
"send"] |
mUdpSend;
268 }
269 }
270
271
272 if (udpn.
contains(
"recv") && udpn[
"recv"].is_bool()) {
277 }
278 }
279 } else {
280 FL_WARN(
"WLED: 'udpn' field has invalid type (expected object)");
281 }
282 }
283
284
285 if (wledState.
contains(
"playlist")) {
286 if (wledState["playlist"].is_object()) {
287 const fl::json& pl = wledState["playlist"];
288
289
290 if (pl.
contains(
"ps") && pl[
"ps"].is_array()) {
292 for (
size_t i = 0; i < pl[
"ps"].
size(); i++) {
293 if (pl["ps"][i].is_int()) {
294 i64 psInt = pl[
"ps"][i] | -1;
295
296 if (psInt < -1) psInt = -1;
297 if (psInt > 250) psInt = 250;
299 }
300 }
302 }
303
304
305 if (pl.
contains(
"dur") && pl[
"dur"].is_array()) {
307 for (
size_t i = 0; i < pl[
"dur"].
size(); i++) {
308 if (pl["dur"][i].is_int()) {
309 i64 durInt = pl[
"dur"][i] | 0;
310 if (durInt < 0) durInt = 0;
311 if (durInt > 65535) durInt = 65535;
313 }
314 }
315 }
316
317
318 if (pl.
contains(
"transition") && pl[
"transition"].is_array()) {
320 for (
size_t i = 0; i < pl[
"transition"].
size(); i++) {
321 if (pl["transition"][i].is_int()) {
322 i64 transInt = pl[
"transition"][i] | 0;
323 if (transInt < 0) transInt = 0;
324 if (transInt > 65535) transInt = 65535;
326 }
327 }
328 }
329
330
331 if (pl.
contains(
"repeat") && pl[
"repeat"].is_int()) {
332 i64 repeatInt = pl[
"repeat"] | 0;
333 if (repeatInt < 0) repeatInt = 0;
334 if (repeatInt > 65535) repeatInt = 65535;
337 }
338
339
340 if (pl.
contains(
"end") && pl[
"end"].is_int()) {
341 i64 endInt = pl[
"end"] | -1;
342 if (endInt < -1) endInt = -1;
343 if (endInt > 250) endInt = 250;
346 }
347
348
349 if (pl.
contains(
"r") && pl[
"r"].is_bool()) {
352 }
353 } else {
354 FL_WARN(
"WLED: 'playlist' field has invalid type (expected object)");
355 }
356 }
357
358
360 if (wledState["seg"].is_array()) {
361 for (
size_t i = 0; i < wledState[
"seg"].
size(); i++) {
362 const fl::json& segJson = wledState["seg"][i];
364 FL_WARN(
"WLED: segment at index " << i <<
" is not an object");
365 continue;
366 }
367
368
370 if (segJson.
contains(
"id") && segJson[
"id"].is_int()) {
371 i64 idInt = segJson[
"id"] | 0;
372 if (idInt < 0) idInt = 0;
373 if (idInt > 255) idInt = 255;
374 segId =
static_cast<u8>(idInt);
375 } else {
376
377 segId =
static_cast<u8>(i);
378 }
379
380
381 WLEDSegment* seg = nullptr;
382 for (
size_t j = 0; j <
mSegments.size(); j++) {
385 break;
386 }
387 }
388 if (!seg) {
389
390 WLEDSegment newSeg;
391 newSeg.mId = segId;
394 }
395
396
398 }
399 } else {
400 FL_WARN(
"WLED: 'seg' field has invalid type (expected array)");
401 }
402 }
403}
fl::vector< u16 > mPlaylistDurations
fl::vector< u16 > mPlaylistTransitions
u8 mNightlightTargetBrightness
fl::vector< i16 > mPlaylistPresets
fl::vector< WLEDSegment > mSegments
bool has_value() const FL_NOEXCEPT
bool is_object() const FL_NOEXCEPT
size_t size() const FL_NOEXCEPT
bool contains(size_t idx) const FL_NOEXCEPT
void parseSegmentFields(const fl::json &segJson, WLEDSegment &seg)
Parse all fields from a segment JSON object into a WLEDSegment.