1010// OLED displays to provide a four line display
1111// for WLED.
1212//
13- // This Usermod works best, by far, when coupled with RotaryEncoderUIUsermod.
13+ // Dependencies
14+ // * This usermod REQURES the ModeSortUsermod
15+ // * This Usermod works best, by far, when coupled
16+ // with RotaryEncoderUIUsermod.
1417//
1518// Make sure to enable NTP and set your time zone in WLED Config | Time.
1619//
@@ -124,6 +127,9 @@ class FourLineDisplayUsermod : public Usermod {
124127
125128 char lineBuffer[LINE_BUFFER_SIZE];
126129
130+ char **modes_qstrings = nullptr ;
131+ char **palettes_qstrings = nullptr ;
132+
127133 // If display does not work or looks corrupted check the
128134 // constructor reference:
129135 // https://github.com/olikraus/u8g2/wiki/u8x8setupcpp
@@ -140,6 +146,10 @@ class FourLineDisplayUsermod : public Usermod {
140146 u8x8.setContrast (10 ); // Contrast setup will help to preserve OLED lifetime. In case OLED need to be brighter increase number up to 255
141147 u8x8.setFont (u8x8_font_chroma48medium8_r);
142148 u8x8.DRAW_STRING (0 , 0 *LINE_HEIGHT, " Loading..." );
149+
150+ ModeSortUsermod *modeSortUsermod = (ModeSortUsermod*) usermods.lookup (USERMOD_ID_MODE_SORT);
151+ modes_qstrings = modeSortUsermod->getModesQStrings ();
152+ palettes_qstrings = modeSortUsermod->getPalettesQStrings ();
143153 }
144154
145155 // gets called every time WiFi is (re-)connected. Initialize own network
@@ -254,7 +264,7 @@ class FourLineDisplayUsermod : public Usermod {
254264 }
255265
256266 // Third row with mode name
257- showCurrentEffectOrPalette (JSON_mode_names , 2 , knownMode );
267+ showCurrentEffectOrPalette (modes_qstrings[knownMode] , 2 );
258268
259269 switch (lineThreeType) {
260270 case FLD_LINE_3_BRIGHTNESS:
@@ -270,7 +280,7 @@ class FourLineDisplayUsermod : public Usermod {
270280 u8x8.DRAW_STRING (1 , 3 *LINE_HEIGHT, lineBuffer);
271281 break ;
272282 case FLD_LINE_3_PALETTE:
273- showCurrentEffectOrPalette (JSON_palette_names , 3 , knownPalette );
283+ showCurrentEffectOrPalette (palettes_qstrings[knownPalette] , 3 );
274284 break ;
275285 }
276286
@@ -289,35 +299,21 @@ class FourLineDisplayUsermod : public Usermod {
289299 * TODO: Should we cache the current effect and
290300 * TODO: palette name? This seems expensive.
291301 */
292- void showCurrentEffectOrPalette (const char json[], uint8_t row, uint8_t desiredEntry) {
293- uint8_t qComma = 0 ;
294- bool insideQuotes = false ;
295- // advance past the mark for markLineNum that may exist.
302+ void showCurrentEffectOrPalette (char *qstring, uint8_t row) {
296303 uint8_t printedChars = 1 ;
297304 char singleJsonSymbol;
298-
299- // Find the mode name in JSON
300- for (size_t i = 0 ; i < strlen_P (json); i++) {
301- singleJsonSymbol = pgm_read_byte_near (json + i);
302- switch (singleJsonSymbol) {
303- case ' "' :
304- insideQuotes = !insideQuotes;
305- break ;
306- case ' [' :
307- case ' ]' :
305+ int i = 0 ;
306+ while (true ) {
307+ singleJsonSymbol = pgm_read_byte_near (qstring + i);
308+ if (singleJsonSymbol == ' "' || singleJsonSymbol == ' \0 ' ) {
308309 break ;
309- case ' ,' :
310- qComma++;
311- default :
312- if (!insideQuotes || (qComma != desiredEntry)) {
313- break ;
314- }
315- u8x8.DRAW_GLYPH (printedChars, row * LINE_HEIGHT, singleJsonSymbol);
316- printedChars++;
317310 }
318- if ((qComma > desiredEntry) || (printedChars > u8x8.getCols () - 2 )) {
311+ u8x8.DRAW_GLYPH (printedChars, row * LINE_HEIGHT, singleJsonSymbol);
312+ printedChars++;
313+ if ( (printedChars > u8x8.getCols () - 2 )) {
319314 break ;
320315 }
316+ i++;
321317 }
322318 }
323319
0 commit comments