Browse Source

pad string in lcd_finishstatus

Scott Lahteine 9 years ago
parent
commit
94955a8bf7
1 changed files with 15 additions and 17 deletions
  1. 15
    17
      Marlin/ultralcd.cpp

+ 15
- 17
Marlin/ultralcd.cpp View File

@@ -2738,7 +2738,18 @@ void lcd_update() {
2738 2738
   }
2739 2739
 }
2740 2740
 
2741
+void set_utf_strlen(char* s, uint8_t n) {
2742
+  uint8_t i = 0, j = 0;
2743
+  while (s[i] && (j < n)) {
2744
+    if ((s[i] & 0xC0u) != 0x80u) j++;
2745
+    i++;
2746
+  }
2747
+  while (j++ < n) s[i++] = ' ';
2748
+  s[i] = '\0';
2749
+}
2750
+
2741 2751
 void lcd_finishstatus(bool persist=false) {
2752
+  set_utf_strlen(lcd_status_message, LCD_WIDTH);
2742 2753
   #if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
2743 2754
     UNUSED(persist);
2744 2755
   #endif
@@ -2760,32 +2771,19 @@ void lcd_finishstatus(bool persist=false) {
2760 2771
   void dontExpireStatus() { expire_status_ms = 0; }
2761 2772
 #endif
2762 2773
 
2763
-void set_utf_strlen(char* s, uint8_t n) {
2764
-  uint8_t i = 0, j = 0;
2765
-  while (s[i] && (j < n)) {
2766
-    if ((s[i] & 0xc0u) != 0x80u) j++;
2767
-    i++;
2768
-  }
2769
-  while (j++ < n) s[i++] = ' ';
2770
-  s[i] = '\0';
2771
-}
2772
-
2773 2774
 bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
2774 2775
 
2775 2776
 void lcd_setstatus(const char* message, bool persist) {
2776 2777
   if (lcd_status_message_level > 0) return;
2777 2778
   strncpy(lcd_status_message, message, 3 * (LCD_WIDTH));
2778
-  set_utf_strlen(lcd_status_message, LCD_WIDTH);
2779 2779
   lcd_finishstatus(persist);
2780 2780
 }
2781 2781
 
2782 2782
 void lcd_setstatuspgm(const char* message, uint8_t level) {
2783
-  if (level >= lcd_status_message_level) {
2784
-    strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
2785
-    set_utf_strlen(lcd_status_message, LCD_WIDTH);
2786
-    lcd_status_message_level = level;
2787
-    lcd_finishstatus(level > 0);
2788
-  }
2783
+  if (level < lcd_status_message_level) return;
2784
+  lcd_status_message_level = level;
2785
+  strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH));
2786
+  lcd_finishstatus(level > 0);
2789 2787
 }
2790 2788
 
2791 2789
 void lcd_setalertstatuspgm(const char* message) {

Loading…
Cancel
Save