Parcourir la source

🎨 Apply F() to MKS UI errors, assets

Scott Lahteine il y a 2 ans
Parent
révision
d1938d54ed

+ 5
- 4
Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp Voir le fichier

@@ -33,11 +33,12 @@
33 33
 
34 34
 static lv_obj_t *scr;
35 35
 
36
-void lv_draw_error_message(PGM_P const msg) {
36
+void lv_draw_error_message(FSTR_P const fmsg) {
37
+  FSTR_P fhalted = F("PRINTER HALTED"), fplease = F("Please Reset");
37 38
   SPI_TFT.LCD_clear(0x0000);
38
-  if (msg) disp_string((TFT_WIDTH - strlen(msg) * 16) / 2, 100, msg, 0xFFFF, 0x0000);
39
-  disp_string((TFT_WIDTH - strlen("PRINTER HALTED") * 16) / 2, 140, "PRINTER HALTED", 0xFFFF, 0x0000);
40
-  disp_string((TFT_WIDTH - strlen("Please Reset") * 16) / 2, 180, "Please Reset", 0xFFFF, 0x0000);
39
+  if (fmsg) disp_string((TFT_WIDTH - strlen_P(FTOP(fmsg)) * 16) / 2, 100, fmsg, 0xFFFF, 0x0000);
40
+  disp_string((TFT_WIDTH - strlen_P(FTOP(fhalted)) * 16) / 2, 140, fhalted, 0xFFFF, 0x0000);
41
+  disp_string((TFT_WIDTH - strlen_P(FTOP(fplease)) * 16) / 2, 180, fplease, 0xFFFF, 0x0000);
41 42
 }
42 43
 
43 44
 void lv_clear_error_message() { lv_obj_del(scr); }

+ 1
- 1
Marlin/src/lcd/extui/mks_ui/draw_error_message.h Voir le fichier

@@ -29,7 +29,7 @@
29 29
   #define PGM_P const char *
30 30
 #endif
31 31
 
32
-void lv_draw_error_message(PGM_P const msg);
32
+void lv_draw_error_message(FSTR_P const fmsg);
33 33
 void lv_clear_error_message();
34 34
 
35 35
 #ifdef __cplusplus

+ 16
- 12
Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp Voir le fichier

@@ -697,24 +697,28 @@ void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint1
697 697
   }
698 698
 }
699 699
 
