Skip to content

Commit 492d704

Browse files
committed
🎨 Apply F() to MKS UI errors, assets
1 parent 24dbece commit 492d704

5 files changed

Lines changed: 159 additions & 153 deletions

File tree

Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333

3434
static lv_obj_t *scr;
3535

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");
3738
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);
4142
}
4243

4344
void lv_clear_error_message() { lv_obj_del(scr); }

Marlin/src/lcd/extui/mks_ui/draw_error_message.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define PGM_P const char *
3030
#endif
3131

32-
void lv_draw_error_message(PGM_P const msg);
32+
void lv_draw_error_message(FSTR_P const fmsg);
3333
void lv_clear_error_message();
3434

3535
#ifdef __cplusplus

Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -697,24 +697,28 @@ void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint1
697697
}
698698
}
699699

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);
706709
}
707710

708711
void disp_assets_update() {
709712
SPI_TFT.LCD_clear(0x0000);
710-
disp_string(100, 140, "Assets Updating...", 0xFFFF, 0x0000);
713+
disp_string(100, 140, F("Assets Updating..."), 0xFFFF, 0x0000);
711714
}
712715

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';
718722
disp_string(100, 165, buf, 0xFFFF, 0x0000);
719723
}
720724

Marlin/src/lcd/extui/mks_ui/mks_hardware.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#endif
3737

3838
// 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);
4041
void disp_assets_update();
41-
void disp_assets_update_progress(const char *msg);
42+
void disp_assets_update_progress(FSTR_P const msg);

0 commit comments

Comments
 (0)