@@ -12,50 +12,6 @@ void getStringFromJson(char* dest, const char* src, size_t len) {
1212 if (src != nullptr ) strlcpy (dest, src, len);
1313}
1414
15- // populates bus objects from instance JsonArray, called by deserializeConfig() and by doInitStrip
16- bool initBusInstances (JsonArray ins) {
17- uint8_t s = 0 ;
18- useRGBW = false ;
19- busses.removeAll ();
20- for (JsonObject elm : ins) {
21- if (s >= WLED_MAX_BUSSES) break ;
22- uint8_t pins[5 ] = {255 , 255 , 255 , 255 , 255 };
23- JsonArray pinArr = elm[F (" pin" )];
24- if (pinArr.size () == 0 ) continue ;
25- pins[0 ] = pinArr[0 ];
26- uint8_t i = 0 ;
27- for (int p : pinArr) {
28- pins[i] = p;
29- i++;
30- if (i>4 ) break ;
31- }
32-
33- uint16_t length = elm[F (" len" )];
34- if (length==0 ) continue ;
35- uint8_t colorOrder = (int )elm[F (" order" )];
36- // only use skip from the first strip (this shouldn't have been in ins obj. but remains here for compatibility)
37- if (s==0 ) skipFirstLed = elm[F (" skip" )];
38- uint16_t start = elm[F (" start" )] | 0 ;
39- if (start >= ledCount) continue ;
40- // limit length of strip if it would exceed total configured LEDs
41- if (start + length > ledCount) length = ledCount - start;
42- uint8_t ledType = elm[F (" type" )] | TYPE_WS2812_RGB;
43- bool reversed = elm[F (" rev" )];
44- // RGBW mode is enabled if at least one of the strips is RGBW
45- useRGBW = (useRGBW || BusManager::isRgbw (ledType));
46- s++;
47- BusConfig bc = BusConfig (ledType, pins, start, ledCount, colorOrder, reversed);
48- busses.add (bc);
49- }
50- // if no bus inited successfully (empty cfg or invalid), init default
51- if (s==0 ) {
52- uint8_t defPin[] = {LEDPIN};
53- BusConfig defCfg = BusConfig (TYPE_WS2812_RGB, defPin, 0 , ledCount, COL_ORDER_GRB);
54- busses.add (defCfg);
55- }
56- return s;
57- }
58-
5915void deserializeConfig () {
6016 bool fromeep = false ;
6117 bool success = deserializeConfigSec ();
@@ -142,8 +98,41 @@ void deserializeConfig() {
14298 CJSON (strip.reverseMode , hw_led[F (" rev" )]);
14399 CJSON (strip.rgbwMode , hw_led[F (" rgbwm" )]);
144100
145- JsonVariant strVar = hw_led[" ins" ];
146- initBusInstances (strVar.as <JsonArray>());
101+ JsonArray ins = hw_led[" ins" ];
102+ uint8_t s = 0 ;
103+ useRGBW = false ;
104+ busses.removeAll ();
105+ for (JsonObject elm : ins) {
106+ if (s >= WLED_MAX_BUSSES) break ;
107+ uint8_t pins[5 ] = {255 , 255 , 255 , 255 , 255 };
108+ JsonArray pinArr = elm[F (" pin" )];
109+ if (pinArr.size () == 0 ) continue ;
110+ pins[0 ] = pinArr[0 ];
111+ uint8_t i = 0 ;
112+ for (int p : pinArr) {
113+ pins[i] = p;
114+ i++;
115+ if (i>4 ) break ;
116+ }
117+
118+ uint16_t length = elm[F (" len" )];
119+ if (length==0 ) continue ;
120+ uint8_t colorOrder = (int )elm[F (" order" )];
121+ // only use skip from the first strip (this shouldn't have been in ins obj. but remains here for compatibility)
122+ if (s==0 ) skipFirstLed = elm[F (" skip" )];
123+ uint16_t start = elm[F (" start" )] | 0 ;
124+ if (start >= ledCount) continue ;
125+ // limit length of strip if it would exceed total configured LEDs
126+ if (start + length > ledCount) length = ledCount - start;
127+ uint8_t ledType = elm[F (" type" )] | TYPE_WS2812_RGB;
128+ bool reversed = elm[F (" rev" )];
129+ // RGBW mode is enabled if at least one of the strips is RGBW
130+ useRGBW = (useRGBW || BusManager::isRgbw (ledType));
131+ s++;
132+ BusConfig bc = BusConfig (ledType, pins, start, length, colorOrder, reversed);
133+ busses.add (bc);
134+ }
135+ strip.finalizeInit (useRGBW, ledCount, skipFirstLed);
147136
148137 JsonObject hw_btn_ins_0 = hw[F (" btn" )][F (" ins" )][0 ];
149138 CJSON (buttonEnabled, hw_btn_ins_0[F (" type" )]);
0 commit comments