Browse Source

Unify status scrolling further

Scott Lahteine 6 years ago
parent
commit
58bca67883

+ 12
- 31
Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp View File

660
       lcd_put_u8str(status_message);
660
       lcd_put_u8str(status_message);
661
 
661
 
662
       // Fill the rest with spaces
662
       // Fill the rest with spaces
663
-      while (slen < LCD_WIDTH) {
664
-        lcd_put_wchar(' ');
665
-        ++slen;
666
-      }
663
+      while (slen < LCD_WIDTH) { lcd_put_wchar(' '); ++slen; }
667
     }
664
     }
668
     else {
665
     else {
669
       // String is larger than the available space in screen.
666
       // String is larger than the available space in screen.
670
 
667
 
671
       // Get a pointer to the next valid UTF8 character
668
       // Get a pointer to the next valid UTF8 character
672
-      const char *stat = status_message + status_scroll_offset;
673
-
674
-      // Get the string remaining length
675
-      const uint8_t rlen = utf8_strlen(stat);
676
-
677
-      // If we have enough characters to display
678
-      if (rlen >= LCD_WIDTH) {
679
-        // The remaining string fills the screen - Print it
680
-        lcd_put_u8str_max(stat, LCD_WIDTH);
681
-      }
682
-      else {
683
-
684
-        // The remaining string does not completely fill the screen
685
-        lcd_put_u8str_max(stat, LCD_WIDTH);               // The string leaves space
686
-        uint8_t chars = LCD_WIDTH - rlen;                 // Amount of space left in characters
687
-
688
-        lcd_put_wchar('.');                               // Always at 1+ spaces left, draw a dot
689
-        if (--chars) {                                    // Draw a second dot if there's space
669
+      // and the string remaining length
670
+      uint8_t rlen;
671
+      const char *stat = status_and_len(rlen);
672
+      lcd_put_u8str_max(stat, LCD_WIDTH);     // The string leaves space
673
+
674
+      // If the remaining string doesn't completely fill the screen
675
+      if (rlen < LCD_WIDTH) {
676
+        lcd_put_wchar('.');                   // Always at 1+ spaces left, draw a dot
677
+        uint8_t chars = LCD_WIDTH - rlen;     // Amount of space left in characters
678
+        if (--chars) {                        // Draw a second dot if there's space
690
           lcd_put_wchar('.');
679
           lcd_put_wchar('.');
691
           if (--chars)
680
           if (--chars)
692
             lcd_put_u8str_max(status_message, chars); // Print a second copy of the message
681
             lcd_put_u8str_max(status_message, chars); // Print a second copy of the message
694
       }
683
       }
695
       if (last_blink != blink) {
684
       if (last_blink != blink) {
696
         last_blink = blink;
685
         last_blink = blink;
697
-
698
-        // Adjust by complete UTF8 characters
699
-        if (status_scroll_offset < slen) {
700
-          status_scroll_offset++;
701
-          while (!START_OF_UTF8_CHAR(status_message[status_scroll_offset]))
702
-            status_scroll_offset++;
703
-        }
704
-        else
705
-          status_scroll_offset = 0;
686
+        advance_status_scroll();
706
       }
687
       }
707
     }
688
     }
708
   #else
689
   #else

+ 13
- 28
Marlin/src/lcd/dogm/status_screen_DOGM.cpp View File

612
     if (slen <= LCD_WIDTH) {
612
     if (slen <= LCD_WIDTH) {
613
       // The string fits within the line. Print with no scrolling
613
       // The string fits within the line. Print with no scrolling
614
       lcd_put_u8str(status_message);
614
       lcd_put_u8str(status_message);
615
-      for (; slen < LCD_WIDTH; ++slen) lcd_put_wchar(' ');
615
+      while (slen < LCD_WIDTH) { lcd_put_wchar(' '); ++slen; }
616
     }
616
     }
617
     else {
617
     else {
618
       // String is longer than the available space
618
       // String is longer than the available space
619
 
619
 
620
       // Get a pointer to the next valid UTF8 character
620
       // Get a pointer to the next valid UTF8 character
621
-      const char *stat = status_message + status_scroll_offset;
622
-
623
-      // Get the string remaining length
624
-      const uint8_t rlen = utf8_strlen(stat);
625
-
626
-      if (rlen >= LCD_WIDTH) {
627
-        // The remaining string fills the screen - Print it
628
-        lcd_put_u8str_max(stat, LCD_PIXEL_WIDTH);
629
-      }
630
-      else {
631
-        // The remaining string does not completely fill the screen
632
-        lcd_put_u8str_max(stat, LCD_PIXEL_WIDTH);         // The string leaves space
633
-        uint8_t chars = LCD_WIDTH - rlen;                 // Amount of space left in characters
634
-
635
-        lcd_put_wchar('.');                               // Always at 1+ spaces left, draw a dot
636
-        if (--chars) {                                    // Draw a second dot if there's space
621
+      // and the string remaining length
622
+      uint8_t rlen;
623
+      const char *stat = status_and_len(rlen);
624
+      lcd_put_u8str_max(stat, LCD_PIXEL_WIDTH);
625
+
626
+      // If the remaining string doesn't completely fill the screen
627
+      if (rlen < LCD_WIDTH) {
628
+        lcd_put_wchar('.');                     // Always at 1+ spaces left, draw a dot
629
+        uint8_t chars = LCD_WIDTH - rlen;       // Amount of space left in characters
630
+        if (--chars) {                          // Draw a second dot if there's space
637
           lcd_put_wchar('.');
631
           lcd_put_wchar('.');
638
-          if (--chars) {
639
-            // Print a second copy of the message
632
+          if (--chars) {                        // Print a second copy of the message
640
             lcd_put_u8str_max(status_message, LCD_PIXEL_WIDTH - (rlen + 2) * (MENU_FONT_WIDTH));
633
             lcd_put_u8str_max(status_message, LCD_PIXEL_WIDTH - (rlen + 2) * (MENU_FONT_WIDTH));
641
             lcd_put_wchar(' ');
634
             lcd_put_wchar(' ');
642
           }
635
           }
644
       }
637
       }
645
       if (last_blink != blink) {
638
       if (last_blink != blink) {
646
         last_blink = blink;
639
         last_blink = blink;
647
-
648
-        // Adjust by complete UTF8 characters
649
-        if (status_scroll_offset < slen) {
650
-          status_scroll_offset++;
651
-          while (!START_OF_UTF8_CHAR(status_message[status_scroll_offset]))
652
-            status_scroll_offset++;
653
-        }
654
-        else
655
-          status_scroll_offset = 0;
640
+        advance_status_scroll();
656
       }
641
       }
657
     }
642
     }
658
 
643
 

+ 10
- 26
Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp View File

627
     if (slen <= LCD_WIDTH) {
627
     if (slen <= LCD_WIDTH) {
628
       // String fits the LCD, so just print it
628
       // String fits the LCD, so just print it
629
       write_str(str);
629
       write_str(str);
630
-      for (; slen < LCD_WIDTH; ++slen) write_byte(' ');
630
+      while (slen < LCD_WIDTH) { write_byte(' '); ++slen; }
631
     }
631
     }
632
     else {
632
     else {
633
       // String is larger than the available space in screen.
633
       // String is larger than the available space in screen.
634
 
634
 
635
       // Get a pointer to the next valid UTF8 character
635
       // Get a pointer to the next valid UTF8 character
636
-      const char *stat = str + ui.status_scroll_offset;
637
-
638
-      // Get the string remaining length
639
-      const uint8_t rlen = utf8_strlen(stat);
640
-
641
-      // If we have enough characters to display
642
-      if (rlen >= LCD_WIDTH) {
643
-        // The remaining string fills the screen - Print it
644
-        write_str(stat, LCD_WIDTH);
645
-      }
646
-      else {
647
-        // The remaining string does not completely fill the screen
648
-        write_str(stat);                        // The string leaves space
649
-        uint8_t chars = LCD_WIDTH - rlen;         // Amount of space left in characters
636
+      // and the string remaining length
637
+      uint8_t rlen;
638
+      const char *stat = ui.status_and_len(rlen);
639
+      write_str(stat, LCD_WIDTH);
650
 
640
 
641
+      // If the remaining string doesn't completely fill the screen
642
+      if (rlen < LCD_WIDTH) {
651
         write_byte('.');                        // Always at 1+ spaces left, draw a dot
643
         write_byte('.');                        // Always at 1+ spaces left, draw a dot
644
+        uint8_t chars = LCD_WIDTH - rlen;       // Amount of space left in characters
652
         if (--chars) {                          // Draw a second dot if there's space
645
         if (--chars) {                          // Draw a second dot if there's space
653
           write_byte('.');
646
           write_byte('.');
654
-          if (--chars)
655
-            write_str(str, chars);              // Print a second copy of the message
647
+          if (--chars) write_str(str, chars);   // Print a second copy of the message
656
         }
648
         }
657
       }
649
       }
658
-
659
-      // Adjust by complete UTF8 characters
660
-      if (ui.status_scroll_offset < slen) {
661
-        ui.status_scroll_offset++;
662
-        while (!START_OF_UTF8_CHAR(str[ui.status_scroll_offset]))
663
-          ui.status_scroll_offset++;
664
-      }
665
-      else
666
-        ui.status_scroll_offset = 0;
650
+      ui.advance_status_scroll();
667
     }
651
     }
668
 
652
 
669
   #else
653
   #else

+ 16
- 1
Marlin/src/lcd/ultralcd.cpp View File

1162
   /////////////// Status Line ////////////////
1162
   /////////////// Status Line ////////////////
1163
   ////////////////////////////////////////////
1163
   ////////////////////////////////////////////
1164
 
1164
 
1165
+  #if ENABLED(STATUS_MESSAGE_SCROLLING)
1166
+    void MarlinUI::advance_status_scroll() {
1167
+      // Advance by one UTF8 code-word
1168
+      if (status_scroll_offset < utf8_strlen(status_message))
1169
+        while (!START_OF_UTF8_CHAR(status_message[++status_scroll_offset]));
1170
+      else
1171
+        status_scroll_offset = 0;
1172
+    }
1173
+    char* MarlinUI::status_and_len(uint8_t &len) {
1174
+      char *out = status_message + status_scroll_offset;
1175
+      len = utf8_strlen(out);
1176
+      return out;
1177
+    }
1178
+  #endif
1179
+
1165
   void MarlinUI::finish_status(const bool persist) {
1180
   void MarlinUI::finish_status(const bool persist) {
1166
 
1181
 
1167
     #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
1182
     #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
1179
       next_filament_display = millis() + 5000UL; // Show status message for 5s
1194
       next_filament_display = millis() + 5000UL; // Show status message for 5s
1180
     #endif
1195
     #endif
1181
 
1196
 
1182
-    #if ENABLED(STATUS_MESSAGE_SCROLLING)
1197
+    #if HAS_SPI_LCD && ENABLED(STATUS_MESSAGE_SCROLLING)
1183
       status_scroll_offset = 0;
1198
       status_scroll_offset = 0;
1184
     #endif
1199
     #endif
1185
 
1200
 

+ 7
- 5
Marlin/src/lcd/ultralcd.h View File

277
     static char status_message[];
277
     static char status_message[];
278
     static bool has_status();
278
     static bool has_status();
279
 
279
 
280
-
281
     static uint8_t status_message_level;      // Higher levels block lower levels
280
     static uint8_t status_message_level;      // Higher levels block lower levels
282
     static inline void reset_alert_level() { status_message_level = 0; }
281
     static inline void reset_alert_level() { status_message_level = 0; }
283
 
282
 
283
+    #if ENABLED(STATUS_MESSAGE_SCROLLING)
284
+      static uint8_t status_scroll_offset;
285
+      static void advance_status_scroll();
286
+      static char* status_and_len(uint8_t &len);
287
+    #endif
288
+
284
     #if HAS_PRINT_PROGRESS
289
     #if HAS_PRINT_PROGRESS
285
       #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
290
       #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
286
         static uint8_t progress_bar_percent;
291
         static uint8_t progress_bar_percent;
327
 
332
 
328
       #endif
333
       #endif
329
 
334
 
330
-      #if ENABLED(STATUS_MESSAGE_SCROLLING)
331
-        static uint8_t status_scroll_offset;
332
-      #endif
333
       static uint8_t lcd_status_update_delay;
335
       static uint8_t lcd_status_update_delay;
334
 
336
 
335
       #if HAS_LCD_CONTRAST
337
       #if HAS_LCD_CONTRAST
520
   static void _synchronize();
522
   static void _synchronize();
521
 
523
 
522
   #if HAS_SPI_LCD || ENABLED(EXTENSIBLE_UI)
524
   #if HAS_SPI_LCD || ENABLED(EXTENSIBLE_UI)
523
-    static void finishstatus(const bool persist);
525
+    static void finish_status(const bool persist);
524
   #endif
526
   #endif
525
 
527
 
526
   #if HAS_SPI_LCD
528
   #if HAS_SPI_LCD

Loading…
Cancel
Save