Skip to content

Commit

Permalink
🚸 MarlinUI Endstop Test Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Apr 13, 2023
1 parent c8cb618 commit c4ec723
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 128 deletions.
3 changes: 3 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,9 @@
// Insert a menu for preheating at the top level to allow for quick access
//#define PREHEAT_SHORTCUT_MENU_ITEM

// Add Configuration > Debug Menu > Endstop Test for endstop/probe/runout testing
//#define LCD_ENDSTOP_TEST

#endif // HAS_MARLINUI_MENU

#if HAS_DISPLAY
Expand Down
35 changes: 28 additions & 7 deletions Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,17 +1137,38 @@ void MarlinUI::draw_status_screen() {
#endif // ADVANCED_PAUSE_FEATURE

// Draw a static item with no left-right margin required. Centered by default.
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
int8_t n = LCD_WIDTH;
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) {
lcd_moveto(0, row);

int8_t n = LCD_WIDTH;
const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
const int8_t plen = fstr ? utf8_strlen(fstr) : 0,
vlen = vstr ? utf8_strlen(vstr) : 0;
if (style & SS_CENTER) {
int8_t pad = (LCD_WIDTH - plen - vlen) / 2;
while (--pad >= 0) { lcd_put_u8str(F(" ")); n--; }
int8_t pad = (center || full) ? n - plen - vlen : 0;

// SS_CENTER: Pad with half of the unused space first
if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd_put_u8str(F(" ")); n--; }

// Draw as much of the label as fits
if (plen) {
const int8_t expl = n;
n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
pad -= (expl - n - plen); // Reduce the padding
}
if (plen) n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
if (vlen) n -= lcd_put_u8str_max(vstr, n);

if (vlen && n > 0) {
// SS_FULL: Pad with enough space to justify the value
if (full && !center) {
// Move the leading colon from the value to the label
if (*vstr == ':') { n -= lcd_put_u8str(F(":")); vstr++; }
// Move spaces to the padding
while (*vstr == ' ') { vstr++; pad++; }
// Pad in-between
for (; pad > 0; --pad) { lcd_put_u8str(F(" ")); n--; }
}
n -= lcd_put_u8str_max(vstr, n);
}

for (; n > 0; --n) lcd_put_u8str(F(" "));
}

Expand Down
40 changes: 32 additions & 8 deletions Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,17 +962,41 @@ void MarlinUI::draw_status_screen() {
#endif

// Draw a static item with no left-right margin required. Centered by default.
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char * const valstr/*=nullptr*/) {
void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) {
if (!PanelDetected) return;
uint8_t n = LCD_WIDTH;
lcd_moveto(0, row);
if ((style & SS_CENTER) && !valstr) {
int8_t pad = (LCD_WIDTH - utf8_strlen(fstr)) / 2;
while (--pad >= 0) { lcd.write(' '); n--; }

uint8_t n = LCD_WIDTH;
const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
const int8_t plen = fstr ? utf8_strlen(fstr) : 0,
vlen = vstr ? utf8_strlen(vstr) : 0;
int8_t pad = (center || full) ? n - plen - vlen : 0;

// SS_CENTER: Pad with half of the unused space first
if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) { lcd.write(' '); n--; }

// Draw as much of the label as fits
if (plen) {
const int8_t expl = n;
n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
pad -= (expl - n - plen); // Reduce the padding
}
n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
if (valstr) n -= lcd_put_u8str_max(valstr, n);
for (; n; --n) lcd.write(' ');

if (vlen && n > 0) {
// SS_FULL: Pad with enough space to justify the value
if (full && !center) {
// Move the leading colon from the value to the label
if (*vstr == ':') { lcd.write(':'); vstr++; n--; }
// Move spaces to the padding
while (*vstr == ' ') { vstr++; pad++; }
// Pad in-between
for (; pad > 0; --pad) { lcd.write(' '); n--; }
}
n -= lcd_put_u8str_max(vstr, n);
}

for (; n > 0; --n) lcd.write(' ');

lcd.print_line();
}

