FastLED 3.9.15
Loading...
Searching...
No Matches
wled.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/remote/remote.h"
4#include "fl/stl/vector.h"
5#include "fl/stl/span.h" // IWYU pragma: keep
6#include "fl/stl/memory.h" // IWYU pragma: keep
7#include "fl/stl/shared_ptr.h" // IWYU pragma: keep
8
9// WLED subdirectory components (always available)
10#include "fl/fx/wled/ifastled.h" // IWYU pragma: keep
11#include "fl/fx/wled/adapter.h" // IWYU pragma: keep
12#include "fl/fx/wled/client.h" // IWYU pragma: keep
13
14// WLED-specific Remote extension requires JSON support
15#include "fl/fx/wled/segment.h"
16#include "fl/fx/wled/json_helpers.h" // IWYU pragma: keep
17#include "fl/stl/noexcept.h"
18
19namespace fl {
20
246class WLED : public Remote {
247public:
258
270 WLED(RequestSource source, ResponseSink sink) : Remote(source, sink) {}
271
284 void setState(const fl::json& wledState);
285
294 fl::json getState() const;
295
300 bool getOn() const { return mWledOn; }
301
306 u8 getBrightness() const { return mWledBri; }
307
312 u16 getTransition() const { return mTransition; }
313
318 i16 getPreset() const { return mPreset; }
319
324 i16 getPlaylist() const { return mPlaylist; }
325
330 u8 getLiveOverride() const { return mLiveOverride; }
331
336 u8 getMainSegment() const { return mMainSegment; }
337
342 bool getNightlightOn() const { return mNightlightOn; }
343
349
355
361
367
372 bool hasPlaylistConfig() const { return !mPlaylistPresets.empty(); }
373
378 bool getUdpSend() const { return mUdpSend; }
379
384 bool getUdpReceive() const { return mUdpReceive; }
385
390 size_t getSegmentCount() const { return mSegments.size(); }
391
397 const WLEDSegment& getSegment(size_t index) const { return mSegments[index]; }
398
404
410 const WLEDSegment* findSegmentById(u8 id) const;
411
412private:
421
429 void stubResponseSink(const fl::json& response);
430
431 // WLED state (runtime-only, no persistence)
432 bool mWledOn = false; // WLED on/off state
433 u8 mWledBri = 255; // WLED brightness (0-255)
434 u16 mTransition = 7; // Crossfade duration (×100ms, default 700ms)
435 i16 mPreset = -1; // Active preset ID (-1 = none)
436 i16 mPlaylist = -1; // Active playlist ID (-1 = none)
437 u8 mLiveOverride = 0; // Live data override (0=off, 1=override, 2=until reboot)
438 u8 mMainSegment = 0; // Main segment for global controls
439
440 // Nightlight state
441 bool mNightlightOn = false; // Nightlight active
442 u8 mNightlightDuration = 60; // Nightlight duration in minutes (default 60)
443 u8 mNightlightMode = 1; // Nightlight mode (0=instant, 1=fade, 2=color, 3=sunrise)
444 u8 mNightlightTargetBrightness = 0; // Target brightness for nightlight end
445
446 // Playlist configuration
447 fl::vector<i16> mPlaylistPresets; // Array of preset IDs to cycle through
448 fl::vector<u16> mPlaylistDurations; // Array of durations (seconds) for each preset
449 fl::vector<u16> mPlaylistTransitions; // Array of transition times (×100ms) for each preset
450 u16 mPlaylistRepeat = 0; // Number of cycles (0=infinite)
451 i16 mPlaylistEnd = -1; // End preset ID (after playlist completes, -1=none)
452 bool mPlaylistRandomize = false; // True for randomized playback order
453
454 // UDP sync settings
455 bool mUdpSend = false; // Send UDP broadcast packets on state change
456 bool mUdpReceive = true; // Receive UDP broadcast packets
457
458 // Segment configurations
459 fl::vector<WLEDSegment> mSegments; // Array of segment configurations
460};
461
462} // namespace fl
Remote(RequestSource source, ResponseSink sink)
Construct with I/O callbacks.
fl::function< fl::optional< fl::json >()> RequestSource
Definition server.h:29
fl::function< void(const fl::json &)> ResponseSink
Definition server.h:30
fl::json getPlaylistConfig() const
Get playlist configuration.
Definition wled.cpp.hpp:510
fl::vector< u16 > mPlaylistDurations
Definition wled.h:448
void setState(const fl::json &wledState)
Set WLED state from JSON object.
Definition wled.cpp.hpp:26
bool mNightlightOn
Definition wled.h:441
fl::vector< u16 > mPlaylistTransitions
Definition wled.h:449
const WLEDSegment & getSegment(size_t index) const
Get segment by index.
Definition wled.h:397
u8 mWledBri
Definition wled.h:433
const fl::vector< WLEDSegment > & getSegments() const
Get all segments.
Definition wled.h:403
i16 mPlaylistEnd
Definition wled.h:451
bool getUdpSend() const
Get UDP sync send setting.
Definition wled.h:378
void stubResponseSink(const fl::json &response)
Stub response sink callback.
Definition wled.cpp.hpp:20
fl::optional< fl::json > stubRequestSource()
Stub request source callback.
Definition wled.cpp.hpp:15
u8 mLiveOverride
Definition wled.h:437
u16 mTransition
Definition wled.h:434
bool getUdpReceive() const
Get UDP sync receive setting.
Definition wled.h:384
u8 getBrightness() const
Get WLED brightness.
Definition wled.h:306
u8 mNightlightTargetBrightness
Definition wled.h:444
u8 getNightlightDuration() const
Get nightlight duration.
Definition wled.h:348
WLED(RequestSource source, ResponseSink sink)
Construct WLED with custom I/O callbacks.
Definition wled.h:270
u8 mNightlightDuration
Definition wled.h:442
bool mUdpSend
Definition wled.h:455
bool getNightlightOn() const
Get nightlight active state.
Definition wled.h:342
bool mUdpReceive
Definition wled.h:456
size_t getSegmentCount() const
Get segment count.
Definition wled.h:390
u8 getLiveOverride() const
Get live data override setting.
Definition wled.h:330
i16 mPreset
Definition wled.h:435
i16 mPlaylist
Definition wled.h:436
fl::vector< i16 > mPlaylistPresets
Definition wled.h:447
WLED() FL_NOEXCEPT
Construct WLED with default stub I/O callbacks.
Definition wled.cpp.hpp:9
i16 getPreset() const
Get active preset ID.
Definition wled.h:318
bool mWledOn
Definition wled.h:432
bool mPlaylistRandomize
Definition wled.h:452
u8 getNightlightTargetBrightness() const
Get nightlight target brightness.
Definition wled.h:360
u16 mPlaylistRepeat
Definition wled.h:450
fl::vector< WLEDSegment > mSegments
Definition wled.h:459
u8 mMainSegment
Definition wled.h:438
fl::json getState() const
Get current WLED state as JSON object.
Definition wled.cpp.hpp:405
u8 getMainSegment() const
Get main segment index.
Definition wled.h:336
u8 mNightlightMode
Definition wled.h:443
const WLEDSegment * findSegmentById(u8 id) const
Find segment by ID.
Definition wled.cpp.hpp:548
bool hasPlaylistConfig() const
Check if playlist is active.
Definition wled.h:372
u16 getTransition() const
Get transition duration.
Definition wled.h:312
u8 getNightlightMode() const
Get nightlight mode.
Definition wled.h:354
bool getOn() const
Get WLED on/off state.
Definition wled.h:300
i16 getPlaylist() const
Get active playlist ID.
Definition wled.h:324
unsigned char u8
Definition stdint.h:131
Optional< T > optional
Definition optional.h:16
Base definition for an LED controller.
Definition crgb.hpp:179
WLED segment configuration.
Definition segment.h:15
#define FL_NOEXCEPT