700
-void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor, uint16_t bkColor) {
701
-  while (*string != '\0') {
702
-    disp_char_1624(x, y, *string, charColor, bkColor);
703
-    string++;
704
-    x += 16;
705
-  }
700
+void disp_string(uint16_t x, uint16_t y, const char * cstr, uint16_t charColor, uint16_t bkColor) {
701
+  for (char c; (c = *cstr); cstr++, x += 16)
702
+    disp_char_1624(x, y, c, charColor, bkColor);
703
+}
704
+
705
+void disp_string(uint16_t x, uint16_t y, FSTR_P const fstr, uint16_t charColor, uint16_t bkColor) {
706
+  PGM_P pstr = FTOP(fstr);
707
+  for (char c; (c = pgm_read_byte(pstr)); pstr++, x += 16)
708
+    disp_char_1624(x, y, c, charColor, bkColor);
706 709
 }
707 710
 
708 711
 void disp_assets_update() {
709 712
   SPI_TFT.LCD_clear(0x0000);
710
-  disp_string(100, 140, "Assets Updating...", 0xFFFF, 0x0000);
713
+  disp_string(100, 140, F("Assets Updating..."), 0xFFFF, 0x0000);
711 714
 }
712 715
 
713
-void disp_assets_update_progress(const char *msg) {
714
-  char buf[30];
715
-  memset(buf, ' ', COUNT(buf));
716
-  strncpy(buf, msg, strlen(msg));
717
-  buf[COUNT(buf) - 1] = '\0';
716
+void disp_assets_update_progress(FSTR_P const fmsg) {
717
+  static constexpr int buflen = 30;
718
+  char buf[buflen];
719
+  memset(buf, ' ', buflen);
720
+  strncpy_P(buf, FTOP(fmsg), buflen - 1);
721
+  buf[buflen - 1] = '\0';
718 722
   disp_string(100, 165, buf, 0xFFFF, 0x0000);
719 723
 }
720 724
 

+ 3
- 2
Marlin/src/lcd/extui/mks_ui/mks_hardware.h Voir le fichier

@@ -36,6 +36,7 @@
36 36
 #endif
37 37
 
38 38
 // String display and assets
39
-void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor, uint16_t bkColor);
39
+void disp_string(uint16_t x, uint16_t y, const char * cstr, uint16_t charColor, uint16_t bkColor);
40
+void disp_string(uint16_t x, uint16_t y, FSTR_P const fstr, uint16_t charColor, uint16_t bkColor);
40 41
 void disp_assets_update();
41
-void disp_assets_update_progress(const char *msg);
42
+void disp_assets_update_progress(FSTR_P const msg);

+ 134
- 134
Marlin/src/lcd/extui/mks_ui/pic_manager.cpp Voir le fichier

@@ -40,186 +40,186 @@ extern uint16_t DeviceCode;
40 40
   extern char *createFilename(char * const buffer, const dir_t &p);
41 41
 #endif
42 42
 
43
-static const char assets[][LONG_FILENAME_LENGTH] = {
43
+static FSTR_P const assets[] = {
44 44
   // Homing screen
45
-  "bmp_zeroAll.bin",
46
-  "bmp_zero.bin",
47
-  "bmp_zeroX.bin",
48
-  "bmp_zeroY.bin",
49
-  "bmp_zeroZ.bin",
50
-  "bmp_manual_off.bin",
45
+  F("bmp_zeroAll.bin"),
46
+  F("bmp_zero.bin"),
47
+  F("bmp_zeroX.bin"),
48
+  F("bmp_zeroY.bin"),
49
+  F("bmp_zeroZ.bin"),
50
+  F("bmp_manual_off.bin"),
51 51
 
52 52
   // Tool screen
53
-  "bmp_preHeat.bin",
54
-  "bmp_extruct.bin",
55
-  "bmp_mov.bin",
56
-  "bmp_leveling.bin",
57
-  "bmp_filamentchange.bin",
58
-  "bmp_more.bin",
53
+  F("bmp_preHeat.bin"),
54
+  F("bmp_extruct.bin"),
55
+  F("bmp_mov.bin"),
56
+  F("bmp_leveling.bin"),
57
+  F("bmp_filamentchange.bin"),
58
+  F("bmp_more.bin"),
59 59
 
60 60
   // Fan screen
61
-  "bmp_Add.bin",
62
-  "bmp_Dec.bin",
63
-  "bmp_speed255.bin",
64
-  "bmp_speed127.bin",
65
-  "bmp_speed0.bin",
61
+  F("bmp_Add.bin"),
62
+  F("bmp_Dec.bin"),
63
+  F("bmp_speed255.bin"),
64
+  F("bmp_speed127.bin"),
65
+  F("bmp_speed0.bin"),
66 66
 
67
-  "bmp_bed.bin",
68
-  "bmp_step1_degree.bin",
69
-  "bmp_step5_degree.bin",
70
-  "bmp_step10_degree.bin",
67
+  F("bmp_bed.bin"),
68
+  F("bmp_step1_degree.bin"),
69
+  F("bmp_step5_degree.bin"),
70
+  F("bmp_step10_degree.bin"),
71 71
 
72 72
   // Extrusion screen
73
-  "bmp_in.bin",
74
-  "bmp_out.bin",
75
-  "bmp_extru1.bin",
73
+  F("bmp_in.bin"),
74
+  F("bmp_out.bin"),
75
+  F("bmp_extru1.bin"),
76 76
   #if HAS_MULTI_EXTRUDER
77
-    "bmp_extru2.bin",
77
+    F("bmp_extru2.bin"),
78 78
   #endif
79
-  "bmp_speed_high.bin",
80
-  "bmp_speed_slow.bin",
81
-  "bmp_speed_normal.bin",
82
-  "bmp_step1_mm.bin",
83
-  "bmp_step5_mm.bin",
84
-  "bmp_step10_mm.bin",
79
+  F("bmp_speed_high.bin"),
80
+  F("bmp_speed_slow.bin"),
81
+  F("bmp_speed_normal.bin"),
82
+  F("bmp_step1_mm.bin"),
83
+  F("bmp_step5_mm.bin"),
84
+  F("bmp_step10_mm.bin"),
85 85
 
86 86
   // Select file screen
87
-  "bmp_pageUp.bin",
88
-  "bmp_pageDown.bin",
89
-  "bmp_back.bin", //TODO: why two back buttons? Why not just one? (return / back)
90
-  "bmp_dir.bin",
91
-  "bmp_file.bin",
87
+  F("bmp_pageUp.bin"),
88
+  F("bmp_pageDown.bin"),
89
+  F("bmp_back.bin"), // TODO: why two back buttons? Why not just one? (return / back)
90
+  F("bmp_dir.bin"),
91
+  F("bmp_file.bin"),
92 92
 
93 93
   // Move motor screen
94 94
   // TODO: 6 equal icons, just in diffenct rotation... it may be optimized too
95
-  "bmp_xAdd.bin",
96
-  "bmp_xDec.bin",
97
-  "bmp_yAdd.bin",
98
-  "bmp_yDec.bin",
99
-  "bmp_zAdd.bin",
100
-  "bmp_zDec.bin",
101
-  "bmp_step_move0_1.bin",
102
-  "bmp_step_move1.bin",
103
-  "bmp_step_move10.bin",
95
+  F("bmp_xAdd.bin"),
96
+  F("bmp_xDec.bin"),
97
+  F("bmp_yAdd.bin"),
98
+  F("bmp_yDec.bin"),
99
+  F("bmp_zAdd.bin"),
100
+  F("bmp_zDec.bin"),
101
+  F("bmp_step_move0_1.bin"),
102
+  F("bmp_step_move1.bin"),
103
+  F("bmp_step_move10.bin"),
104 104
 
105 105
   // Operation screen
106
-  "bmp_auto_off.bin",
107
-  "bmp_speed.bin",
108
-  "bmp_fan.bin",
109
-  "bmp_temp.bin",
110
-  "bmp_extrude_opr.bin",
111
-  "bmp_move_opr.bin",
106
+  F("bmp_auto_off.bin"),
107
+  F("bmp_speed.bin"),
108
+  F("bmp_fan.bin"),
109
+  F("bmp_temp.bin"),
110
+  F("bmp_extrude_opr.bin"),
111
+  F("bmp_move_opr.bin"),
112 112
 
113 113
   // Change speed screen
114
-  "bmp_step1_percent.bin",
115
-  "bmp_step5_percent.bin",
116
-  "bmp_step10_percent.bin",
117
-  "bmp_extruct_sel.bin",
118
-  "bmp_mov_changespeed.bin",
119
-  "bmp_mov_sel.bin",
120
-  "bmp_speed_extruct.bin",
114
+  F("bmp_step1_percent.bin"),
115
+  F("bmp_step5_percent.bin"),
116
+  F("bmp_step10_percent.bin"),
117
+  F("bmp_extruct_sel.bin"),
118
+  F("bmp_mov_changespeed.bin"),
119
+  F("bmp_mov_sel.bin"),
120
+  F("bmp_speed_extruct.bin"),
121 121
 
122 122
   // Printing screen
123
-  "bmp_pause.bin",
124
-  "bmp_resume.bin",
125
-  "bmp_stop.bin",
126
-  "bmp_ext1_state.bin",
123
+  F("bmp_pause.bin"),
124
+  F("bmp_resume.bin"),
125
+  F("bmp_stop.bin"),
126
+  F("bmp_ext1_state.bin"),
127 127
   #if HAS_MULTI_EXTRUDER
128
-    "bmp_ext2_state.bin",
128
+    F("bmp_ext2_state.bin"),
129 129
   #endif
130
-  "bmp_bed_state.bin",
131
-  "bmp_fan_state.bin",
132
-  "bmp_time_state.bin",
133
-  "bmp_zpos_state.bin",
134
-  "bmp_operate.bin",
130
+  F("bmp_bed_state.bin"),
131
+  F("bmp_fan_state.bin"),
132
+  F("bmp_time_state.bin"),
133
+  F("bmp_zpos_state.bin"),
134
+  F("bmp_operate.bin"),
135 135
 
136 136
   // Manual Level screen (only if auto level is disabled)
137 137
   #if DISABLED(AUTO_BED_LEVELING_BILINEAR)
138
-    "bmp_leveling1.bin",
139
-    "bmp_leveling2.bin",
140
-    "bmp_leveling3.bin",
141
-    "bmp_leveling4.bin",
142
-    "bmp_leveling5.bin",
138
+    F("bmp_leveling1.bin"),
139
+    F("bmp_leveling2.bin"),
140
+    F("bmp_leveling3.bin"),
141
+    F("bmp_leveling4.bin"),
142
+    F("bmp_leveling5.bin"),
143 143
   #endif
144 144
 
145 145
   // Language Select screen
146 146
   #if HAS_LANG_SELECT_SCREEN
147
-    "bmp_language.bin",
148
-    "bmp_simplified_cn.bin",
149
-    "bmp_simplified_cn_sel.bin",
150
-    "bmp_traditional_cn.bin",
151
-    "bmp_traditional_cn_sel.bin",
152
-    "bmp_english.bin",
153
-    "bmp_english_sel.bin",
154
-    "bmp_russian.bin",
155
-    "bmp_russian_sel.bin",
156
-    "bmp_spanish.bin",
157
-    "bmp_spanish_sel.bin",
158
-    "bmp_french.bin",
159
-    "bmp_french_sel.bin",
160
-    "bmp_italy.bin",
161
-    "bmp_italy_sel.bin",
147
+    F("bmp_language.bin"),
148
+    F("bmp_simplified_cn.bin"),
149
+    F("bmp_simplified_cn_sel.bin"),
150
+    F("bmp_traditional_cn.bin"),
151
+    F("bmp_traditional_cn_sel.bin"),
152
+    F("bmp_english.bin"),
153
+    F("bmp_english_sel.bin"),
154
+    F("bmp_russian.bin"),
155
+    F("bmp_russian_sel.bin"),
156
+    F("bmp_spanish.bin"),
157
+    F("bmp_spanish_sel.bin"),
158
+    F("bmp_french.bin"),
159
+    F("bmp_french_sel.bin"),
160
+    F("bmp_italy.bin"),
161
+    F("bmp_italy_sel.bin"),
162 162
   #endif // HAS_LANG_SELECT_SCREEN
163 163
 
164 164
   // G-code preview
165 165
   #if HAS_GCODE_DEFAULT_VIEW_IN_FLASH
166
-    "bmp_preview.bin",
166
+    F("bmp_preview.bin"),
167 167
   #endif
168 168
 
169 169
   #if HAS_LOGO_IN_FLASH
170
-    "bmp_logo.bin",
170
+    F("bmp_logo.bin"),
171 171
   #endif
172 172
 
173 173
   // Settings screen
174
-  "bmp_about.bin",
175
-  "bmp_eeprom_settings.bin",
176
-  "bmp_machine_para.bin",
177
-  "bmp_function1.bin",
174
+  F("bmp_about.bin"),
175
+  F("bmp_eeprom_settings.bin"),
176
+  F("bmp_machine_para.bin"),
177
+  F("bmp_function1.bin"),
178 178
 
179 179
   // Start screen
180
-  "bmp_printing.bin",
181
-  "bmp_set.bin",
182
-  "bmp_tool.bin",
180
+  F("bmp_printing.bin"),
181
+  F("bmp_set.bin"),
182
+  F("bmp_tool.bin"),
183 183
 
184 184
   // Base icons
185
-  "bmp_arrow.bin",
186
-  "bmp_back70x40.bin",
187
-  "bmp_value_blank.bin",
188
-  "bmp_blank_sel.bin",
189
-  "bmp_disable.bin",
190
-  "bmp_enable.bin",
191
-  "bmp_return.bin",
185
+  F("bmp_arrow.bin"),
186
+  F("bmp_back70x40.bin"),
187
+  F("bmp_value_blank.bin"),
188
+  F("bmp_blank_sel.bin"),
189
+  F("bmp_disable.bin"),
190
+  F("bmp_enable.bin"),
191
+  F("bmp_return.bin"),
192 192
 
193 193
   #if ENABLED(MKS_WIFI_MODULE)
194 194
     // Wifi screen
195
-    "bmp_wifi.bin",
196
-    "bmp_cloud.bin",
195
+    F("bmp_wifi.bin"),
196
+    F("bmp_cloud.bin"),
197 197
   #endif
198 198
 
199 199
   #if ENABLED(MULTI_VOLUME)
200
-    "bmp_usb_disk.bin",
201
-    // "bmp_usb_disk_sel.bin",
202
-    "bmp_sd.bin",
203
-    // "bmp_sd_sel.bin",
200
+    F("bmp_usb_disk.bin"),
201
+    //F("bmp_usb_disk_sel.bin"),
202
+    F("bmp_sd.bin"),
203
+    //F("bmp_sd_sel.bin"),
204 204
   #endif
205 205
 
206 206
   // Babystep screen
207
-  "bmp_baby_move0_01.bin",
208
-  "bmp_baby_move0_05.bin",
209
-  "bmp_baby_move0_1.bin",
207
+  F("bmp_baby_move0_01.bin"),
208
+  F("bmp_baby_move0_05.bin"),
209
+  F("bmp_baby_move0_1.bin"),
210 210
 
211 211
   // More screen
212
-  "bmp_custom1.bin",
213
-  "bmp_custom2.bin",
214
-  "bmp_custom3.bin",
215
-  "bmp_custom4.bin",
216
-  "bmp_custom5.bin",
217
-  "bmp_custom6.bin",
218
-  "bmp_custom7.bin"
212
+  F("bmp_custom1.bin"),
213
+  F("bmp_custom2.bin"),
214
+  F("bmp_custom3.bin"),
215
+  F("bmp_custom4.bin"),
216
+  F("bmp_custom5.bin"),
217
+  F("bmp_custom6.bin"),
218
+  F("bmp_custom7.bin")
219 219
 };
220 220
 
221 221
 #if HAS_SPI_FLASH_FONT
222
-  static char fonts[][LONG_FILENAME_LENGTH] = { "FontUNIGBK.bin" };
222
+  static FSTR_P const fonts[] = { F("FontUNIGBK.bin") };
223 223
 #endif
224 224
 
225 225
 uint8_t currentFlashPage = 0;
@@ -386,9 +386,9 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
386 386
     longName[j] = '\0';
387 387
   }
388 388
 
389
-  static int8_t arrayFindStr(const char arr[][LONG_FILENAME_LENGTH], uint8_t arraySize, const char *str) {
389
+  static int8_t arrayFindStr(FSTR_P const arr[], uint8_t arraySize, const char *str) {
390 390
     for (uint8_t a = 0; a < arraySize; a++) {
391
-      if (strcasecmp(arr[a], str) == 0)
391
+      if (strcasecmp(FTOP(arr[a]), str) == 0)
392 392
         return a;
393 393
     }
394 394
     return -1;
@@ -403,7 +403,7 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
403 403
   #define ASSET_TYPE_TITLE_LOGO 2
404 404
   #define ASSET_TYPE_G_PREVIEW  3
405 405
   #define ASSET_TYPE_FONT       4
406
-  static void loadAsset(SdFile &dir, dir_t& entry, const char *fn, int8_t assetType) {
406
+  static void loadAsset(SdFile &dir, dir_t& entry, FSTR_P const fn, int8_t assetType) {
407 407
     SdFile file;
408 408
     char dosFilename[FILENAME_LENGTH];
409 409
     createFilename(dosFilename, entry);
@@ -429,14 +429,14 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
429 429
       do {
430 430
         watchdog_refresh();
431 431
         pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
432
-        Pic_Logo_Write((uint8_t *)fn, public_buf, pbr);
432
+        Pic_Logo_Write((uint8_t*)fn, public_buf, pbr);
433 433
       } while (pbr >= BMP_WRITE_BUF_LEN);
434 434
     }
435 435
     else if (assetType == ASSET_TYPE_TITLE_LOGO) {
436 436
       do {
437 437
         watchdog_refresh();
438 438
         pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
439
-        Pic_TitleLogo_Write((uint8_t *)fn, public_buf, pbr);
439
+        Pic_TitleLogo_Write((uint8_t*)fn, public_buf, pbr);
440 440
       } while (pbr >= BMP_WRITE_BUF_LEN);
441 441
     }
442 442
     else if (assetType == ASSET_TYPE_G_PREVIEW) {
@@ -447,7 +447,7 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
447 447
       } while (pbr >= BMP_WRITE_BUF_LEN);
448 448
     }
449 449
     else if (assetType == ASSET_TYPE_ICON) {
450
-      Pic_Write_Addr = Pic_Info_Write((uint8_t *)fn, pfileSize);
450
+      Pic_Write_Addr = Pic_Info_Write((uint8_t*)fn, pfileSize);
451 451
       SPIFlash.beginWrite(Pic_Write_Addr);
452 452
       #if HAS_SPI_FLASH_COMPRESSION
453 453
         do {
@@ -492,16 +492,16 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
492 492
     if (dir.open(&root, assetsPath, O_RDONLY)) {
493 493
 
494 494
       disp_assets_update();
495
-      disp_assets_update_progress("Erasing pics...");
495
+      disp_assets_update_progress(F("Erasing pics..."));
496 496
       watchdog_refresh();
497 497
       spiFlashErase_PIC();
498 498
       #if HAS_SPI_FLASH_FONT
499
-        disp_assets_update_progress("Erasing fonts...");
499
+        disp_assets_update_progress(F("Erasing fonts..."));
500 500
         watchdog_refresh();
501 501
         spiFlashErase_FONT();
502 502
       #endif
503 503
 
504
-      disp_assets_update_progress("Reading files...");
504
+      disp_assets_update_progress(F("Reading files..."));
505 505
       dir_t d;
506 506
       while (dir.readDir(&d, card.longFilename) > 0) {
507 507
         // If we don't get a long name, but gets a short one, try it
@@ -513,11 +513,11 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
513 513
         int8_t a = arrayFindStr(assets, COUNT(assets), card.longFilename);
514 514
         if (a >= 0 && a < (int8_t)COUNT(assets)) {
515 515
           uint8_t assetType = ASSET_TYPE_ICON;
516
-          if (strstr(assets[a], "_logo"))
516
+          if (strstr_P(FTOP(assets[a]), PSTR("_logo")))
517 517
             assetType = ASSET_TYPE_LOGO;
518
-          else if (strstr(assets[a], "_titlelogo"))
518
+          else if (strstr_P(FTOP(assets[a]), PSTR("_titlelogo")))
519 519
             assetType = ASSET_TYPE_TITLE_LOGO;
520
-          else if (strstr(assets[a], "_preview"))
520
+          else if (strstr_P(FTOP(assets[a]), PSTR("_preview")))
521 521
             assetType = ASSET_TYPE_G_PREVIEW;
522 522
 
523 523
           loadAsset(dir, d, assets[a], assetType);

Chargement…
Annuler
Enregistrer