Skip to content

Commit

Permalink
🎨 Apply F() to MKS UI errors, assets
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 25, 2021
1 parent 24dbece commit 492d704
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 153 deletions.
9 changes: 5 additions & 4 deletions Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@

static lv_obj_t *scr;

void lv_draw_error_message(PGM_P const msg) {
void lv_draw_error_message(FSTR_P const fmsg) {
FSTR_P fhalted = F("PRINTER HALTED"), fplease = F("Please Reset");
SPI_TFT.LCD_clear(0x0000);
if (msg) disp_string((TFT_WIDTH - strlen(msg) * 16) / 2, 100, msg, 0xFFFF, 0x0000);
disp_string((TFT_WIDTH - strlen("PRINTER HALTED") * 16) / 2, 140, "PRINTER HALTED", 0xFFFF, 0x0000);
disp_string((TFT_WIDTH - strlen("Please Reset") * 16) / 2, 180, "Please Reset", 0xFFFF, 0x0000);
if (fmsg) disp_string((TFT_WIDTH - strlen_P(FTOP(fmsg)) * 16) / 2, 100, fmsg, 0xFFFF, 0x0000);
disp_string((TFT_WIDTH - strlen_P(FTOP(fhalted)) * 16) / 2, 140, fhalted, 0xFFFF, 0x0000);
disp_string((TFT_WIDTH - strlen_P(FTOP(fplease)) * 16) / 2, 180, fplease, 0xFFFF, 0x0000);
}

void lv_clear_error_message() { lv_obj_del(scr); }
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/mks_ui/draw_error_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define PGM_P const char *
#endif

void lv_draw_error_message(PGM_P const msg);
void lv_draw_error_message(FSTR_P const fmsg);
void lv_clear_error_message();

#ifdef __cplusplus
Expand Down
28 changes: 16 additions & 12 deletions Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,24 +697,28 @@ void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint1
}
}

void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor, uint16_t bkColor) {
while (*string != '\0') {
disp_char_1624(x, y, *string, charColor, bkColor);
string++;
x += 16;
}
void disp_string(uint16_t x, uint16_t y, const char * cstr, uint16_t charColor, uint16_t bkColor) {
for (char c; (c = *cstr); cstr++, x += 16)
disp_char_1624(x, y, c, charColor, bkColor);
}

void disp_string(uint16_t x, uint16_t y, FSTR_P const fstr, uint16_t charColor, uint16_t bkColor) {
PGM_P pstr = FTOP(fstr);
for (char c; (c = pgm_read_byte(pstr)); pstr++, x += 16)
disp_char_1624(x, y, c, charColor, bkColor);
}

void disp_assets_update() {
SPI_TFT.LCD_clear(0x0000);
disp_string(100, 140, "Assets Updating...", 0xFFFF, 0x0000);
disp_string(100, 140, F("Assets Updating..."), 0xFFFF, 0x0000);
}

void disp_assets_update_progress(const char *msg) {
char buf[30];
memset(buf, ' ', COUNT(buf));
strncpy(buf, msg, strlen(msg));
buf[COUNT(buf) - 1] = '\0';
void disp_assets_update_progress(FSTR_P const fmsg) {
static constexpr int buflen = 30;
char buf[buflen];
memset(buf, ' ', buflen);
strncpy_P(buf, FTOP(fmsg), buflen - 1);
buf[buflen - 1] = '\0';
disp_string(100, 165, buf, 0xFFFF, 0x0000);
}

Expand Down
5 changes: 3 additions & 2 deletions Marlin/src/lcd/extui/mks_ui/mks_hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#endif

// String display and assets
void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor, uint16_t bkColor);
void disp_string(uint16_t x, uint16_t y, const char * cstr, uint16_t charColor, uint16_t bkColor);
void disp_string(uint16_t x, uint16_t y, FSTR_P const fstr, uint16_t charColor, uint16_t bkColor);
void disp_assets_update();
void disp_assets_update_progress(const char *msg);
void disp_assets_update_progress(FSTR_P const msg);
Loading

0 comments on commit 492d704

Please sign in to comment.