Skip to content

Commit

Permalink
Add print at position shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 23, 2019
1 parent 5c0e5c5 commit 7924e0d
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 134 deletions.
89 changes: 31 additions & 58 deletions Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp
Expand Up @@ -401,9 +401,7 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
void lcd_scroll(const lcd_uint_t col, const lcd_uint_t line, PGM_P const text, const uint8_t len, const int16_t time) {
uint8_t slen = utf8_strlen_P(text);
if (slen < len) {
// Fits into,
lcd_moveto(col, line);
lcd_put_u8str_max_P(text, len);
lcd_put_u8str_max_P(col, line, text, len);
for (; slen < len; ++slen) lcd_put_wchar(' ');
safe_delay(time);
}
Expand All @@ -412,11 +410,8 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
int dly = time / _MAX(slen, 1);
for (uint8_t i = 0; i <= slen; i++) {

// Go to the correct place
lcd_moveto(col, line);

// Print the text
lcd_put_u8str_max_P(p, len);
// Print the text at the correct place
lcd_put_u8str_max_P(col, line, p, len);

// Fill with spaces
for (uint8_t ix = slen - i; ix < len; ++ix) lcd_put_wchar(' ');
Expand All @@ -433,9 +428,9 @@ void MarlinUI::clear_lcd() { lcd.clear(); }

static void logo_lines(PGM_P const extra) {
int16_t indent = (LCD_WIDTH - 8 - utf8_strlen_P(extra)) / 2;
lcd_moveto(indent, 0); lcd_put_wchar('\x00'); lcd_put_u8str_P(PSTR( "------" )); lcd_put_wchar('\x01');
lcd_moveto(indent, 1); lcd_put_u8str_P(PSTR("|Marlin|")); lcd_put_u8str_P(extra);
lcd_moveto(indent, 2); lcd_put_wchar('\x02'); lcd_put_u8str_P(PSTR( "------" )); lcd_put_wchar('\x03');
lcd_put_wchar(indent, 0, '\x00'); lcd_put_u8str_P(PSTR( "------" )); lcd_put_wchar('\x01');
lcd_put_u8str_P(indent, 1, PSTR("|Marlin|")); lcd_put_u8str_P(extra);
lcd_put_wchar(indent, 2, '\x02'); lcd_put_u8str_P(PSTR( "------" )); lcd_put_wchar('\x03');
}

void MarlinUI::show_bootscreen() {
Expand All @@ -447,8 +442,7 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
#define CENTER_OR_SCROLL(STRING,DELAY) \
lcd_erase_line(3); \
if (utf8_strlen(STRING) <= LCD_WIDTH) { \
lcd_moveto((LCD_WIDTH - utf8_strlen_P(PSTR(STRING))) / 2, 3); \
lcd_put_u8str_P(PSTR(STRING)); \
lcd_put_u8str_P((LCD_WIDTH - utf8_strlen_P(PSTR(STRING))) / 2, 3, PSTR(STRING)); \
safe_delay(DELAY); \
} \
else { \
Expand Down Expand Up @@ -518,16 +512,12 @@ void MarlinUI::clear_lcd() { lcd.clear(); }
#endif // SHOW_BOOTSCREEN

void MarlinUI::draw_kill_screen() {
lcd_moveto(0, 0);
lcd_put_u8str(status_message);
#if LCD_HEIGHT < 4
lcd_moveto(0, 2);
#else
lcd_moveto(0, 2);
lcd_put_u8str_P(PSTR(MSG_HALTED));
lcd_moveto(0, 3);
lcd_put_u8str(0, 0, status_message);
lcd_uint_t y = 2;
#if LCD_HEIGHT >= 4
lcd_put_u8str_P(0, y++, PSTR(MSG_HALTED));
#endif
lcd_put_u8str_P(PSTR(MSG_PLEASE_RESET));
lcd_put_u8str_P(0, y, PSTR(MSG_PLEASE_RESET));
}

//
Expand Down Expand Up @@ -886,17 +876,15 @@ void MarlinUI::draw_status_screen() {

#if LCD_HEIGHT > 3

lcd_moveto(0, 2);
lcd_put_wchar(LCD_STR_FEEDRATE[0]);
lcd_put_wchar(0, 2, LCD_STR_FEEDRATE[0]);
lcd_put_u8str(i16tostr3(feedrate_percentage));
lcd_put_wchar('%');

char buffer[14];
duration_t elapsed = print_job_timer.duration();
const uint8_t len = elapsed.toDigital(buffer),
timepos = LCD_WIDTH - len - 1;
lcd_moveto(timepos, 2);
lcd_put_wchar(LCD_STR_CLOCK[0]);
lcd_put_wchar(timepos, 2, LCD_STR_CLOCK[0]);
lcd_put_u8str(buffer);

#if LCD_WIDTH >= 20
Expand Down Expand Up @@ -945,8 +933,7 @@ void MarlinUI::draw_status_screen() {
_draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position[Z_AXIS])), blink);

#if HAS_LEVELING && (HOTENDS > 1 || !HAS_HEATED_BED)
lcd_moveto(LCD_WIDTH - 1, 0);
lcd_put_wchar(planner.leveling_active || blink ? '_' : ' ');
lcd_put_wchar(LCD_WIDTH - 1, 0, planner.leveling_active || blink ? '_' : ' ');
#endif

// ========== Line 2 ==========
Expand All @@ -961,8 +948,7 @@ void MarlinUI::draw_status_screen() {
_draw_bed_status(blink);
#endif

lcd_moveto(LCD_WIDTH - 9, 1);
lcd_put_wchar(LCD_STR_FEEDRATE[0]);
lcd_put_wchar(LCD_WIDTH - 9, 1, LCD_STR_FEEDRATE[0]);
lcd_put_u8str(i16tostr3(feedrate_percentage));
lcd_put_wchar('%');

Expand Down Expand Up @@ -1033,17 +1019,15 @@ void MarlinUI::draw_status_screen() {

void draw_menu_item(const bool sel, const uint8_t row, PGM_P pstr, const char pre_char, const char post_char) {
uint8_t n = LCD_WIDTH - 2;
lcd_moveto(0, row);
lcd_put_wchar(sel ? pre_char : ' ');
lcd_put_wchar(0, row, sel ? pre_char : ' ');
n -= lcd_put_u8str_max_P(pstr, n);
for (; n; --n) lcd_put_wchar(' ');
lcd_put_wchar(post_char);
}

void _draw_menu_item_edit(const bool sel, const uint8_t row, PGM_P pstr, const char* const data, const bool pgm) {
uint8_t n = LCD_WIDTH - 2 - (pgm ? utf8_strlen_P(data) : utf8_strlen(data));
lcd_moveto(0, row);
lcd_put_wchar(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
lcd_put_wchar(0, row, sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
n -= lcd_put_u8str_max_P(pstr, n);
lcd_put_wchar(':');
for (; n; --n) lcd_put_wchar(' ');
Expand All @@ -1053,14 +1037,12 @@ void MarlinUI::draw_status_screen() {
void draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
ui.encoder_direction_normal();

lcd_moveto(0, 1);
lcd_put_u8str_P(pstr);
lcd_put_u8str_P(0, 1, pstr);
if (value != nullptr) {
lcd_put_wchar(':');
int len = utf8_strlen(value);
const lcd_uint_t valrow = (utf8_strlen_P(pstr) + 1 + len + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit
lcd_moveto((LCD_WIDTH - 1) - (len + 1), valrow); // Right-justified, padded by spaces
lcd_put_wchar(' '); // Overwrite char if value gets shorter
lcd_put_wchar((LCD_WIDTH - 1) - (len + 1), valrow, ' '); // Right-justified, padded, add a leading space
lcd_put_u8str(value);
}
}
Expand All @@ -1078,8 +1060,7 @@ void MarlinUI::draw_status_screen() {
void draw_sd_menu_item(const bool sel, const uint8_t row, PGM_P const pstr, CardReader &theCard, const bool isDir) {
UNUSED(pstr);

lcd_moveto(0, row);
lcd_put_wchar(sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
lcd_put_wchar(0, row, sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
constexpr uint8_t maxlen = LCD_WIDTH - 2;
uint8_t n = maxlen - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
for (; n; --n) lcd_put_wchar(' ');
Expand Down Expand Up @@ -1206,8 +1187,7 @@ void MarlinUI::draw_status_screen() {
void prep_and_put_map_char(custom_char &chrdata, const coordinate &ul, const coordinate &lr, const coordinate &brc, const uint8_t cl, const char c, const lcd_uint_t x, const lcd_uint_t y) {
add_edges_to_custom_char(chrdata, ul, lr, brc, cl);
lcd.createChar(c, (uint8_t*)&chrdata);
lcd_moveto(x, y);
lcd_put_wchar(c);
lcd_put_wchar(x, y, c);
}

void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
Expand All @@ -1216,15 +1196,15 @@ void MarlinUI::draw_status_screen() {
#define _LCD_W_POS 12
#define _PLOT_X 1
#define _MAP_X 3
#define _LABEL(C,X,Y) lcd_moveto(X, Y); lcd_put_u8str(C)
#define _LABEL(C,X,Y) lcd_put_u8str(X, Y, C)
#define _XLABEL(X,Y) _LABEL("X:",X,Y)
#define _YLABEL(X,Y) _LABEL("Y:",X,Y)
#define _ZLABEL(X,Y) _LABEL("Z:",X,Y)
#else
#define _LCD_W_POS 8
#define _PLOT_X 0
#define _MAP_X 1
#define _LABEL(X,Y,C) lcd_moveto(X, Y); lcd_put_wchar(C)
#define _LABEL(X,Y,C) lcd_put_wchar(X, Y, C)
#define _XLABEL(X,Y) _LABEL('X',X,Y)
#define _YLABEL(X,Y) _LABEL('Y',X,Y)
#define _ZLABEL(X,Y) _LABEL('Z',X,Y)
Expand Down Expand Up @@ -1288,17 +1268,13 @@ void MarlinUI::draw_status_screen() {
n_cols = right_edge / (HD44780_CHAR_WIDTH) + 1;

for (i = 0; i < n_cols; i++) {
lcd_moveto(i, 0);
lcd_put_wchar(CHAR_LINE_TOP); // Box Top line
lcd_moveto(i, n_rows - 1);
lcd_put_wchar(CHAR_LINE_BOT); // Box Bottom line
lcd_put_wchar(i, 0, CHAR_LINE_TOP); // Box Top line
lcd_put_wchar(i, n_rows - 1, CHAR_LINE_BOT); // Box Bottom line
}

for (j = 0; j < n_rows; j++) {
lcd_moveto(0, j);
lcd_put_wchar(CHAR_EDGE_L); // Box Left edge
lcd_moveto(n_cols - 1, j);
lcd_put_wchar(CHAR_EDGE_R); // Box Right edge
lcd_put_wchar(0, j, CHAR_EDGE_L); // Box Left edge
lcd_put_wchar(n_cols - 1, j, CHAR_EDGE_R); // Box Right edge
}

/**
Expand All @@ -1308,10 +1284,8 @@ void MarlinUI::draw_status_screen() {
k = pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y) + 2;
l = (HD44780_CHAR_HEIGHT) * n_rows;
if (l > k && l - k >= (HD44780_CHAR_HEIGHT) / 2) {
lcd_moveto(0, n_rows - 1); // Box Left edge
lcd_put_wchar(' ');
lcd_moveto(n_cols - 1, n_rows - 1); // Box Right edge
lcd_put_wchar(' ');
lcd_put_wchar(0, n_rows - 1, ' '); // Box Left edge
lcd_put_wchar(n_cols - 1, n_rows - 1, ' '); // Box Right edge
}

clear_custom_char(&new_char);
Expand Down Expand Up @@ -1425,8 +1399,7 @@ void MarlinUI::draw_status_screen() {
/**
* Print plot position
*/
lcd_moveto(_LCD_W_POS, 0);
lcd_put_wchar('(');
lcd_put_wchar(_LCD_W_POS, 0, '(');
lcd_put_u8str(ui8tostr3(x_plot));
lcd_put_wchar(',');
lcd_put_u8str(ui8tostr3(y_plot));
Expand Down
37 changes: 12 additions & 25 deletions Marlin/src/lcd/dogm/status_screen_DOGM.cpp
Expand Up @@ -100,8 +100,7 @@
FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, const uint8_t ty) {
const char *str = i16tostr3(temp);
const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
lcd_moveto(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty);
lcd_put_u8str(&str[3-len]);
lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
lcd_put_wchar(LCD_STR_DEGREE[0]);
}

Expand Down Expand Up @@ -264,8 +263,7 @@ FORCE_INLINE void _draw_heater_status(const heater_ind_t heater, const bool blin
//
FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
const uint8_t offs = (XYZ_SPACING) * axis;
lcd_moveto(X_LABEL_POS + offs, XYZ_BASELINE);
lcd_put_wchar('X' + axis);
lcd_put_wchar(X_LABEL_POS + offs, XYZ_BASELINE, 'X' + axis);
lcd_moveto(X_VALUE_POS + offs, XYZ_BASELINE);
if (blink)
lcd_put_u8str(value);
Expand Down Expand Up @@ -429,8 +427,7 @@ void MarlinUI::draw_status_screen() {
c = '*';
}
#endif
lcd_moveto(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y);
lcd_put_u8str(i16tostr3(thermalManager.fanPercent(spd)));
lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3(thermalManager.fanPercent(spd)));
lcd_put_wchar(c);
}
}
Expand Down Expand Up @@ -488,8 +485,7 @@ void MarlinUI::draw_status_screen() {
#if ENABLED(DOGM_SD_PERCENT)
if (PAGE_CONTAINS(41, 48)) {
// Percent complete
lcd_moveto(55, 48);
lcd_put_u8str(ui8tostr3(progress));
lcd_put_u8str(55, 48, ui8tostr3(progress));
lcd_put_wchar('%');
}
#endif
Expand All @@ -510,8 +506,7 @@ void MarlinUI::draw_status_screen() {
duration_t elapsed = print_job_timer.duration();
bool has_days = (elapsed.value >= 60*60*24L);
uint8_t len = elapsed.toDigital(buffer, has_days);
lcd_moveto(SD_DURATION_X, EXTRAS_BASELINE);
lcd_put_u8str(buffer);
lcd_put_u8str(SD_DURATION_X, EXTRAS_BASELINE, buffer);
}

#endif // HAS_PRINT_PROGRESS
Expand Down Expand Up @@ -546,8 +541,6 @@ void MarlinUI::draw_status_screen() {

// Two-component mix / gradient instead of XY

lcd_moveto(X_LABEL_POS, XYZ_BASELINE);

char mixer_messages[12];
const char *mix_label;
#if ENABLED(GRADIENT_MIX)
Expand All @@ -562,7 +555,7 @@ void MarlinUI::draw_status_screen() {
mix_label = "Mx";
}
sprintf_P(mixer_messages, PSTR("%s %d;%d%% "), mix_label, int(mixer.mix[0]), int(mixer.mix[1]));
lcd_put_u8str(mixer_messages);
lcd_put_u8str(X_LABEL_POS, XYZ_BASELINE, mixer_messages);

#else

Expand All @@ -587,28 +580,22 @@ void MarlinUI::draw_status_screen() {

if (PAGE_CONTAINS(EXTRAS_2_BASELINE - INFO_FONT_ASCENT, EXTRAS_2_BASELINE - 1)) {
set_font(FONT_MENU);
lcd_moveto(3, EXTRAS_2_BASELINE);
lcd_put_wchar(LCD_STR_FEEDRATE[0]);
lcd_put_wchar(3, EXTRAS_2_BASELINE, LCD_STR_FEEDRATE[0]);

set_font(FONT_STATUSMENU);
lcd_moveto(12, EXTRAS_2_BASELINE);
lcd_put_u8str(i16tostr3(feedrate_percentage));
lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3(feedrate_percentage));
lcd_put_wchar('%');

//
// Filament sensor display if SD is disabled
//
#if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
lcd_moveto(56, EXTRAS_2_BASELINE);
lcd_put_u8str(wstring);
lcd_moveto(102, EXTRAS_2_BASELINE);
lcd_put_u8str(mstring);
lcd_put_u8str(56, EXTRAS_2_BASELINE, wstring);
lcd_put_u8str(102, EXTRAS_2_BASELINE, mstring);
lcd_put_wchar('%');
set_font(FONT_MENU);
lcd_moveto(47, EXTRAS_2_BASELINE);
lcd_put_wchar(LCD_STR_FILAM_DIA[0]); // lcd_put_u8str_P(PSTR(LCD_STR_FILAM_DIA));
lcd_moveto(93, EXTRAS_2_BASELINE);
lcd_put_wchar(LCD_STR_FILAM_MUL[0]);
lcd_put_wchar(47, EXTRAS_2_BASELINE, LCD_STR_FILAM_DIA[0]); // lcd_put_u8str_P(PSTR(LCD_STR_FILAM_DIA));
lcd_put_wchar(93, EXTRAS_2_BASELINE, LCD_STR_FILAM_MUL[0]);
#endif
}

Expand Down

0 comments on commit 7924e0d

Please sign in to comment.