Skip to content

Commit 225f7b5

Browse files
committed
🚸 MarlinUI Endstop Test Screen
1 parent c8cb618 commit 225f7b5

File tree

16 files changed

+394
-189
lines changed

16 files changed

+394
-189
lines changed

Marlin/Configuration_adv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,9 @@
15121512
// Insert a menu for preheating at the top level to allow for quick access
15131513
//#define PREHEAT_SHORTCUT_MENU_ITEM
15141514

1515+
// Add Configuration > Debug Menu > Endstop Test for endstop/probe/runout testing
1516+
//#define LCD_ENDSTOP_TEST
1517+
15151518
#endif // HAS_MARLINUI_MENU
15161519

15171520
#if HAS_DISPLAY

Marlin/src/inc/SanityCheck.h

Lines changed: 54 additions & 54 deletions
Large diffs are not rendered by default.

Marlin/src/lcd/HD44780/marlinui_HD44780.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,17 +1137,38 @@ void MarlinUI::draw_status_screen() {
11371137
#endif // ADVANCED_PAUSE_FEATURE
11381138

11391139
// Draw a static item with no left-right margin required. Centered by default.
1140-
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
1141-
int8_t n = LCD_WIDTH;
1140+
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) {
11421141
lcd_moveto(0, row);
1142+
1143+
int8_t n = LCD_WIDTH;
1144+
const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
11431145
const int8_t plen = fstr ? utf8_strlen(fstr) : 0,
11441146
vlen = vstr ? utf8_strlen(vstr) : 0;
1145-
if (style & SS_CENTER) {
1146-
int8_t pad = (LCD_WIDTH - plen - vlen) / 2;
1147-
while (--pad >= 0) { lcd_put_u8str(F(" ")); n--; }
1147+
int8_t pad = (center || full) ? n - plen - vlen : 0;
1148+
1149+
// SS_CENTER: Pad with half of the unused space first
1150+
if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd_put_u8str(F(" ")); n--; }
1151+
1152+
// Draw as much of the label as fits
1153+
if (plen) {
1154+
const int8_t expl = n;
1155+
n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
1156+
pad -= (expl - n - plen); // Reduce the padding
11481157
}
1149-
if (plen) n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
1150-
if (vlen) n -= lcd_put_u8str_max(vstr, n);
1158+
1159+
if (vlen && n > 0) {
1160+
// SS_FULL: Pad with enough space to justify the value
1161+
if (full && !center) {
1162+
// Move the leading colon from the value to the label
1163+
if (*vstr == ':') { n -= lcd_put_u8str(F(":")); vstr++; }
1164+
// Move spaces to the padding
1165+
while (*vstr == ' ') { vstr++; pad++; }
1166+
// Pad in-between
1167+
for (; pad > 0; --pad) { lcd_put_u8str(F(" ")); n--; }
1168+
}
1169+
n -= lcd_put_u8str_max(vstr, n);
1170+
}
1171+
11511172
for (; n > 0; --n) lcd_put_u8str(F(" "));
11521173
}
11531174

Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -962,17 +962,41 @@ void MarlinUI::draw_status_screen() {
962962
#endif
963963

964964
// Draw a static item with no left-right margin required. Centered by default.
965-
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char * const valstr/*=nullptr*/) {
965+
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) {
966966
if (!PanelDetected) return;
967-
uint8_t n = LCD_WIDTH;
968967
lcd_moveto(0, row);
969-
if ((style & SS_CENTER) && !valstr) {
970-
int8_t pad = (LCD_WIDTH - utf8_strlen(fstr)) / 2;
971-
while (--pad >= 0) { lcd.write(' '); n--; }
968+
969+
uint8_t n = LCD_WIDTH;
970+
const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
971+
const int8_t plen = fstr ? utf8_strlen(fstr) : 0,
972+
vlen = vstr ? utf8_strlen(vstr) : 0;
973+
int8_t pad = (center || full) ? n - plen - vlen : 0;
974+
975+
// SS_CENTER: Pad with half of the unused space first
976+
if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd.write(' '); n--; }
977+
978+
// Draw as much of the label as fits
979+
if (plen) {
980+
const int8_t expl = n;
981+
n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
982+
pad -= (expl - n - plen); // Reduce the padding
972983
}
973-
n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
974-
if (valstr) n -= lcd_put_u8str_max(valstr, n);
975-
for (; n; --n) lcd.write(' ');
984+
985+
if (vlen && n > 0) {
986+
// SS_FULL: Pad with enough space to justify the value
987+
if (full && !center) {
988+
// Move the leading colon from the value to the label
989+
if (*vstr == ':') { lcd.write(':'); vstr++; n--; }
990+
// Move spaces to the padding
991+
while (*vstr == ' ') { vstr++; pad++; }
992+
// Pad in-between
993+
for (; pad > 0; --pad) { lcd.write(' '); n--; }
994+
}
995+
n -= lcd_put_u8str_max(vstr, n);
996+
}
997+
998+
for (; n > 0; --n) lcd.write(' ');
999+
9761000
lcd.print_line();
9771001
}
9781002

