FastLED 3.9.15
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 405 of file wled.cpp.hpp.

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

References fl::json::array(), fl::basic_string::c_str(), 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: