Skip to content

Commit 1e27824

Browse files
thinkyheadLCh-77
authored andcommitted
πŸ§‘β€πŸ’» Apply F() to some LCD / TFT strings
Followup to MarlinFirmware#24228
1 parent b0442b0 commit 1e27824

20 files changed

+160
-109
lines changed

β€ŽMarlin/src/gcode/queue.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,15 @@ bool GCodeQueue::process_injected_command() {
196196
* Never call this from a G-code handler!
197197
*/
198198
void GCodeQueue::enqueue_one_now(const char * const cmd) { while (!enqueue_one(cmd)) idle(); }
199+
void GCodeQueue::enqueue_one_now(FSTR_P const fcmd) { while (!enqueue_one(fcmd)) idle(); }
199200

200201
/**
201202
* Attempt to enqueue a single G-code command
202203
* and return 'true' if successful.
203204
*/
204-
bool GCodeQueue::enqueue_one(FSTR_P const fgcode) {
205+
bool GCodeQueue::enqueue_one(FSTR_P const fcmd) {
205206
size_t i = 0;
206-
PGM_P p = FTOP(fgcode);
207+
PGM_P p = FTOP(fcmd);
207208
char c;
208209
while ((c = pgm_read_byte(&p[i])) && c != '\n') i++;
209210
char cmd[i + 1];

β€ŽMarlin/src/gcode/queue.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,13 @@ class GCodeQueue {
141141
* Enqueue and return only when commands are actually enqueued
142142
*/
143143
static void enqueue_one_now(const char * const cmd);
144+
static void enqueue_one_now(FSTR_P const fcmd);
144145

145146
/**
146147
* Attempt to enqueue a single G-code command
147148
* and return 'true' if successful.
148149
*/
149-
static bool enqueue_one(FSTR_P const fgcode);
150+
static bool enqueue_one(FSTR_P const fcmd);
150151

151152
/**
152153
* Enqueue with Serial Echo

β€ŽMarlin/src/lcd/e3v2/common/dwin_api.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,13 @@ void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
176176
void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * const string, uint16_t rlimit=0xFFFF);
177177

178178
inline void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, FSTR_P const ftitle) {
179-
char ctitle[strlen_P(FTOP(ftitle)) + 1];
180-
strcpy_P(ctitle, FTOP(ftitle));
181-
DWIN_Draw_String(bShow, size, color, bColor, x, y, ctitle);
179+
#ifdef __AVR__
180+
char ctitle[strlen_P(FTOP(ftitle)) + 1];
181+
strcpy_P(ctitle, FTOP(ftitle));
182+
DWIN_Draw_String(bShow, size, color, bColor, x, y, ctitle);
183+
#else
184+
DWIN_Draw_String(bShow, size, color, bColor, x, y, FTOP(ftitle));
185+
#endif
182186
}
183187

184188
// Draw a positive integer

β€ŽMarlin/src/lcd/e3v2/creality/dwin.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -4307,9 +4307,13 @@ void DWIN_StatusChanged(const char * const cstr/*=nullptr*/) {
43074307
}
43084308

43094309
void DWIN_StatusChanged(FSTR_P const fstr) {
4310-
char str[strlen_P(FTOP(fstr)) + 1];
4311-
strcpy_P(str, FTOP(fstr));
4312-
DWIN_StatusChanged(str);
4310+
#ifdef __AVR__
4311+
char str[strlen_P(FTOP(fstr)) + 1];
4312+
strcpy_P(str, FTOP(fstr));
4313+
DWIN_StatusChanged(str);
4314+
#else
4315+
DWIN_StatusChanged(FTOP(fstr));
4316+
#endif
43134317
}
43144318

43154319
#endif // DWIN_CREALITY_LCD

β€ŽMarlin/src/lcd/e3v2/marlinui/ui_common.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,15 @@ void MarlinUI::draw_status_message(const bool blink) {
274274

275275
dwin_font.solid = false;
276276
dwin_font.fg = Color_White;
277-
dwin_string.set("E");
277+
dwin_string.set('E');
278278
dwin_string.add('1' + extruder);
279279
dwin_string.add(' ');
280280
dwin_string.add(i16tostr3rj(thermalManager.degHotend(extruder)));
281281
dwin_string.add('/');
282282
if (get_blink() || !thermalManager.heater_idle[thermalManager.idle_index_for_id(extruder)].timed_out)
283283
dwin_string.add(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
284284
else
285-
dwin_string.add(PSTR(" "));
285+
dwin_string.add(F(" "));
286286

287287
lcd_moveto(LCD_WIDTH - dwin_string.length, row);
288288
lcd_put_dwin_string();
@@ -540,11 +540,11 @@ void MarlinUI::draw_status_message(const bool blink) {
540540
lcd_put_u8str(ftostr52(lpos.y));
541541

542542
// Print plot position
543-
dwin_string.set("(");
543+
dwin_string.set('(');
544544
dwin_string.add(i8tostr3rj(x_plot));
545-
dwin_string.add(",");
545+
dwin_string.add(',');
546546
dwin_string.add(i8tostr3rj(y_plot));
547-
dwin_string.add(")");
547+
dwin_string.add(')');
548548
lcd_moveto(
549549
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length),
550550
TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 2, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 1)
@@ -556,7 +556,7 @@ void MarlinUI::draw_status_message(const bool blink) {
556556
if (!isnan(bedlevel.z_values[x_plot][y_plot]))
557557
dwin_string.add(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
558558
else
559-
dwin_string.add(PSTR(" -----"));
559+
dwin_string.add(F(" -----"));
560560
lcd_moveto(
561561
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length),
562562
TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 1, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 2)

β€ŽMarlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
8888

8989
// For E_TOTAL there may be some characters to cover up
9090
if (BOTH(DWIN_MARLINUI_PORTRAIT, LCD_SHOW_E_TOTAL) && axis == X_AXIS)
91-
dwin_string.add(" ");
91+
dwin_string.add(F(" "));
9292

9393
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
9494

@@ -117,7 +117,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
117117

118118
// For E_TOTAL there may be some characters to cover up
119119
if (ENABLED(LCD_SHOW_E_TOTAL) && (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) && axis == X_AXIS)
120-
dwin_string.add(" ");
120+
dwin_string.add(F(" "));
121121

122122
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 32, y + 4, S(dwin_string.string()));
123123

@@ -133,7 +133,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
133133

134134
if (!ui.did_first_redraw) {
135135
// Extra spaces to erase previous value
136-
dwin_string.set("E ");
136+
dwin_string.set(F("E "));
137137
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (4 * 14 / 2) - 7, y + 2, S(dwin_string.string()));
138138
}
139139

@@ -146,7 +146,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
146146
#else // !DWIN_MARLINUI_PORTRAIT
147147

148148
if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
149-
dwin_string.set("E ");
149+
dwin_string.set(F("E "));
150150
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x, y, S(dwin_string.string()));
151151
}
152152

@@ -176,7 +176,7 @@ FORCE_INLINE void _draw_fan_status(const uint16_t x, const uint16_t y) {
176176
else {
177177
DWIN_ICON_AnimationControl(0x0000); // disable all icon animations (this is the only one)
178178
DWIN_ICON_Show(ICON, ICON_Fan0, x + fanx, y);
179-
dwin_string.set(PSTR(" "));
179+
dwin_string.set(F(" "));
180180
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
181181
}
182182
}
@@ -289,7 +289,7 @@ FORCE_INLINE void _draw_feedrate_status(const char *value, uint16_t x, uint16_t
289289
}
290290

291291
dwin_string.set(value);
292-
dwin_string.add(PSTR("%"));
292+
dwin_string.add('%');
293293
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 14, y, S(dwin_string.string()));
294294
}
295295

