♻️ Apply F() to more LCD code (#24228)

This commit is contained in:
Scott Lahteine
2022-05-22 19:56:46 -05:00
committed by Scott Lahteine
parent 9a74bcd4cf
commit 28f8646aa6
44 changed files with 622 additions and 609 deletions

View File

@ -89,13 +89,13 @@ uint8_t read_byte(uint8_t *byte) { return *byte; }
/**
* Add a string, applying substitutions for the following characters:
*
* $ displays an inserted C-string given by the itemString parameter
* $ displays an inserted C-string given by the inStr parameter
* = displays '0'....'10' for indexes 0 - 10
* ~ displays '1'....'11' for indexes 0 - 10
* * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
* @ displays an axis name such as XYZUVW, or E for an extruder
*/
void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString/*=nullptr*/) {
void TFT_String::add(uint8_t *string, int8_t index, uint8_t *inStr/*=nullptr*/) {
wchar_t wchar;
while (*string) {
@ -113,8 +113,8 @@ void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString/*=nullpt
else
add(index == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED));
}
else if (ch == '$' && itemString)
add(itemString);
else if (ch == '$' && inStr)
add(inStr);
else if (ch == '@')
add_character(axis_codes[index]);
else

View File

@ -86,13 +86,19 @@ class TFT_String {
static void set();
static void add(uint8_t character) { add_character(character); eol(); }
static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH);
static void add(uint8_t *string, int8_t index, uint8_t *itemString=nullptr);
static void add(uint8_t *string, int8_t index, uint8_t *inStr=nullptr);
static void set(uint8_t *string) { set(); add(string); };
static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); };
static void set(uint8_t *string, int8_t index, const char *inStr=nullptr) { set(); add(string, index, (uint8_t *)inStr); };
static void set(const char *string) { set((uint8_t *)string); }
static void set(const char *string, int8_t index, const char *itemString=nullptr) { set((uint8_t *)string, index, itemString); }
static void set(const char *string, int8_t index, const char *inStr=nullptr) { set((uint8_t *)string, index, inStr); }
static void add(const char *string) { add((uint8_t *)string); }
static void add(FSTR_P const string, uint8_t max_len=MAX_STRING_LENGTH) { add((uint8_t *)FTOP(string), max_len); }
static void add(FSTR_P const string, int8_t index, uint8_t *inStr=nullptr) { add((uint8_t *)FTOP(string), index, inStr); }
static void set(FSTR_P const string) { set((uint8_t *)FTOP(string)); }
static void set(FSTR_P const string, int8_t index, const char *inStr=nullptr) { set((uint8_t *)FTOP(string), index, inStr); }
static void add(FSTR_P const string) { add((uint8_t *)FTOP(string)); }
static void trim(uint8_t character=0x20);
static void rtrim(uint8_t character=0x20);
static void ltrim(uint8_t character=0x20);

View File

@ -189,26 +189,26 @@ void Touch::touch(touch_control_t *control) {
#if HAS_HOTEND
if (heater >= 0) { // HotEnd
#if HOTENDS == 1
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE), &thermalManager.temp_hotend[0].target, 0, thermalManager.hotend_max_target(0), []{ thermalManager.start_watching_hotend(0); });
MenuItem_int3::action(GET_TEXT_F(MSG_NOZZLE), &thermalManager.temp_hotend[0].target, 0, thermalManager.hotend_max_target(0), []{ thermalManager.start_watching_hotend(0); });
#else
MenuItemBase::itemIndex = heater;
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_NOZZLE_N), &thermalManager.temp_hotend[heater].target, 0, thermalManager.hotend_max_target(heater), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); });
MenuItem_int3::action(GET_TEXT_F(MSG_NOZZLE_N), &thermalManager.temp_hotend[heater].target, 0, thermalManager.hotend_max_target(heater), []{ thermalManager.start_watching_hotend(MenuItemBase::itemIndex); });
#endif
}
#endif
#if HAS_HEATED_BED
else if (heater == H_BED) {
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_BED), &thermalManager.temp_bed.target, 0, BED_MAX_TARGET, thermalManager.start_watching_bed);
MenuItem_int3::action(GET_TEXT_F(MSG_BED), &thermalManager.temp_bed.target, 0, BED_MAX_TARGET, thermalManager.start_watching_bed);
}
#endif
#if HAS_HEATED_CHAMBER
else if (heater == H_CHAMBER) {
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_CHAMBER), &thermalManager.temp_chamber.target, 0, CHAMBER_MAX_TARGET, thermalManager.start_watching_chamber);
MenuItem_int3::action(GET_TEXT_F(MSG_CHAMBER), &thermalManager.temp_chamber.target, 0, CHAMBER_MAX_TARGET, thermalManager.start_watching_chamber);
}
#endif
#if HAS_COOLER
else if (heater == H_COOLER) {
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_COOLER), &thermalManager.temp_cooler.target, 0, COOLER_MAX_TARGET, thermalManager.start_watching_cooler);
MenuItem_int3::action(GET_TEXT_F(MSG_COOLER), &thermalManager.temp_cooler.target, 0, COOLER_MAX_TARGET, thermalManager.start_watching_cooler);
}
#endif
@ -218,19 +218,19 @@ void Touch::touch(touch_control_t *control) {
static uint8_t fan, fan_speed;
fan = 0;
fan_speed = thermalManager.fan_speed[fan];
MenuItem_percent::action((const char *)GET_TEXT_F(MSG_FIRST_FAN_SPEED), &fan_speed, 0, 255, []{ thermalManager.set_fan_speed(fan, fan_speed); });
MenuItem_percent::action(GET_TEXT_F(MSG_FIRST_FAN_SPEED), &fan_speed, 0, 255, []{ thermalManager.set_fan_speed(fan, fan_speed); });
break;
case FEEDRATE:
ui.clear_lcd();
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_SPEED), &feedrate_percentage, 10, 999);
MenuItem_int3::action(GET_TEXT_F(MSG_SPEED), &feedrate_percentage, 10, 999);
break;
case FLOWRATE:
ui.clear_lcd();
MenuItemBase::itemIndex = control->data;
#if EXTRUDERS == 1
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_FLOW), &planner.flow_percentage[MenuItemBase::itemIndex], 10, 999, []{ planner.refresh_e_factor(MenuItemBase::itemIndex); });
MenuItem_int3::action(GET_TEXT_F(MSG_FLOW), &planner.flow_percentage[MenuItemBase::itemIndex], 10, 999, []{ planner.refresh_e_factor(MenuItemBase::itemIndex); });
#else
MenuItem_int3::action((const char *)GET_TEXT_F(MSG_FLOW_N), &planner.flow_percentage[MenuItemBase::itemIndex], 10, 999, []{ planner.refresh_e_factor(MenuItemBase::itemIndex); });
MenuItem_int3::action(GET_TEXT_F(MSG_FLOW_N), &planner.flow_percentage[MenuItemBase::itemIndex], 10, 999, []{ planner.refresh_e_factor(MenuItemBase::itemIndex); });
#endif
break;

View File

@ -105,12 +105,12 @@ void MarlinUI::draw_kill_screen() {
line++;
menu_line(line++, COLOR_KILL_SCREEN_BG);
tft_string.set(GET_TEXT(MSG_HALTED));
tft_string.set(GET_TEXT_F(MSG_HALTED));
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
menu_line(line++, COLOR_KILL_SCREEN_BG);
tft_string.set(GET_TEXT(MSG_PLEASE_RESET));
tft_string.set(GET_TEXT_F(MSG_PLEASE_RESET));
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
@ -352,14 +352,14 @@ void MarlinUI::draw_status_screen() {
}
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const value/*=nullptr*/) {
void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const value/*=nullptr*/) {
ui.encoder_direction_normal();
TERN_(TOUCH_SCREEN, touch.clear());
uint16_t line = 1;
menu_line(line++);
tft_string.set(pstr, itemIndex, itemString);
tft_string.set(FTOP(fstr), itemIndex, FTOP(itemString));
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
@ -421,7 +421,7 @@ void TFT::draw_edit_screen_buttons() {
}
// The Select Screen presents a prompt and two "buttons"
void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, const bool yesno, FSTR_P const pref, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/) {
uint16_t line = 1;
if (!string) line++;
@ -473,7 +473,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
#endif
menu_line(row);
tft_string.set(GET_TEXT(MSG_FILAMENT_CHANGE_NOZZLE));
tft_string.set(GET_TEXT_F(MSG_FILAMENT_CHANGE_NOZZLE));
tft_string.add('E');
tft_string.add((char)('1' + extruder));
tft_string.add(' ');
@ -693,18 +693,18 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
drawAxisValue(axis);
}
else {
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS));
}
#elif HAS_BED_PROBE
// only change probe.offset.z
probe.offset.z += diff;
if (direction < 0 && current_position[axis] < Z_PROBE_OFFSET_RANGE_MIN) {
current_position[axis] = Z_PROBE_OFFSET_RANGE_MIN;
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS));
}
else if (direction > 0 && current_position[axis] > Z_PROBE_OFFSET_RANGE_MAX) {
current_position[axis] = Z_PROBE_OFFSET_RANGE_MAX;
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS));
}
else {
drawMessage(""); // clear the error
@ -733,7 +733,7 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
#if IS_KINEMATIC
UNUSED(limited);
#else
PGM_P const msg = limited ? GET_TEXT(MSG_LCD_SOFT_ENDSTOPS) : NUL_STR;
FSTR_P const msg = limited ? GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS) : FPSTR(NUL_STR);
drawMessage(msg);
#endif
@ -766,7 +766,7 @@ static void z_minus() { moveAxis(Z_AXIS, -1); }
static void do_home() {
quick_feedback();
drawMessage(GET_TEXT(MSG_LEVEL_BED_HOMING));
drawMessage(GET_TEXT_F(MSG_LEVEL_BED_HOMING));
queue.inject_P(G28_STR);
// Disable touch until home is done
TERN_(TOUCH_SCREEN, touch.disable());

View File

@ -347,14 +347,14 @@ void MarlinUI::draw_status_screen() {
}
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const value/*=nullptr*/) {
void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const value/*=nullptr*/) {
ui.encoder_direction_normal();
TERN_(TOUCH_SCREEN, touch.clear());
uint16_t line = 1;
menu_line(line++);
tft_string.set(pstr, itemIndex, itemString);
tft_string.set(FTOP(fstr), itemIndex, FTOP(itemString));
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
@ -416,7 +416,7 @@ void TFT::draw_edit_screen_buttons() {
}
// The Select Screen presents a prompt and two "buttons"
void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, const bool yesno, FSTR_P const pref, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/) {
uint16_t line = 1;
if (!string) line++;
@ -621,7 +621,7 @@ static void drawCurESelection() {
tft.add_text(tft_string.width(), 0, E_BTN_COLOR, ui8tostr3rj(motionAxisState.e_selection));
}
static void drawMessage(const char *msg) {
static void drawMessage(PGM_P const msg) {
tft.canvas(X_MARGIN, TFT_HEIGHT - Y_MARGIN - 29, (TFT_WIDTH / 2) - (BTN_WIDTH / 2) - X_MARGIN, 20);
tft.set_background(COLOR_BACKGROUND);
tft.add_text(0, 0, COLOR_YELLOW, msg);
@ -652,7 +652,7 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
#if ENABLED(PREVENT_COLD_EXTRUSION)
if (axis == E_AXIS && thermalManager.tooColdToExtrude(motionAxisState.e_selection)) {
drawMessage("Too cold");
drawMessage(PSTR("Too cold"));
return;
}
#endif
@ -675,7 +675,7 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
probe.offset.z = new_offs;
else
TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP);
drawMessage(""); // clear the error
drawMessage(NUL_STR); // clear the error
drawAxisValue(axis);
}
else {
@ -693,7 +693,7 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
}
else {
drawMessage(""); // clear the error
drawMessage(NUL_STR); // clear the error
}
drawAxisValue(axis);
#endif

View File

@ -352,14 +352,14 @@ void MarlinUI::draw_status_screen() {
}
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const value/*=nullptr*/) {
void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char * const value/*=nullptr*/) {
ui.encoder_direction_normal();
TERN_(TOUCH_SCREEN, touch.clear());
uint16_t line = 1;
menu_line(line++);
tft_string.set(pstr, itemIndex, itemString);
tft_string.set(FTOP(fstr), itemIndex, FTOP(itemString));
tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
@ -421,7 +421,7 @@ void TFT::draw_edit_screen_buttons() {
}
// The Select Screen presents a prompt and two "buttons"
void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, const bool yesno, FSTR_P const pref, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/) {
uint16_t line = 1;
if (!string) line++;
@ -622,7 +622,7 @@ static void drawCurESelection() {
tft.add_text(tft_string.width(), 0, E_BTN_COLOR, ui8tostr3rj(motionAxisState.e_selection));
}
static void drawMessage(const char *msg) {
static void drawMessage(PGM_P const msg) {
tft.canvas(X_MARGIN, TFT_HEIGHT - Y_MARGIN - 34, TFT_HEIGHT / 2, 34);
tft.set_background(COLOR_BACKGROUND);
tft.add_text(0, 0, COLOR_YELLOW, msg);
@ -653,7 +653,7 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
#if ENABLED(PREVENT_COLD_EXTRUSION)
if (axis == E_AXIS && thermalManager.tooColdToExtrude(motionAxisState.e_selection)) {
drawMessage("Too cold");
drawMessage(PSTR("Too cold"));
return;
}
#endif
@ -676,7 +676,7 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
probe.offset.z = new_offs;
else
TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP);
drawMessage(""); // clear the error
drawMessage(NUL_STR); // clear the error
drawAxisValue(axis);
}
else {
@ -694,7 +694,7 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
drawMessage(GET_TEXT(MSG_LCD_SOFT_ENDSTOPS));
}
else {
drawMessage(""); // clear the error
drawMessage(NUL_STR); // clear the error
}
drawAxisValue(axis);
#endif

View File

@ -130,10 +130,10 @@ void lcd_put_int(const int i) {
//
// Draw a generic menu item with pre_char (if selected) and post_char
void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char pre_char, const char post_char) {
menu_item(row, sel);
uint8_t *string = (uint8_t *)pstr;
uint8_t *string = (uint8_t *)FTOP(fstr);
MarlinImage image = noImage;
switch (*string) {
case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH
@ -147,15 +147,15 @@ void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, co
tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
}
tft_string.set(string, itemIndex, itemString);
tft_string.set(string, itemIndex, FTOP(itemString));
tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
}
// Draw a menu item with a (potentially) editable value
void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char * const data, const bool pgm) {
void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char * const data, const bool pgm) {
menu_item(row, sel);
tft_string.set(pstr, itemIndex, itemString);
tft_string.set(FTOP(fstr), itemIndex, FTOP(itemString));
tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
if (data) {
tft_string.set(data);
@ -164,16 +164,16 @@ void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr,
}
// Draw a static item with no left-right margin required. Centered by default.
void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
menu_item(row);
tft_string.set(pstr, itemIndex, itemString);
tft_string.set(FTOP(fstr), itemIndex, FTOP(itemString));
if (vstr) tft_string.add(vstr);
tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string);
}
#if ENABLED(SDSUPPORT)
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
menu_item(row, sel);
if (isDir) tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
constexpr uint8_t maxlen = (MENU_ITEM_HEIGHT) - (MENU_TEXT_Y_OFFSET) + 1;