14 if (
hex.length() > 0 &&
hex[0] ==
'#') {
19 if (
hex.length() != 6) {
24 for (
size_t i = 0; i <
hex.length(); i++) {
26 if (!((c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f') || (c >=
'A' && c <=
'F'))) {
32 auto hexDigitToInt = [](
char c) ->
u8 {
33 if (c >=
'0' && c <=
'9')
return c -
'0';
34 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
35 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
39 r = (hexDigitToInt(
hex[0]) << 4) | hexDigitToInt(
hex[1]);
40 g = (hexDigitToInt(
hex[2]) << 4) | hexDigitToInt(
hex[3]);
41 b = (hexDigitToInt(
hex[4]) << 4) | hexDigitToInt(
hex[5]);
52 const char hexChars[] =
"0123456789ABCDEF";
54 result.push_back(hexChars[val >> 4]);
55 result.push_back(hexChars[val & 0x0F]);
70 i64 startInt = segJson[
"start"] | 0;
71 if (startInt < 0) startInt = 0;
72 if (startInt > 65535) startInt = 65535;
73 seg.
mStart =
static_cast<u16
>(startInt);
77 i64 stopInt = segJson[
"stop"] | 0;
78 if (stopInt < 0) stopInt = 0;
79 if (stopInt > 65535) stopInt = 65535;
80 seg.
mStop =
static_cast<u16
>(stopInt);
84 i64 lenInt = segJson[
"len"] | 0;
85 if (lenInt < 0) lenInt = 0;
86 if (lenInt > 65535) lenInt = 65535;
87 seg.
mLen =
static_cast<u16
>(lenInt);
91 i64 grpInt = segJson[
"grp"] | 1;
92 if (grpInt < 1) grpInt = 1;
93 if (grpInt > 255) grpInt = 255;
94 seg.
mGrp =
static_cast<u8>(grpInt);
98 i64 spcInt = segJson[
"spc"] | 0;
99 if (spcInt < 0) spcInt = 0;
100 if (spcInt > 255) spcInt = 255;
101 seg.
mSpc =
static_cast<u8>(spcInt);
105 i64 ofInt = segJson[
"of"] | 0;
106 if (ofInt < 0) ofInt = 0;
107 if (ofInt > 65535) ofInt = 65535;
108 seg.
mOf =
static_cast<u16
>(ofInt);
112 seg.
mOn = segJson[
"on"] |
true;
116 i64 briInt = segJson[
"bri"] | 255;
117 if (briInt < 0) briInt = 0;
118 if (briInt > 255) briInt = 255;
119 seg.
mBri =
static_cast<u8>(briInt);
123 i64 cctInt = segJson[
"cct"] | 0;
124 if (cctInt < 0) cctInt = 0;
125 if (cctInt > 65535) cctInt = 65535;
126 seg.
mCct =
static_cast<u16
>(cctInt);
131 i64 fxInt = segJson[
"fx"] | 0;
132 if (fxInt < 0) fxInt = 0;
133 if (fxInt > 255) fxInt = 255;
134 seg.
mFx =
static_cast<u8>(fxInt);
138 i64 sxInt = segJson[
"sx"] | 128;
139 if (sxInt < 0) sxInt = 0;
140 if (sxInt > 255) sxInt = 255;
141 seg.
mSx =
static_cast<u8>(sxInt);
145 i64 ixInt = segJson[
"ix"] | 128;
146 if (ixInt < 0) ixInt = 0;
147 if (ixInt > 255) ixInt = 255;
148 seg.
mIx =
static_cast<u8>(ixInt);
152 i64 palInt = segJson[
"pal"] | 0;
153 if (palInt < 0) palInt = 0;
154 if (palInt > 255) palInt = 255;
155 seg.
mPal =
static_cast<u8>(palInt);
159 i64 c1Int = segJson[
"c1"] | 128;
160 if (c1Int < 0) c1Int = 0;
161 if (c1Int > 255) c1Int = 255;
162 seg.
mC1 =
static_cast<u8>(c1Int);
166 i64 c2Int = segJson[
"c2"] | 128;
167 if (c2Int < 0) c2Int = 0;
168 if (c2Int > 255) c2Int = 255;
169 seg.
mC2 =
static_cast<u8>(c2Int);
173 i64 c3Int = segJson[
"c3"] | 16;
174 if (c3Int < 0) c3Int = 0;
175 if (c3Int > 255) c3Int = 255;
176 seg.
mC3 =
static_cast<u8>(c3Int);
181 seg.
mSel = segJson[
"sel"] |
false;
185 seg.
mRev = segJson[
"rev"] |
false;
189 seg.
mMi = segJson[
"mi"] |
false;
193 seg.
mO1 = segJson[
"o1"] |
false;
197 seg.
mO2 = segJson[
"o2"] |
false;
201 seg.
mO3 = segJson[
"o3"] |
false;
205 i64 siInt = segJson[
"si"] | 0;
206 if (siInt < 0) siInt = 0;
207 if (siInt > 3) siInt = 3;
208 seg.
mSi =
static_cast<u8>(siInt);
212 i64 m12Int = segJson[
"m12"] | 0;
213 if (m12Int < 0) m12Int = 0;
214 if (m12Int > 3) m12Int = 3;
215 seg.
mM12 =
static_cast<u8>(m12Int);
219 seg.
mRpt = segJson[
"rpt"] |
false;
229 for (
size_t i = 0; i < segJson[
"col"].
size(); i++) {
230 const fl::json& colJson = segJson[
"col"][i];
235 for (
size_t j = 0; j < colJson.
size() && j < 4; j++) {
236 if (colJson[j].is_int()) {
237 i64 val = colJson[j] | 0;
238 if (val < 0) val = 0;
239 if (val > 255) val = 255;
243 if (color.
size() >= 3) {
257 FL_WARN(
"WLED: invalid hex color string: " << hexStr);
268 for (
size_t i = 0; i < segJson[
"i"].
size(); i++) {
269 const fl::json& ledJson = segJson[
"i"][i];
278 size_t pipePos = ledStr.
find(
'|');
281 size_t startIdx = ledIndex;
282 size_t endIdx = ledIndex;
286 hexStr = ledStr.
substr(0, pipePos);
290 size_t dashPos = indexStr.
find(
'-');
299 if (endptr == startStr.
c_str() || startVal < 0) {
300 FL_WARN(
"WLED: invalid range start index: " << startStr);
305 if (endptr == endStr.
c_str() || endVal < 0) {
306 FL_WARN(
"WLED: invalid range end index: " << endStr);
310 startIdx =
static_cast<size_t>(startVal);
311 endIdx =
static_cast<size_t>(endVal);
316 if (endptr == indexStr.
c_str() || idxVal < 0) {
317 FL_WARN(
"WLED: invalid LED index: " << indexStr);
320 startIdx = endIdx =
static_cast<size_t>(idxVal);
331 FL_WARN(
"WLED: invalid hex color in individual LED: " << hexStr);
336 size_t maxIdx = (endIdx > startIdx) ? endIdx : startIdx;
342 for (
size_t idx = startIdx; idx <= endIdx; idx++) {
fl::size find(const char &value) const FL_NOEXCEPT
const char * c_str() const FL_NOEXCEPT
bool is_array() const FL_NOEXCEPT
bool is_int() const FL_NOEXCEPT
size_t size() const FL_NOEXCEPT
bool is_string() const FL_NOEXCEPT
bool is_bool() const FL_NOEXCEPT
bool contains(size_t idx) const FL_NOEXCEPT
string substr(fl::size start, fl::size length) const FL_NOEXCEPT
static constexpr fl::size npos
fl::size size() const FL_NOEXCEPT
void push_back(const T &value) FL_NOEXCEPT
void resize(fl::size n) FL_NOEXCEPT
Centralized logging categories for FastLED hardware interfaces and subsystems.
void parseSegmentFields(const fl::json &segJson, WLEDSegment &seg)
Parse all fields from a segment JSON object into a WLEDSegment.
bool parseHexColor(const fl::string &hexStr, u8 &r, u8 &g, u8 &b)
Parse hex color string to RGB components.
fl::string rgbToHex(u8 r, u8 g, u8 b)
Convert RGB components to hex string.
expected< T, E > result
Alias for expected (Rust-style naming)
long strtol(const char *str, char **endptr, int base)
Base definition for an LED controller.
fl::vector< fl::vector< u8 > > mColors
fl::vector< fl::vector< u8 > > mIndividualLeds
WLED segment configuration.