@@ -396,7 +396,7 @@ void MarlinUI::draw_status_screen() {
396396
// landscape mode shows both elapsed and remaining (if SHOW_REMAINING_TIME)
397397
time = print_job_timer.duration();
398398
time.toDigital(buffer);
399-
dwin_string.set(" ");
399+
dwin_string.set(' ');
400400
dwin_string.add(buffer);
401401
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 230, 170, S(dwin_string.string()));
402402

@@ -405,15 +405,15 @@ void MarlinUI::draw_status_screen() {
405405
time = get_remaining_time();
406406
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(" R "));
407407
if (print_job_timer.isPaused() && blink)
408-
dwin_string.set(" ");
408+
dwin_string.set(F(" "));
409409
else {
410410
time.toDigital(buffer);
411411
dwin_string.set(buffer);
412412
}
413413
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 378, 170, S(dwin_string.string()));
414414
}
415415
else if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
416-
dwin_string.set(" ");
416+
dwin_string.set(F(" "));
417417
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(dwin_string.string()));
418418
}
419419
#endif
@@ -449,7 +449,7 @@ void MarlinUI::draw_status_screen() {
449449

450450
#if ENABLED(SHOW_SD_PERCENT)
451451
dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
452-
dwin_string.add(PSTR("%"));
452+
dwin_string.add('%');
453453
DWIN_Draw_String(
454454
false, font16x32, Percent_Color, Color_Bg_Black,
455455
pb_left + (pb_width - dwin_string.length * 16) / 2,

β€ŽMarlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,8 @@ void DGUSScreenHandler::HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr
474474

475475
void DGUSScreenHandler::HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr) {
476476
DEBUG_ECHOLNPGM("HandleMotorLockUnlock");
477-
478-
char buf[4];
479477
const int16_t lock = swap16(*(uint16_t*)val_ptr);
480-
strcpy_P(buf, lock ? PSTR("M18") : PSTR("M17"));
481-
482-
//DEBUG_ECHOPGM(" ", buf);
483-
queue.enqueue_one_now(buf);
478+
queue.enqueue_one_now(lock ? F("M18") : F("M17"));
484479
}
485480

486481
void DGUSScreenHandler::HandleSettings(DGUS_VP_Variable &var, void *val_ptr) {
@@ -552,23 +547,23 @@ void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, vo
552547
#if HAS_HOTEND
553548
case VP_PID_AUTOTUNE_E0: // Autotune Extruder 0
554549
sprintf_P(buf, PSTR("M303 E%d C5 S210 U1"), ExtUI::extruder_t::E0);
550+
queue.enqueue_one_now(buf);
555551
break;
556552
#endif
557553
#if HAS_MULTI_HOTEND
558554
case VP_PID_AUTOTUNE_E1:
559555
sprintf_P(buf, PSTR("M303 E%d C5 S210 U1"), ExtUI::extruder_t::E1);
556+
queue.enqueue_one_now(buf);
560557
break;
561558
#endif
562559
#endif
563560
#if ENABLED(PIDTEMPBED)
564561
case VP_PID_AUTOTUNE_BED:
565-
strcpy_P(buf, PSTR("M303 E-1 C5 S70 U1"));
562+
queue.enqueue_one_now(F("M303 E-1 C5 S70 U1"));
566563
break;
567564
#endif
568565
}
569566

570-
if (buf[0]) queue.enqueue_one_now(buf);
571-
572567
#if ENABLED(DGUS_UI_WAITING)
573568
sendinfoscreen(F("PID is autotuning"), F("please wait"), NUL_STR, NUL_STR, true, true, true, true);
574569
GotoScreen(DGUSLCD_SCREEN_WAITING);

β€ŽMarlin/src/lcd/extui/ftdi_eve_touch_ui/bioprinter/printing_dialog_box.cpp

+13-9
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ using namespace Theme;
3232
#define GRID_COLS 2
3333
#define GRID_ROWS 9
3434

35-
void BioPrintingDialogBox::draw_status_message(draw_mode_t what, const char *message) {
35+
void BioPrintingDialogBox::draw_status_message(draw_mode_t what, const char *cmsg) {
3636
if (what & BACKGROUND) {
3737
CommandProcessor cmd;
3838
cmd.cmd(COLOR_RGB(bg_text_enabled))
3939
.tag(0);
40-
draw_text_box(cmd, BTN_POS(1,2), BTN_SIZE(2,2), message, OPT_CENTER, font_large);
40+
draw_text_box(cmd, BTN_POS(1,2), BTN_SIZE(2,2), cmsg, OPT_CENTER, font_large);
4141
}
4242
}
4343

@@ -105,26 +105,30 @@ bool BioPrintingDialogBox::onTouchEnd(uint8_t tag) {
105105
return true;
106106
}
107107

108-
void BioPrintingDialogBox::setStatusMessage(FSTR_P message) {
109-
char buff[strlen_P(FTOP(message)) + 1];
110-
strcpy_P(buff, FTOP(message));
111-
setStatusMessage(buff);
108+
void BioPrintingDialogBox::setStatusMessage(FSTR_P fmsg) {
109+
#ifdef __AVR__
110+
char buff[strlen_P(FTOP(fmsg)) + 1];
111+
strcpy_P(buff, FTOP(fmsg));
112+
setStatusMessage(buff);
113+
#else
114+
setStatusMessage(FTOP(fmsg));
115+
#endif
112116
}
113117

114-
void BioPrintingDialogBox::setStatusMessage(const char *message) {
118+
void BioPrintingDialogBox::setStatusMessage(const char *cmsg) {
115119
CommandProcessor cmd;
116120
cmd.cmd(CMD_DLSTART)
117121
.cmd(CLEAR_COLOR_RGB(bg_color))
118122
.cmd(CLEAR(true,true,true));
119123

120-
draw_status_message(BACKGROUND, message);
124+
draw_status_message(BACKGROUND, cmsg);
121125
draw_progress(BACKGROUND);
122126
draw_time_remaining(BACKGROUND);
123127
draw_interaction_buttons(BACKGROUND);
124128
storeBackground();
125129

126130
#if ENABLED(TOUCH_UI_DEBUG)
127-
SERIAL_ECHO_MSG("New status message: ", message);
131+
SERIAL_ECHO_MSG("New status message: ", cmsg);
128132
#endif
129133

130134
if (AT_SCREEN(BioPrintingDialogBox))

β€ŽMarlin/src/lcd/extui/ftdi_eve_touch_ui/bioprinter/status_screen.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void StatusScreen::draw_temperature(draw_mode_t what) {
122122

123123
ui.bounds(POLY(bed_temp), x, y, h, v);
124124
cmd.text(x, y, h, v, str);
125-
#endif
125+
#endif
126126
}
127127
}
128128

@@ -354,8 +354,8 @@ bool StatusScreen::onTouchHeld(uint8_t tag) {
354354
return false;
355355
}
356356

357-
void StatusScreen::setStatusMessage(FSTR_P pstr) {
358-
BioPrintingDialogBox::setStatusMessage(pstr);
357+
void StatusScreen::setStatusMessage(FSTR_P fstr) {
358+
BioPrintingDialogBox::setStatusMessage(fstr);
359359
}
360360

361361
void StatusScreen::setStatusMessage(const char * const str) {

β€ŽMarlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ namespace FTDI {
136136
}
137137

138138
void draw_text_box(CommandProcessor& cmd, int x, int y, int w, int h, FSTR_P fstr, uint16_t options, uint8_t font) {
139-
char str[strlen_P(FTOP(fstr)) + 1];
140-
strcpy_P(str, FTOP(fstr));
141-
draw_text_box(cmd, x, y, w, h, (const char*) str, options, font);
139+
#ifdef __AVR__
140+
char str[strlen_P(FTOP(fstr)) + 1];
141+
strcpy_P(str, FTOP(fstr));
142+
draw_text_box(cmd, x, y, w, h, (const char*) str, options, font);
143+
#else
144+
draw_text_box(cmd, x, y, w, h, FTOP(fstr), options, font);
145+
#endif
142146
}
143147
} // namespace FTDI
144148

β€ŽMarlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,13 @@
192192
}
193193

194194
uint16_t FTDI::get_utf8_text_width(FSTR_P fstr, font_size_t fs) {
195-
char str[strlen_P(FTOP(fstr)) + 1];
196-
strcpy_P(str, FTOP(fstr));
197-
return get_utf8_text_width(str, fs);
195+
#ifdef __AVR__
196+
char str[strlen_P(FTOP(fstr)) + 1];
197+
strcpy_P(str, FTOP(fstr));
198+
return get_utf8_text_width(str, fs);
199+
#else
200+
return get_utf8_text_width(FTOP(fstr), fs);
201+
#endif
198202
}
199203

200204
/**

β€ŽMarlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using namespace Theme;
3232
#define GRID_ROWS 8
3333

3434
template<typename T>
35-
void DialogBoxBaseClass::drawMessage(T message, int16_t font) {
35+
void DialogBoxBaseClass::drawMessage(T message, const int16_t font) {
3636
CommandProcessor cmd;
3737
cmd.cmd(CMD_DLSTART)
3838
.cmd(CLEAR_COLOR_RGB(bg_color))
@@ -43,8 +43,7 @@ void DialogBoxBaseClass::drawMessage(T message, int16_t font) {
4343
cmd.colors(normal_btn);
4444
}
4545

46-
template void DialogBoxBaseClass::drawMessage(const char *, int16_t font);
47-
template void DialogBoxBaseClass::drawMessage(FSTR_P, int16_t font);
46+
template void DialogBoxBaseClass::drawMessage(PGM_P const, const int16_t);
4847

4948
void DialogBoxBaseClass::drawYesNoButtons(uint8_t default_btn) {
5049
CommandProcessor cmd;

β€ŽMarlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727

2828
class DialogBoxBaseClass : public BaseScreen {
2929
protected:
30-
template<typename T> static void drawMessage(T, int16_t font = 0);
30+
template<typename T> static void drawMessage(T, const int16_t font=0);
31+
static void drawMessage(FSTR_P const fstr, const int16_t font=0) { drawMessage(FTOP(fstr), font); }
32+
3133
template<typename T> static void drawButton(T);
3234
static void drawYesNoButtons(uint8_t default_btn = 0);
3335
static void drawOkayButton();
3436

35-
static void onRedraw(draw_mode_t) {};
37+
static void onRedraw(draw_mode_t) {}
38+
3639
public:
3740
static bool onTouchEnd(uint8_t tag);
3841
static void onIdle();

0 commit comments

Comments
Β (0)