Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Apply F() to some LCD / TFT strings
Browse files Browse the repository at this point in the history
Followup to #24228
  • Loading branch information
thinkyhead committed Jun 14, 2022
1 parent f31178f commit 5408259
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 109 deletions.
5 changes: 3 additions & 2 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,15 @@ bool GCodeQueue::process_injected_command() {
* Never call this from a G-code handler!
*/
void GCodeQueue::enqueue_one_now(const char * const cmd) { while (!enqueue_one(cmd)) idle(); }
void GCodeQueue::enqueue_one_now(FSTR_P const fcmd) { while (!enqueue_one(fcmd)) idle(); }

/**
* Attempt to enqueue a single G-code command
* and return 'true' if successful.
*/
bool GCodeQueue::enqueue_one(FSTR_P const fgcode) {
bool GCodeQueue::enqueue_one(FSTR_P const fcmd) {
size_t i = 0;
PGM_P p = FTOP(fgcode);
PGM_P p = FTOP(fcmd);
char c;
while ((c = pgm_read_byte(&p[i])) && c != '\n') i++;
char cmd[i + 1];
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/gcode/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,13 @@ class GCodeQueue {
* Enqueue and return only when commands are actually enqueued
*/
static void enqueue_one_now(const char * const cmd);
static void enqueue_one_now(FSTR_P const fcmd);

/**
* Attempt to enqueue a single G-code command
* and return 'true' if successful.
*/
static bool enqueue_one(FSTR_P const fgcode);
static bool enqueue_one(FSTR_P const fcmd);

/**
* Enqueue with Serial Echo
Expand Down
10 changes: 7 additions & 3 deletions Marlin/src/lcd/e3v2/common/dwin_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
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);

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) {
char ctitle[strlen_P(FTOP(ftitle)) + 1];
strcpy_P(ctitle, FTOP(ftitle));
DWIN_Draw_String(bShow, size, color, bColor, x, y, ctitle);
#ifdef __AVR__
char ctitle[strlen_P(FTOP(ftitle)) + 1];
strcpy_P(ctitle, FTOP(ftitle));
DWIN_Draw_String(bShow, size, color, bColor, x, y, ctitle);
#else
DWIN_Draw_String(bShow, size, color, bColor, x, y, FTOP(ftitle));
#endif
}

// Draw a positive integer
Expand Down
10 changes: 7 additions & 3 deletions Marlin/src/lcd/e3v2/creality/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4307,9 +4307,13 @@ void DWIN_StatusChanged(const char * const cstr/*=nullptr*/) {
}

void DWIN_StatusChanged(FSTR_P const fstr) {
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
DWIN_StatusChanged(str);
#ifdef __AVR__
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
DWIN_StatusChanged(str);
#else
DWIN_StatusChanged(FTOP(fstr));
#endif
}

#endif // DWIN_CREALITY_LCD
12 changes: 6 additions & 6 deletions Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ void MarlinUI::draw_status_message(const bool blink) {

dwin_font.solid = false;
dwin_font.fg = Color_White;
dwin_string.set("E");
dwin_string.set('E');
dwin_string.add('1' + extruder);
dwin_string.add(' ');
dwin_string.add(i16tostr3rj(thermalManager.degHotend(extruder)));
dwin_string.add('/');
if (get_blink() || !thermalManager.heater_idle[thermalManager.idle_index_for_id(extruder)].timed_out)
dwin_string.add(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
else
dwin_string.add(PSTR(" "));
dwin_string.add(F(" "));

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

// Print plot position
dwin_string.set("(");
dwin_string.set('(');
dwin_string.add(i8tostr3rj(x_plot));
dwin_string.add(",");
dwin_string.add(',');
dwin_string.add(i8tostr3rj(y_plot));
dwin_string.add(")");
dwin_string.add(')');
lcd_moveto(
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length),
TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 2, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 1)
Expand All @@ -556,7 +556,7 @@ void MarlinUI::draw_status_message(const bool blink) {
if (!isnan(bedlevel.z_values[x_plot][y_plot]))
dwin_string.add(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else
dwin_string.add(PSTR(" -----"));
dwin_string.add(F(" -----"));
lcd_moveto(
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length),
TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 1, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 2)
Expand Down
20 changes: 10 additions & 10 deletions Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const

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

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

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

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

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

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

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

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

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

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

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

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

Expand All @@ -405,15 +405,15 @@ void MarlinUI::draw_status_screen() {
time = get_remaining_time();
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(" R "));
if (print_job_timer.isPaused() && blink)
dwin_string.set(" ");
dwin_string.set(F(" "));
else {
time.toDigital(buffer);
dwin_string.set(buffer);
}
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 378, 170, S(dwin_string.string()));
}
else if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
dwin_string.set(" ");
dwin_string.set(F(" "));
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(dwin_string.string()));
}
#endif
Expand Down Expand Up @@ -449,7 +449,7 @@ void MarlinUI::draw_status_screen() {

#if ENABLED(SHOW_SD_PERCENT)
dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
dwin_string.add(PSTR("%"));
dwin_string.add('%');
DWIN_Draw_String(
false, font16x32, Percent_Color, Color_Bg_Black,
pb_left + (pb_width - dwin_string.length * 16) / 2,
Expand Down
13 changes: 4 additions & 9 deletions Marlin/src/lcd/extui/dgus/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,8 @@ void DGUSScreenHandler::HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr

void DGUSScreenHandler::HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr) {
DEBUG_ECHOLNPGM("HandleMotorLockUnlock");

char buf[4];
const int16_t lock = swap16(*(uint16_t*)val_ptr);
strcpy_P(buf, lock ? PSTR("M18") : PSTR("M17"));

//DEBUG_ECHOPGM(" ", buf);
queue.enqueue_one_now(buf);
queue.enqueue_one_now(lock ? F("M18") : F("M17"));
}

void DGUSScreenHandler::HandleSettings(DGUS_VP_Variable &var, void *val_ptr) {
Expand Down Expand Up @@ -552,23 +547,23 @@ void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, vo
#if HAS_HOTEND
case VP_PID_AUTOTUNE_E0: // Autotune Extruder 0
sprintf_P(buf, PSTR("M303 E%d C5 S210 U1"), ExtUI::extruder_t::E0);
queue.enqueue_one_now(buf);
break;
#endif
#if HAS_MULTI_HOTEND
case VP_PID_AUTOTUNE_E1:
sprintf_P(buf, PSTR("M303 E%d C5 S210 U1"), ExtUI::extruder_t::E1);
queue.enqueue_one_now(buf);
break;
#endif
#endif
#if ENABLED(PIDTEMPBED)
case VP_PID_AUTOTUNE_BED:
strcpy_P(buf, PSTR("M303 E-1 C5 S70 U1"));
queue.enqueue_one_now(F("M303 E-1 C5 S70 U1"));
break;
#endif
}

if (buf[0]) queue.enqueue_one_now(buf);

#if ENABLED(DGUS_UI_WAITING)
sendinfoscreen(F("PID is autotuning"), F("please wait"), NUL_STR, NUL_STR, true, true, true, true);
GotoScreen(DGUSLCD_SCREEN_WAITING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ using namespace Theme;
#define GRID_COLS 2
#define GRID_ROWS 9

void BioPrintingDialogBox::draw_status_message(draw_mode_t what, const char *message) {
void BioPrintingDialogBox::draw_status_message(draw_mode_t what, const char *cmsg) {
if (what & BACKGROUND) {
CommandProcessor cmd;
cmd.cmd(COLOR_RGB(bg_text_enabled))
.tag(0);
draw_text_box(cmd, BTN_POS(1,2), BTN_SIZE(2,2), message, OPT_CENTER, font_large);
draw_text_box(cmd, BTN_POS(1,2), BTN_SIZE(2,2), cmsg, OPT_CENTER, font_large);
}
}

Expand Down Expand Up @@ -105,26 +105,30 @@ bool BioPrintingDialogBox::onTouchEnd(uint8_t tag) {
return true;
}

void BioPrintingDialogBox::setStatusMessage(FSTR_P message) {
char buff[strlen_P(FTOP(message)) + 1];
strcpy_P(buff, FTOP(message));
setStatusMessage(buff);
void BioPrintingDialogBox::setStatusMessage(FSTR_P fmsg) {
#ifdef __AVR__
char buff[strlen_P(FTOP(fmsg)) + 1];
strcpy_P(buff, FTOP(fmsg));
setStatusMessage(buff);
#else
setStatusMessage(FTOP(fmsg));
#endif
}

void BioPrintingDialogBox::setStatusMessage(const char *message) {
void BioPrintingDialogBox::setStatusMessage(const char *cmsg) {
CommandProcessor cmd;
cmd.cmd(CMD_DLSTART)
.cmd(CLEAR_COLOR_RGB(bg_color))
.cmd(CLEAR(true,true,true));

draw_status_message(BACKGROUND, message);
draw_status_message(BACKGROUND, cmsg);
draw_progress(BACKGROUND);
draw_time_remaining(BACKGROUND);
draw_interaction_buttons(BACKGROUND);
storeBackground();

#if ENABLED(TOUCH_UI_DEBUG)
SERIAL_ECHO_MSG("New status message: ", message);
SERIAL_ECHO_MSG("New status message: ", cmsg);
#endif

if (AT_SCREEN(BioPrintingDialogBox))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void StatusScreen::draw_temperature(draw_mode_t what) {

ui.bounds(POLY(bed_temp), x, y, h, v);
cmd.text(x, y, h, v, str);
#endif
#endif
}
}

Expand Down Expand Up @@ -354,8 +354,8 @@ bool StatusScreen::onTouchHeld(uint8_t tag) {
return false;
}

void StatusScreen::setStatusMessage(FSTR_P pstr) {
BioPrintingDialogBox::setStatusMessage(pstr);
void StatusScreen::setStatusMessage(FSTR_P fstr) {
BioPrintingDialogBox::setStatusMessage(fstr);
}

void StatusScreen::setStatusMessage(const char * const str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ namespace FTDI {
}

void draw_text_box(CommandProcessor& cmd, int x, int y, int w, int h, FSTR_P fstr, uint16_t options, uint8_t font) {
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
draw_text_box(cmd, x, y, w, h, (const char*) str, options, font);
#ifdef __AVR__
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
draw_text_box(cmd, x, y, w, h, (const char*) str, options, font);
#else
draw_text_box(cmd, x, y, w, h, FTOP(fstr), options, font);
#endif
}
} // namespace FTDI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@
}

uint16_t FTDI::get_utf8_text_width(FSTR_P fstr, font_size_t fs) {
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
return get_utf8_text_width(str, fs);
#ifdef __AVR__
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
return get_utf8_text_width(str, fs);
#else
return get_utf8_text_width(FTOP(fstr), fs);
#endif
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using namespace Theme;
#define GRID_ROWS 8

template<typename T>
void DialogBoxBaseClass::drawMessage(T message, int16_t font) {
void DialogBoxBaseClass::drawMessage(T message, const int16_t font) {
CommandProcessor cmd;
cmd.cmd(CMD_DLSTART)
.cmd(CLEAR_COLOR_RGB(bg_color))
Expand All @@ -43,8 +43,7 @@ void DialogBoxBaseClass::drawMessage(T message, int16_t font) {
cmd.colors(normal_btn);
}

template void DialogBoxBaseClass::drawMessage(const char *, int16_t font);
template void DialogBoxBaseClass::drawMessage(FSTR_P, int16_t font);
template void DialogBoxBaseClass::drawMessage(PGM_P const, const int16_t);

void DialogBoxBaseClass::drawYesNoButtons(uint8_t default_btn) {
CommandProcessor cmd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@

class DialogBoxBaseClass : public BaseScreen {
protected:
template<typename T> static void drawMessage(T, int16_t font = 0);
template<typename T> static void drawMessage(T, const int16_t font=0);
static void drawMessage(FSTR_P const fstr, const int16_t font=0) { drawMessage(FTOP(fstr), font); }

template<typename T> static void drawButton(T);
static void drawYesNoButtons(uint8_t default_btn = 0);
static void drawOkayButton();

static void onRedraw(draw_mode_t) {};
static void onRedraw(draw_mode_t) {}

public:
static bool onTouchEnd(uint8_t tag);
static void onIdle();
Expand Down
Loading

0 comments on commit 5408259

Please sign in to comment.