FastLED 3.10.8
Loading...
Searching...
No Matches

◆ getState()

fl::json fl::WLED::getState ( ) const

Get current WLED state as JSON object.

Returns
JSON object with "on" and "bri" fields

Example: fl::json state = remote.getState(); // Returns: {"on":true,"bri":128}

Definition at line 408 of file wled.cpp.hpp.

408 {
409 fl::json state = fl::json::object();
410 state.set("on", mWledOn);
411 state.set("bri", static_cast<i64>(mWledBri));
412 state.set("transition", static_cast<i64>(mTransition));
413 state.set("ps", static_cast<i64>(mPreset));
414 state.set("pl", static_cast<i64>(mPlaylist));
415 state.set("lor", static_cast<i64>(mLiveOverride));
416 state.set("mainseg", static_cast<i64>(mMainSegment));
417
418 // Nightlight object
419 fl::json nl = fl::json::object();
420 nl.set("on", mNightlightOn);
421 nl.set("dur", static_cast<i64>(mNightlightDuration));
422 nl.set("mode", static_cast<i64>(mNightlightMode));
423 nl.set("tbri", static_cast<i64>(mNightlightTargetBrightness));
424 state.set("nl", nl);
425
426 // UDP sync settings
427 fl::json udpn = fl::json::object();
428 udpn.set("send", mUdpSend);
429 udpn.set("recv", mUdpReceive);
430 state.set("udpn", udpn);
431
432 // Playlist configuration (if present)
433 if (hasPlaylistConfig()) {
434 state.set("playlist", getPlaylistConfig());
435 }
436
437 // Segments
438 if (!mSegments.empty()) {
439 fl::json segments = fl::json::array();
440 for (const auto& seg : mSegments) {
441 fl::json segJson = fl::json::object();
442
443 segJson.set("id", static_cast<i64>(seg.mId));
444 segJson.set("start", static_cast<i64>(seg.mStart));
445 segJson.set("stop", static_cast<i64>(seg.mStop));
446 segJson.set("len", static_cast<i64>(seg.mLen));
447 segJson.set("grp", static_cast<i64>(seg.mGrp));
448 segJson.set("spc", static_cast<i64>(seg.mSpc));
449 segJson.set("of", static_cast<i64>(seg.mOf));
450 segJson.set("on", seg.mOn);
451 segJson.set("bri", static_cast<i64>(seg.mBri));
452 segJson.set("cct", static_cast<i64>(seg.mCct));
453
454 // Effect properties
455 segJson.set("fx", static_cast<i64>(seg.mFx));
456 segJson.set("sx", static_cast<i64>(seg.mSx));
457 segJson.set("ix", static_cast<i64>(seg.mIx));
458 segJson.set("pal", static_cast<i64>(seg.mPal));
459 segJson.set("c1", static_cast<i64>(seg.mC1));
460 segJson.set("c2", static_cast<i64>(seg.mC2));
461 segJson.set("c3", static_cast<i64>(seg.mC3));
462
463 // Boolean flags
464 segJson.set("sel", seg.mSel);
465 segJson.set("rev", seg.mRev);
466 segJson.set("mi", seg.mMi);
467 segJson.set("o1", seg.mO1);
468 segJson.set("o2", seg.mO2);
469 segJson.set("o3", seg.mO3);
470 segJson.set("si", static_cast<i64>(seg.mSi));
471 segJson.set("m12", static_cast<i64>(seg.mM12));
472 segJson.set("rpt", seg.mRpt);
473
474 if (!seg.mName.empty()) {
475 segJson.set("n", seg.mName);
476 }
477
478 // Colors
479 if (!seg.mColors.empty()) {
480 fl::json colors = fl::json::array();
481 for (const auto& color : seg.mColors) {
482 if (color.size() >= 3) {
483 fl::json colorArray = fl::json::array();
484 for (size_t i = 0; i < color.size(); i++) {
485 colorArray.push_back(fl::json(static_cast<i64>(color[i])));
486 }
487 colors.push_back(colorArray);
488 }
489 }
490 segJson.set("col", colors);
491 }
492
493 // Individual LEDs
494 if (!seg.mIndividualLeds.empty()) {
495 fl::json leds = fl::json::array();
496 for (const auto& led : seg.mIndividualLeds) {
497 if (led.size() >= 3) {
498 fl::string hexColor = wled::rgbToHex(led[0], led[1], led[2]);
499 leds.push_back(fl::json(hexColor.c_str()));
500 }
501 }
502 segJson.set("i", leds);
503 }
504
505 segments.push_back(segJson);
506 }
507 state.set("seg", segments);
508 }
509
510 return state;
511}
CRGB leds[1]
TestState state
bool mNightlightOn
Definition wled.h:441
bool hasPlaylistConfig() const FL_NO_EXCEPT
Check if playlist is active.
Definition wled.h:372
u8 mWledBri
Definition wled.h:433
u8 mLiveOverride
Definition wled.h:437
u16 mTransition
Definition wled.h:434
u8 mNightlightTargetBrightness
Definition wled.h:444
fl::json getPlaylistConfig() const FL_NO_EXCEPT
Get playlist configuration.
Definition wled.cpp.hpp:513
u8 mNightlightDuration
Definition wled.h:442
bool mUdpSend
Definition wled.h:455
bool mUdpReceive
Definition wled.h:456
i16 mPreset
Definition wled.h:435
i16 mPlaylist
Definition wled.h:436
bool mWledOn
Definition wled.h:432
fl::vector< WLEDSegment > mSegments
Definition wled.h:459
u8 mMainSegment
Definition wled.h:438
u8 mNightlightMode
Definition wled.h:443
const char * c_str() const FL_NO_EXCEPT
void set(const fl::string &key, const json &value) FL_NO_EXCEPT
Definition json.h:866
void push_back(const json &value) FL_NO_EXCEPT
Definition json.h:918
static json object() FL_NO_EXCEPT
Definition json.h:857
static json array() FL_NO_EXCEPT
Definition json.h:853
fl::string rgbToHex(u8 r, u8 g, u8 b) FL_NO_EXCEPT
Convert RGB components to hex string.
fl::i64 i64
Definition stdint.h:221

References fl::json::array(), fl::basic_string::c_str(), fl::FL_NO_EXCEPT, getPlaylistConfig(), hasPlaylistConfig(), leds, mLiveOverride, mMainSegment, mNightlightDuration, mNightlightMode, mNightlightOn, mNightlightTargetBrightness, mPlaylist, mPreset, mSegments, mTransition, mUdpReceive, mUdpSend, mWledBri, mWledOn, fl::json::object(), fl::json::push_back(), fl::wled::rgbToHex(), fl::json::set(), and state.

+ Here is the call graph for this function: