瀏覽代碼

String interpolation for 2-digit numbers (#18998)

Scott Lahteine 4 年之前
父節點
當前提交
ee28a10795
No account linked to committer's email address
共有 4 個文件被更改,包括 27 次插入22 次删除
  1. 2
    2
      Marlin/src/core/language.h
  2. 12
    6
      Marlin/src/lcd/lcdprint.cpp
  3. 10
    11
      Marlin/src/lcd/tft/tft_string.cpp
  4. 3
    3
      Marlin/src/lcd/tft/tft_string.h

+ 2
- 2
Marlin/src/core/language.h 查看文件

@@ -353,7 +353,7 @@
353 353
  *
354 354
  */
355 355
 #if ENABLED(NUMBER_TOOLS_FROM_0)
356
-  #define LCD_FIRST_TOOL '0'
356
+  #define LCD_FIRST_TOOL 0
357 357
   #define LCD_STR_N0 "0"
358 358
   #define LCD_STR_N1 "1"
359 359
   #define LCD_STR_N2 "2"
@@ -363,7 +363,7 @@
363 363
   #define LCD_STR_N6 "6"
364 364
   #define LCD_STR_N7 "7"
365 365
 #else
366
-  #define LCD_FIRST_TOOL '1'
366
+  #define LCD_FIRST_TOOL 1
367 367
   #define LCD_STR_N0 "1"
368 368
   #define LCD_STR_N1 "2"
369 369
   #define LCD_STR_N2 "3"

+ 12
- 6
Marlin/src/lcd/lcdprint.cpp 查看文件

@@ -44,22 +44,28 @@ lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, PGM_P const i
44 44
     if (ch == '=' || ch == '~' || ch == '*') {
45 45
       if (ind >= 0) {
46 46
         if (ch == '*') { lcd_put_wchar('E'); n--; }
47
-        if (n) { lcd_put_wchar(ind + ((ch == '=') ? '0' : LCD_FIRST_TOOL)); n--; }
47
+        if (n) {
48
+          int8_t inum = ind + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
49
+          if (inum >= 10) {
50
+            lcd_put_wchar('0' + (inum / 10)); n--;
51
+            inum %= 10;
52
+          }
53
+          if (n) { lcd_put_wchar('0' + inum); n--; }
54
+        }
48 55
       }
49 56
       else {
50 57
         PGM_P const b = ind == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED);
51 58
         n -= lcd_put_u8str_max_P(b, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
52 59
       }
53 60
       if (n) n -= lcd_put_u8str_max_P((PGM_P)p, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
54
-      continue;
55 61
     }
56 62
     else if (ch == '$' && inStr) {
57 63
       n -= lcd_put_u8str_max_P(inStr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
58
-      continue;
59 64
     }
60
-
61
-    lcd_put_wchar(ch);
62
-    n--;
65
+    else {
66
+      lcd_put_wchar(ch);
67
+      n--;
68
+    }
63 69
   }
64 70
   return n;
65 71
 }

+ 10
- 11
Marlin/src/lcd/tft/tft_string.cpp 查看文件

@@ -86,33 +86,32 @@ void TFT_String::set() {
86 86
 
87 87
 uint8_t read_byte(uint8_t *byte) { return *byte; }
88 88
 
89
-void TFT_String::add(uint8_t *string, uint8_t index, uint8_t *itemString) {
90
-  uint8_t character;
89
+void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) {
91 90
   wchar_t wchar;
92 91
 
93 92
   while (*string) {
94 93
     string = get_utf8_value_cb(string, read_byte, &wchar);
95
-    if (wchar > 255)
96
-      wchar |= 0x0080;
97
-    character = (uint8_t) (wchar & 0x00FF);
94
+    if (wchar > 255) wchar |= 0x0080;
95
+    uint8_t ch = uint8_t(wchar & 0x00FF);
98 96
 
99
-    if (character == '=' || character == '~' || character == '*') {
97
+    if (ch == '=' || ch == '~' || ch == '*') {
100 98
       if (index >= 0) {
101
-        if (character == '*')
102
-          add_character('E');
103
-        add_character(index + ((character == '=') ? '0' : LCD_FIRST_TOOL));
99
+        int8_t inum = index + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
100
+        if (ch == '*') add_character('E');
101
+        if (inum >= 10) { add_character('0' + (inum / 10)); inum %= 10; }
102
+        add_character('0' + inum);
104 103
       }
105 104
       else {
106 105
         add(index == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED));
107 106
       }
108 107
       continue;
109 108
     }
110
-    else if (character == '$' && itemString) {
109
+    else if (ch == '$' && itemString) {
111 110
       add(itemString);
112 111
       continue;
113 112
     }
114 113
 
115
-    add_character(character);
114
+    add_character(ch);
116 115
   }
117 116
   eol();
118 117
 }

+ 3
- 3
Marlin/src/lcd/tft/tft_string.h 查看文件

@@ -86,11 +86,11 @@ class TFT_String {
86 86
     static void set();
87 87
     static void add(uint8_t character) { add_character(character); eol(); }
88 88
     static void add(uint8_t *string) { while (*string) { add_character(*string++); } eol(); }
89
-    static void add(uint8_t *string, uint8_t index, uint8_t *itemString = NULL);
89
+    static void add(uint8_t *string, int8_t index, uint8_t *itemString = NULL);
90 90
     static void set(uint8_t *string) { set(); add(string); };
91
-    static void set(uint8_t *string, uint8_t index, const char *itemString = NULL) { set(); add(string, index, (uint8_t *)itemString); };
91
+    static void set(uint8_t *string, int8_t index, const char *itemString = NULL) { set(); add(string, index, (uint8_t *)itemString); };
92 92
     static inline void set(const char *string) { set((uint8_t *)string); }
93
-    static inline void set(const char *string, uint8_t index, const char *itemString = NULL) { set((uint8_t *)string, index, itemString); }
93
+    static inline void set(const char *string, int8_t index, const char *itemString = NULL) { set((uint8_t *)string, index, itemString); }
94 94
     static inline void add(const char *string) { add((uint8_t *)string); }
95 95
 
96 96
     static void trim(uint8_t character = 0x20);

Loading…
取消
儲存