Expand Down
32 changes: 25 additions & 7 deletions Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,38 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
}

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

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

const int plen = ftpl ? calculateWidth(ftpl) : 0,
const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
const int pwide = ftpl ? calculateWidth(ftpl) : 0,
vlen = vstr ? utf8_strlen(vstr) : 0;
if (style & SS_CENTER) {
int pad = (LCD_PIXEL_WIDTH - plen - vlen * MENU_FONT_WIDTH) / MENU_FONT_WIDTH / 2;
while (--pad >= 0) n -= lcd_put_u8str(F(" "));
int pad = (center || full) ? ((LCD_PIXEL_WIDTH) - pwide - vlen * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH) : 0;

// SS_CENTER: Pad with half of the unused space first
if (center) for (int lpad = pad / 2; lpad > 0; --lpad) n -= lcd_put_u8str(F(" "));

// Draw as much of the label as fits
if (pwide) {
const pixel_len_t expw = n;
n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
pad -= (expw - n - pwide) / (MENU_FONT_WIDTH); // Reduce the padding
}

if (plen) n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
if (vlen) n -= lcd_put_u8str_max(vstr, n);
if (vlen) {
// SS_FULL: Pad with enough space to justify the value
if (full && !center && n > MENU_FONT_WIDTH) {
// Move the leading colon from the value to the label
if (*vstr == ':') { n -= lcd_put_u8str(F(":")); vstr++; }
// Move spaces to the padding
while (*vstr == ' ') { vstr++; pad++; }
// Pad in-between
for (; pad > 0; --pad) n -= lcd_put_u8str(F(" "));
}
n -= lcd_put_u8str_max(vstr, n);
}
while (n > MENU_FONT_WIDTH) n -= lcd_put_u8str(F(" "));
}
}
Expand Down
36 changes: 27 additions & 9 deletions Marlin/src/lcd/e3v2/marlinui/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void MarlinUI::draw_status_message(const bool blink) {

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

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

dwin_string.set();

const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
const int8_t plen = ftpl ? utf8_strlen(ftpl) : 0,
vlen = vstr ? utf8_strlen(vstr) : 0;
if (style & SS_CENTER) {
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
while (--pad) dwin_string.add(' ');
int8_t pad = (center || full) ? (LCD_WIDTH) - 1 - plen - vlen : 0;

// SS_CENTER: Pad with half of the unused space first
if (center) for (int8_t lpad = pad / 2; lpad > 0; --lpad) dwin_string.add(' ');

// Append the templated label string
if (plen) {
dwin_string.add(ftpl, itemIndex, itemStringC, itemStringF);
pad -= dwin_string.length - plen;
}

if (plen) dwin_string.add(ftpl, itemIndex, itemStringC, itemStringF);
if (vlen) dwin_string.add(vstr);
if (style & SS_CENTER) {
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
while (--pad) dwin_string.add(' ');
// SS_FULL: Pad with enough space to justify the value
if (vlen) {
if (full && !center) {
// Move the leading colon from the value to the label
if (*vstr == ':') { dwin_string.add(':'); vstr++; }
// Move spaces to the padding
while (*vstr == ' ') { vstr++; pad++; }
// Pad in-between
for (; pad > 0; --pad) dwin_string.add(' ');
}
// Append the value
dwin_string.add(vstr);
}

// SS_CENTER: Pad the rest of the string
if (center) for (int8_t rpad = pad - (pad / 2); rpad > 0; --rpad) dwin_string.add(' ');

lcd_moveto(1, row);
lcd_put_dwin_string();
}
Expand Down
34 changes: 9 additions & 25 deletions Marlin/src/lcd/e3v2/proui/endstop_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,42 +66,26 @@ void draw_es_state(const bool is_hit) {
}

void ESDiagClass::Draw() {
Title.ShowCaption(F("End-stops Diagnostic"));
Title.ShowCaption(GET_TEXT_F(MSG_ENDSTOP_TEST));
DWINUI::ClearMainArea();
Draw_Popup_Bkgd();
DWINUI::Draw_Button(BTN_Continue, 86, 250);
DWINUI::cursor.y = 80;
#define ES_LABEL(S) draw_es_label(F(STR_##S))
#if HAS_X_MIN
ES_LABEL(X_MIN);
#endif
#if HAS_Y_MIN
ES_LABEL(Y_MIN);
#endif
#if HAS_Z_MIN
ES_LABEL(Z_MIN);
#endif
#if HAS_FILAMENT_SENSOR
draw_es_label(F(STR_FILAMENT));
#endif
TERN_(HAS_X_MIN, ES_LABEL(X_MIN)); TERN_(HAS_X_MAX, ES_LABEL(X_MAX));
TERN_(HAS_Y_MIN, ES_LABEL(Y_MIN)); TERN_(HAS_Y_MAX, ES_LABEL(Y_MAX));
TERN_(HAS_Z_MIN, ES_LABEL(Z_MIN)); TERN_(HAS_Z_MAX, ES_LABEL(Z_MAX));
TERN_(HAS_FILAMENT_SENSOR, draw_es_label(F(STR_FILAMENT)));
Update();
}

void ESDiagClass::Update() {
DWINUI::cursor.y = 80;
#define ES_REPORT(S) draw_es_state(READ(S##_PIN) == S##_ENDSTOP_HIT_STATE)
#if HAS_X_MIN
ES_REPORT(X_MIN);
#endif
#if HAS_Y_MIN
ES_REPORT(Y_MIN);
#endif
#if HAS_Z_MIN
ES_REPORT(Z_MIN);
#endif
#if HAS_FILAMENT_SENSOR
draw_es_state(READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE);
#endif
TERN_(HAS_X_MIN, ES_REPORT(X_MIN)); TERN_(HAS_X_MAX, ES_REPORT(X_MAX));
TERN_(HAS_Y_MIN, ES_REPORT(Y_MIN)); TERN_(HAS_Y_MAX, ES_REPORT(Y_MAX));
TERN_(HAS_Z_MIN, ES_REPORT(Z_MIN)); TERN_(HAS_Z_MAX, ES_REPORT(Z_MAX));
TERN_(HAS_FILAMENT_SENSOR, draw_es_state(READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE));
DWIN_UpdateLCD();
}

Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ namespace Language_en {
LSTR MSG_DISABLE_STEPPERS = _UxGT("Disable Steppers");
LSTR MSG_DEBUG_MENU = _UxGT("Debug Menu");
LSTR MSG_PROGRESS_BAR_TEST = _UxGT("Progress Bar Test");
LSTR MSG_ENDSTOP_TEST = _UxGT("Endstop Test");
LSTR MSG_Z_PROBE = _UxGT("Z Probe");
LSTR MSG_HOMING = _UxGT("Homing");
LSTR MSG_AUTO_HOME = _UxGT("Auto Home");
LSTR MSG_AUTO_HOME_A = _UxGT("Home @");
Expand Down Expand Up @@ -430,6 +432,7 @@ namespace Language_en {
LSTR MSG_TEMPERATURE = _UxGT("Temperature");
LSTR MSG_MOTION = _UxGT("Motion");
LSTR MSG_FILAMENT = _UxGT("Filament");
LSTR MSG_FILAMENT_EN = _UxGT("Filament *");
LSTR MSG_VOLUMETRIC_ENABLED = _UxGT("E in mm") SUPERSCRIPT_THREE;
LSTR MSG_VOLUMETRIC_LIMIT = _UxGT("E Limit in mm") SUPERSCRIPT_THREE;
LSTR MSG_VOLUMETRIC_LIMIT_E = _UxGT("E Limit *");
Expand Down
5 changes: 3 additions & 2 deletions Marlin/src/lcd/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ typedef void (*selectFunc_t)();

#define SS_LEFT 0x00
#define SS_CENTER 0x01
#define SS_INVERT 0x02
#define SS_FULL 0x02
#define SS_INVERT 0x04
#define SS_DEFAULT SS_CENTER

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

// BACK_ITEM(LABEL)
Expand Down
Loading

0 comments on commit c4ec723

Please sign in to comment.