Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Extend LCD string substitution (MarlinFirmware#24278)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and tomek2k1 committed Jan 13, 2023
1 parent 51c0ebf commit 9b152e9
Show file tree
Hide file tree
Showing 83 changed files with 1,068 additions and 1,287 deletions.
1 change: 0 additions & 1 deletion Marlin/src/feature/dac/stepper_dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#if HAS_MOTOR_CURRENT_DAC

#include "stepper_dac.h"
#include "../../MarlinCore.h" // for SP_X_LBL...

bool dac_present = false;
constexpr xyze_uint8_t dac_order = DAC_STEPPER_ORDER;
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/HD44780/lcdprint_hd44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ void lcd_put_int(const int i) { lcd.print(i); }

// return < 0 on error
// return the advanced cols
int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
int lcd_put_wchar_max(const wchar_t c, const pixel_len_t max_length) {

// find the HD44780 internal ROM first
int ret;
Expand Down Expand Up @@ -1047,9 +1047,9 @@ int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
*
* Draw a UTF-8 string
*/
static int lcd_put_u8str_max_cb(const char * utf8_str, uint8_t (*cb_read_byte)(uint8_t * str), pixel_len_t max_length) {
static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_byte, const pixel_len_t max_length) {
pixel_len_t ret = 0;
uint8_t *p = (uint8_t *)utf8_str;
const uint8_t *p = (uint8_t *)utf8_str;
while (ret < max_length) {
wchar_t ch = 0;
p = get_utf8_value_cb(p, cb_read_byte, &ch);
Expand All @@ -1059,11 +1059,11 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, uint8_t (*cb_read_byte)(u
return (int)ret;
}

int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
int lcd_put_u8str_max(const char * utf8_str, const pixel_len_t max_length) {
return lcd_put_u8str_max_cb(utf8_str, read_byte_ram, max_length);
}

int lcd_put_u8str_max_P(PGM_P utf8_pstr, pixel_len_t max_length) {
int lcd_put_u8str_max_P(PGM_P utf8_pstr, const pixel_len_t max_length) {
return lcd_put_u8str_max_cb(utf8_pstr, read_byte_rom, max_length);
}

Expand Down
23 changes: 12 additions & 11 deletions Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,13 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
#endif // SHOW_BOOTSCREEN

void MarlinUI::draw_kill_screen() {
lcd_put_u8str(0, 0, status_message);
lcd_uint_t y = 2;
lcd_uint_t x = 0, y = 0;
lcd_put_u8str(x, y, status_message);
y = 2;
#if LCD_HEIGHT >= 4
lcd_put_u8str(0, y++, GET_TEXT_F(MSG_HALTED));
lcd_put_u8str(x, y++, GET_TEXT_F(MSG_HALTED));
#endif
lcd_put_u8str(0, y, GET_TEXT_F(MSG_PLEASE_RESET));
lcd_put_u8str(x, y, GET_TEXT_F(MSG_PLEASE_RESET));
}

//
Expand Down Expand Up @@ -1076,24 +1077,24 @@ void MarlinUI::draw_status_screen() {
int8_t pad = (LCD_WIDTH - plen - vlen) / 2;
while (--pad >= 0) { lcd_put_wchar(' '); n--; }
}
if (plen) n = lcd_put_u8str_ind(fstr, itemIndex, itemString, n);
if (plen) n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
if (vlen) n -= lcd_put_u8str_max(vstr, n);
for (; n > 0; --n) lcd_put_wchar(' ');
}

// Draw a generic menu item with pre_char (if selected) and post_char
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char pre_char, const char post_char) {
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char pre_char, const char post_char) {
lcd_put_wchar(0, row, sel ? pre_char : ' ');
uint8_t n = lcd_put_u8str_ind(fstr, itemIndex, itemString, LCD_WIDTH - 2);
uint8_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2);
for (; n; --n) lcd_put_wchar(' ');
lcd_put_wchar(post_char);
}

// Draw a menu item with a (potentially) editable value
void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const fstr, const char * const inStr, const bool pgm) {
void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) {
const uint8_t vlen = inStr ? (pgm ? utf8_strlen_P(inStr) : utf8_strlen(inStr)) : 0;
lcd_put_wchar(0, row, sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
uint8_t n = lcd_put_u8str_ind(fstr, itemIndex, itemString, LCD_WIDTH - 2 - vlen);
uint8_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2 - vlen);
if (vlen) {
lcd_put_wchar(':');
for (; n; --n) lcd_put_wchar(' ');
Expand All @@ -1102,9 +1103,9 @@ 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(FSTR_P const fstr, const char * const value/*=nullptr*/) {
void MenuEditItemBase::draw_edit_screen(FSTR_P const ftpl, const char * const value/*=nullptr*/) {
ui.encoder_direction_normal();
uint8_t n = lcd_put_u8str_ind(0, 1, fstr, itemIndex, itemString, LCD_WIDTH - 1);
uint8_t n = lcd_put_u8str(0, 1, ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 1);
if (value) {
lcd_put_wchar(':'); n--;
const uint8_t len = utf8_strlen(value) + 1; // Plus one for a leading space
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/TFTGLCD/lcdprint_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ void lcd_put_int(const int i) {

// return < 0 on error
// return the advanced cols
int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
int lcd_put_wchar_max(const wchar_t c, const pixel_len_t max_length) {

// find the HD44780 internal ROM first
int ret;
Expand Down Expand Up @@ -1045,9 +1045,9 @@ int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
*
* Draw a UTF-8 string
*/
static int lcd_put_u8str_max_cb(const char * utf8_str, uint8_t (*cb_read_byte)(uint8_t * str), pixel_len_t max_length) {
static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_byte, const pixel_len_t max_length) {
pixel_len_t ret = 0;
uint8_t *p = (uint8_t *)utf8_str;
const uint8_t *p = (uint8_t *)utf8_str;
while (ret < max_length) {
wchar_t ch = 0;
p = get_utf8_value_cb(p, cb_read_byte, &ch);
Expand All @@ -1057,11 +1057,11 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, uint8_t (*cb_read_byte)(u
return (int)ret;
}

int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
int lcd_put_u8str_max(const char * utf8_str, const pixel_len_t max_length) {
return lcd_put_u8str_max_cb(utf8_str, read_byte_ram, max_length);
}

int lcd_put_u8str_max_P(PGM_P utf8_pstr, pixel_len_t max_length) {
int lcd_put_u8str_max_P(PGM_P utf8_pstr, const pixel_len_t max_length) {
return lcd_put_u8str_max_cb(utf8_pstr, read_byte_rom, max_length);
}

Expand Down
Loading

0 comments on commit 9b152e9

Please sign in to comment.