Marlin/src/lcd/dogm/marlinui_DOGM.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,38 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
411411
}
412412

413413
// Draw a static line of text in the same idiom as a menu item
414-
void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
414+
void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) {
415415

416416
if (mark_as_selected(row, style & SS_INVERT)) {
417417
pixel_len_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed
418418

419-
const int plen = ftpl ? calculateWidth(ftpl) : 0,
419+
const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
420+
const int pwide = ftpl ? calculateWidth(ftpl) : 0,
420421
vlen = vstr ? utf8_strlen(vstr) : 0;
421-
if (style & SS_CENTER) {
422-
int pad = (LCD_PIXEL_WIDTH - plen - vlen * MENU_FONT_WIDTH) / MENU_FONT_WIDTH / 2;
423-
while (--pad >= 0) n -= lcd_put_u8str(F(" "));
422+
int pad = (center || full) ? ((LCD_PIXEL_WIDTH) - pwide - vlen * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH) : 0;
423+
424+
// SS_CENTER: Pad with half of the unused space first
425+
if (center) for (int lpad = pad / 2; lpad > 0; --lpad) n -= lcd_put_u8str(F(" "));
426+
427+
// Draw as much of the label as fits
428+
if (pwide) {
429+
const pixel_len_t expw = n;
430+
n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
431+
pad -= (expw - n - pwide) / (MENU_FONT_WIDTH); // Reduce the padding
424432
}
425433

426-
if (plen) n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
427-
if (vlen) n -= lcd_put_u8str_max(vstr, n);
434+
if (vlen) {
435+
// SS_FULL: Pad with enough space to justify the value
436+
if (full && !center && n > MENU_FONT_WIDTH) {
437+
// Move the leading colon from the value to the label
438+
if (*vstr == ':') { n -= lcd_put_u8str(F(":")); vstr++; }
439+
// Move spaces to the padding
440+
while (*vstr == ' ') { vstr++; pad++; }
441+
// Pad in-between
442+
for (; pad > 0; --pad) n -= lcd_put_u8str(F(" "));
443+
}
444+
n -= lcd_put_u8str_max(vstr, n);
445+
}
428446
while (n > MENU_FONT_WIDTH) n -= lcd_put_u8str(F(" "));
429447
}
430448
}

Marlin/src/lcd/e3v2/marlinui/ui_common.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void MarlinUI::draw_status_message(const bool blink) {
311311

312312
// Draw a static line of text in the same idiom as a menu item
313313

314-
void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
314+
void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) {
315315
// Call mark_as_selected to draw a bigger selection box
316316
// and draw the text without a background
317317
if (mark_as_selected(row, (bool)(style & SS_INVERT), true)) {
@@ -320,20 +320,38 @@ void MarlinUI::draw_status_message(const bool blink) {
320320
dwin_font.fg = Color_White;
321321

322322
dwin_string.set();
323+
324+
const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
323325
const int8_t plen = ftpl ? utf8_strlen(ftpl) : 0,
324326
vlen = vstr ? utf8_strlen(vstr) : 0;
325-
if (style & SS_CENTER) {
326-
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
327-
while (--pad) dwin_string.add(' ');
327+
int8_t pad = (center || full) ? (LCD_WIDTH) - 1 - plen - vlen : 0;
328+
329+
// SS_CENTER: Pad with half of the unused space first
330+
if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) dwin_string.add(' ');
331+
332+
// Append the templated label string
333+
if (plen) {
334+
dwin_string.add(ftpl, itemIndex, itemStringC, itemStringF);
335+
pad -= dwin_string.length - plen;
328336
}
329337

330-
if (plen) dwin_string.add(ftpl, itemIndex, itemStringC, itemStringF);
331-
if (vlen) dwin_string.add(vstr);
332-
if (style & SS_CENTER) {
333-
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
334-
while (--pad) dwin_string.add(' ');
338+
// SS_FULL: Pad with enough space to justify the value
339+
if (vlen) {
340+
if (full && !center) {
341+
// Move the leading colon from the value to the label
342+
if (*vstr == ':') { dwin_string.add(':'); vstr++; }
343+
// Move spaces to the padding
344+
while (*vstr == ' ') { vstr++; pad++; }
345+
// Pad in-between
346+
for (; pad > 0; --pad) dwin_string.add(' ');
347+
}
348+
// Append the value
349+
dwin_string.add(vstr);
335350
}
336351

352+
// SS_CENTER: Pad the rest of the string
353+
if (center) for (int8_t rpad = pad - (pad / 2); rpad > 0; --rpad) dwin_string.add(' ');
354+
337355
lcd_moveto(1, row);
338356
lcd_put_dwin_string();
339357
}

Marlin/src/lcd/e3v2/proui/endstop_diag.cpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,26 @@ void draw_es_state(const bool is_hit) {
6666
}
6767

6868
void ESDiagClass::Draw() {
69-
Title.ShowCaption(F("End-stops Diagnostic"));
69+
Title.ShowCaption(GET_TEXT_F(MSG_ENDSTOP_TEST));
7070
DWINUI::ClearMainArea();
7171
Draw_Popup_Bkgd();
7272
DWINUI::Draw_Button(BTN_Continue, 86, 250);
7373
DWINUI::cursor.y = 80;
7474
#define ES_LABEL(S) draw_es_label(F(STR_##S))
75-
#if HAS_X_MIN
76-
ES_LABEL(X_MIN);
77-
#endif
78-
#if HAS_Y_MIN
79-
ES_LABEL(Y_MIN);
80-
#endif
81-
#if HAS_Z_MIN
82-
ES_LABEL(Z_MIN);
83-
#endif
84-
#if HAS_FILAMENT_SENSOR
85-
draw_es_label(F(STR_FILAMENT));
86-
#endif
75+
TERN_(HAS_X_MIN, ES_LABEL(X_MIN)); TERN_(HAS_X_MAX, ES_LABEL(X_MAX));
76+
TERN_(HAS_Y_MIN, ES_LABEL(Y_MIN)); TERN_(HAS_Y_MAX, ES_LABEL(Y_MAX));
77+
TERN_(HAS_Z_MIN, ES_LABEL(Z_MIN)); TERN_(HAS_Z_MAX, ES_LABEL(Z_MAX));
78+
TERN_(HAS_FILAMENT_SENSOR, draw_es_label(F(STR_FILAMENT)));
8779
Update();
8880
}
8981

9082
void ESDiagClass::Update() {
9183
DWINUI::cursor.y = 80;
9284
#define ES_REPORT(S) draw_es_state(READ(S##_PIN) == S##_ENDSTOP_HIT_STATE)
93-
#if HAS_X_MIN
94-
ES_REPORT(X_MIN);
95-
#endif
96-
#if HAS_Y_MIN
97-
ES_REPORT(Y_MIN);
98-
#endif
99-
#if HAS_Z_MIN
100-
ES_REPORT(Z_MIN);
101-
#endif
102-
#if HAS_FILAMENT_SENSOR
103-
draw_es_state(READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE);
104-
#endif
85+
TERN_(HAS_X_MIN, ES_REPORT(X_MIN)); TERN_(HAS_X_MAX, ES_REPORT(X_MAX));
86+
TERN_(HAS_Y_MIN, ES_REPORT(Y_MIN)); TERN_(HAS_Y_MAX, ES_REPORT(Y_MAX));
87+
TERN_(HAS_Z_MIN, ES_REPORT(Z_MIN)); TERN_(HAS_Z_MAX, ES_REPORT(Z_MAX));
88+
TERN_(HAS_FILAMENT_SENSOR, draw_es_state(READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE));
10589
DWIN_UpdateLCD();
10690
}
10791

Marlin/src/lcd/language/language_en.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ namespace Language_en {
7676
LSTR MSG_DISABLE_STEPPERS = _UxGT("Disable Steppers");
7777
LSTR MSG_DEBUG_MENU = _UxGT("Debug Menu");
7878
LSTR MSG_PROGRESS_BAR_TEST = _UxGT("Progress Bar Test");
79+
LSTR MSG_ENDSTOP_TEST = _UxGT("Endstop Test");
80+
LSTR MSG_Z_PROBE = _UxGT("Z Probe");
7981
LSTR MSG_HOMING = _UxGT("Homing");
8082
LSTR MSG_AUTO_HOME = _UxGT("Auto Home");
8183
LSTR MSG_AUTO_HOME_A = _UxGT("Home @");
@@ -430,6 +432,7 @@ namespace Language_en {
430432
LSTR MSG_TEMPERATURE = _UxGT("Temperature");
431433
LSTR MSG_MOTION = _UxGT("Motion");
432434
LSTR MSG_FILAMENT = _UxGT("Filament");
435+
LSTR MSG_FILAMENT_EN = _UxGT("Filament *");
433436
LSTR MSG_VOLUMETRIC_ENABLED = _UxGT("E in mm") SUPERSCRIPT_THREE;
434437
LSTR MSG_VOLUMETRIC_LIMIT = _UxGT("E Limit in mm") SUPERSCRIPT_THREE;
435438
LSTR MSG_VOLUMETRIC_LIMIT_E = _UxGT("E Limit *");

Marlin/src/lcd/menu/menu.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ typedef void (*selectFunc_t)();
3535

3636
#define SS_LEFT 0x00
3737
#define SS_CENTER 0x01
38-
#define SS_INVERT 0x02
38+
#define SS_FULL 0x02
39+
#define SS_INVERT 0x04
3940
#define SS_DEFAULT SS_CENTER
4041

4142
#if ENABLED(BABYSTEP_ZPROBE_OFFSET) && Z_PROBE_OFFSET_RANGE_MIN >= -9 && Z_PROBE_OFFSET_RANGE_MAX <= 9
@@ -75,7 +76,7 @@ class MenuItemBase {
7576
// STATIC_ITEM(LABEL,...)
7677
class MenuItem_static : public MenuItemBase {
7778
public:
78-
static void draw(const uint8_t row, FSTR_P const fstr, const uint8_t style=SS_DEFAULT, const char * const vstr=nullptr);
79+
static void draw(const uint8_t row, FSTR_P const fstr, const uint8_t style=SS_DEFAULT, const char *vstr=nullptr);
7980
};
8081

8182
// BACK_ITEM(LABEL)

0 commit comments

Comments
 (0)