Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progress display followup #24879

Merged
merged 22 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1434,24 +1434,26 @@

#endif // HAS_DISPLAY || DWIN_LCD_PROUI

// Add the G-code 'M73' to set / report the current job progress
// Add 'M73' to set print job progress, overriding Marlin's built-in estimate
//#define SET_PROGRESS_MANUALLY
#if ENABLED(SET_PROGRESS_MANUALLY)
//#define SET_PROGRESS_PERCENT // Add 'P' parameter to set percentage done, otherwise use Marlin's estimate
//#define SET_REMAINING_TIME // Add 'R' parameter to set remaining time, otherwise use Marlin's estimate
#define SET_PROGRESS_PERCENT // Add 'P' parameter to set percentage done
//#define SET_REMAINING_TIME // Add 'R' parameter to set remaining time
//#define SET_INTERACTION_TIME // Add 'C' parameter to set time until next filament change or other user interaction
#if ENABLED(SET_INTERACTION_TIME)
#define SHOW_INTERACTION_TIME // Display time until next user interaction ('C' = filament change)
//#define M73_REPORT // Report M73 values to host
#if BOTH(M73_REPORT, SDDUPPORT)
#define M73_REPORT_SD_ONLY // Report only when printing from SD
#endif
//#define M73_REPORT // Report progress to host with 'M73'
#endif

// LCD Print Progress options, multiple can be rotated depending on screen layout
// LCD Print Progress options. Multiple times may be displayed in turn.
#if HAS_DISPLAY && EITHER(SDSUPPORT, SET_PROGRESS_MANUALLY)
#define SHOW_PROGRESS_PERCENT // Show print progress percentage (doesn't affect progress bar)
#define SHOW_ELAPSED_TIME // Display elapsed printing time (prefix 'E')
//#define SHOW_REMAINING_TIME // Display estimated time to completion (prefix 'R')

#if ENABLED(SET_INTERACTION_TIME)
#define SHOW_INTERACTION_TIME // Display time until next user interaction ('C' = filament change)
#endif
//#define PRINT_PROGRESS_SHOW_DECIMALS // Show/report progress with decimal digits, not all UIs support this

#if EITHER(HAS_MARLINUI_HD44780, IS_TFTGLCD_PANEL)
Expand Down
26 changes: 13 additions & 13 deletions Marlin/src/gcode/lcd/M73.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ void GcodeSuite::M73() {
#endif

#if ENABLED(M73_REPORT)
{
SERIAL_ECHO_MSG(
TERN(M73_REPORT_PRUSA, "M73 Percent done: ", "Progress: ")
, TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui.get_progress_percent())
#if ENABLED(SET_REMAINING_TIME)
, TERN(M73_REPORT_PRUSA, "; Print time remaining in mins: ", "%; Time left: "), ui.remaining_time / 60
#endif
#if ENABLED(SET_INTERACTION_TIME)
, TERN(M73_REPORT_PRUSA, "; Change in mins: ", "m; Change: "), ui.interaction_time / 60
#endif
, TERN(M73_REPORT_PRUSA, ";", "m")
);
}
if (TERN1(M73_REPORT_SD_ONLY, IS_SD_PRINTING)) {
SERIAL_ECHO_MSG(
TERN(M73_REPORT_PRUSA, "M73 Percent done: ", "Progress: ")
, TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui.get_progress_percent())
#if ENABLED(SET_REMAINING_TIME)
, TERN(M73_REPORT_PRUSA, "; Print time remaining in mins: ", "%; Time left: "), ui.remaining_time / 60
#endif
#if ENABLED(SET_INTERACTION_TIME)
, TERN(M73_REPORT_PRUSA, "; Change in mins: ", "m; Change: "), ui.interaction_time / 60
#endif
, TERN(M73_REPORT_PRUSA, ";", "m")
);
}
#endif
}

Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ void MarlinUI::draw_status_message(const bool blink) {
#if HAS_PRINT_PROGRESS
#define TPOFFSET (LCD_WIDTH - 1)
static uint8_t timepos = TPOFFSET - 6;
static char buffer[14];
static char buffer[8];
static lcd_uint_t pc, pr;

#if ENABLED(SHOW_PROGRESS_PERCENT)
Expand Down Expand Up @@ -863,7 +863,7 @@ void MarlinUI::draw_status_screen() {
#if LCD_WIDTH < 20

#if HAS_PRINT_PROGRESS
pc = 0, pr = 2;
pc = 0; pr = 2;
rotate_progress();
#endif

Expand Down Expand Up @@ -950,14 +950,14 @@ void MarlinUI::draw_status_screen() {
#if LCD_WIDTH >= 20

#if HAS_PRINT_PROGRESS
pc = timepos - 7, pr = 2;
pc = 6; pr = 2;
rotate_progress();
#else
char c;
uint16_t per;
#if HAS_FAN0
if (true
#if EXTRUDERS && ENABLED(ADAPTIVE_FAN_SLOWING)
#if BOTH(HAS_EXTRUDERS, ADAPTIVE_FAN_SLOWING)
&& (blink || thermalManager.fan_speed_scaler[0] < 128)
#endif
) {
Expand Down Expand Up @@ -1031,15 +1031,15 @@ void MarlinUI::draw_status_screen() {
_draw_bed_status(blink);
#elif HAS_PRINT_PROGRESS
#define DREW_PRINT_PROGRESS 1
pc = 0, pr = 2;
pc = 0; pr = 2;
rotate_progress();
#endif

//
// All progress strings
//
#if HAS_PRINT_PROGRESS && !DREW_PRINT_PROGRESS
pc = LCD_WIDTH - 9, pr = 2;
pc = LCD_WIDTH - 9; pr = 2;
rotate_progress();
#endif
#endif // LCD_INFO_SCREEN_STYLE 1
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@ void MarlinUI::draw_status_screen() {
_draw_print_progress();
#endif

// TODO!

char buffer[10];
duration_t elapsed = print_job_timer.duration();
uint8_t len = elapsed.toDigital(buffer);
Expand Down
98 changes: 32 additions & 66 deletions Marlin/src/lcd/dogm/status_screen_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,46 +447,53 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
#if HAS_PRINT_PROGRESS
#define _PRGR_INFO_X(len) (LCD_PIXEL_WIDTH - (len) * (MENU_FONT_WIDTH))
#define PCENTERED 1 // center percent value over progress bar, else align to the right
static uint8_t lastProgress = 0xFF;
static u8g_uint_t progress_bar_solid_width = 0;

static MarlinUI::progress_t progress = 0;

#if ENABLED(SHOW_PROGRESS_PERCENT)
static char progress_string[5];
static u8g_uint_t progress_x_pos;
void MarlinUI::drawPercent() {
if (progress_string[0]) {
lcd_put_u8str(progress_x_pos, EXTRAS_BASELINE, progress_string);
if (progress != 0) {
char bufferc[13];
strcpy(bufferc, TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
const u8g_uint_t strxpos = TERN(PCENTERED, 77, _PRGR_INFO_X(strlen(bufferc) + 1));
lcd_put_u8str(strxpos, EXTRAS_BASELINE, bufferc);
lcd_put_lchar('%');
}
}
#endif
#if ENABLED(SHOW_REMAINING_TIME)
static char remaining_string[10];
static u8g_uint_t remaining_x_pos = 0;
void MarlinUI::drawRemain() {
if (printJobOngoing()){
if (printJobOngoing()) {
const duration_t buffert = ui.get_remaining_time();
char bufferc[13];
const uint8_t len = buffert.toDigital(bufferc, buffert.value >= 60*60*24L);
const u8g_uint_t strxpos = _PRGR_INFO_X(len);
lcd_put_u8str(PROGRESS_BAR_X, EXTRAS_BASELINE, F("R:"));
lcd_put_u8str(remaining_x_pos, EXTRAS_BASELINE, remaining_string);
lcd_put_u8str(strxpos, EXTRAS_BASELINE, bufferc);
}
}
#endif
#if ENABLED(SHOW_INTERACTION_TIME)
static char interaction_string[10];
static u8g_uint_t interaction_x_pos = 0;
void MarlinUI::drawInter() {
if (printingIsActive() && interaction_string[0]) {
if (printingIsActive() && interaction_time) {
const duration_t buffert = interaction_time;
char bufferc[13];
const uint8_t len = buffert.toDigital(bufferc, buffert.value >= 60*60*24L);
const u8g_uint_t strxpos = _PRGR_INFO_X(len);
lcd_put_u8str(PROGRESS_BAR_X, EXTRAS_BASELINE, F("C:"));
lcd_put_u8str(interaction_x_pos, EXTRAS_BASELINE, interaction_string);
lcd_put_u8str(strxpos, EXTRAS_BASELINE, bufferc);
}
}
#endif
#if ENABLED(SHOW_ELAPSED_TIME)
static char elapsed_string[10];
static u8g_uint_t elapsed_x_pos = 0;
static uint8_t lastElapsed;
void MarlinUI::drawElapsed() {
if (printJobOngoing()) {
const duration_t buffert = print_job_timer.duration();
char bufferc[13];
const uint8_t len = buffert.toDigital(bufferc, buffert.value >= 60*60*24L);
const u8g_uint_t strxpos = _PRGR_INFO_X(len);
lcd_put_u8str(PROGRESS_BAR_X, EXTRAS_BASELINE, F("E:"));
lcd_put_u8str(elapsed_x_pos, EXTRAS_BASELINE, elapsed_string);
lcd_put_u8str(strxpos, EXTRAS_BASELINE, bufferc);
}
}
#endif
Expand All @@ -508,6 +515,8 @@ void MarlinUI::draw_status_screen() {

const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive());

static u8g_uint_t progress_bar_solid_width = 0;

// At the first page, generate new display values
if (first_page) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that with the regular DOGM display there are several calls per update to redraw the screen. This first_page flag indicates that we're drawing the first "stripe" in the screen update. Any expensive calculations or string composition is done here so that they only happen once per screen update. To optimize the actual draw operations, we use if (...) { ... } with PAGE_OVER, PAGE_UNDER, and PAGE_CONTAINS to check whether the thing we're drawing is within the current stripe, and if not then drawing is skipped.

#if ANIM_HBCC
Expand Down Expand Up @@ -543,59 +552,16 @@ void MarlinUI::draw_status_screen() {
strcpy(mstring, i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled)));
#endif

// Progress / elapsed / estimation updates and string formatting to avoid float math on each LCD draw
// Progress update to avoid float math on each LCD draw
#if HAS_PRINT_PROGRESS
const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
duration_t elapsedt = print_job_timer.duration();
const uint8_t p = progress & 0xFF, ev = elapsedt.value & 0xFF;
progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();

static uint8_t lastProgress = 0xFF;
const uint8_t p = progress & 0xFF;
if (p != lastProgress) {
lastProgress = p;

progress_bar_solid_width = u8g_uint_t((PROGRESS_BAR_WIDTH - 2) * (progress / (PROGRESS_SCALE)) * 0.01f);

#if ENABLED(SHOW_PROGRESS_PERCENT)
if (progress == 0)
progress_string[0] = '\0';
else
strcpy(progress_string, TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
progress_x_pos = TERN(PCENTERED, 77, _PRGR_INFO_X(strlen(progress_string) + 1));
#endif
}

#if ENABLED(SHOW_INTERACTION_TIME)
if (!(interaction_time)) {
interaction_string[0] = '\0';
interaction_x_pos = _PRGR_INFO_X(0);
}
else {
const duration_t interactt = ui.interaction_time;
interactt.toDigital(interaction_string, interactt.value >= 60*60*24L);
interaction_x_pos = _PRGR_INFO_X(strlen(interaction_string));
}
#endif

#if ENABLED(SHOW_ELAPSED_TIME)
if (ev != lastElapsed) {
lastElapsed = ev;
const uint8_t len = elapsedt.toDigital(elapsed_string, elapsedt.value >= 60*60*24L);
elapsed_x_pos = _PRGR_INFO_X(len);
}
#endif

#if ENABLED(SHOW_REMAINING_TIME)
if (!(ev & 0x3)) {
uint32_t timeval = get_remaining_time();
if (!timeval) {
remaining_string[0] = '\0';
remaining_x_pos = _PRGR_INFO_X(0);
}
else {
const duration_t remaint = timeval;
const uint8_t len = remaint.toDigital(remaining_string, remaint.value >= 60*60*24L);
remaining_x_pos = _PRGR_INFO_X(len);
}
}
#endif
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ void MarlinUI::draw_status_screen() {
);
}

// TODO!

//
// Elapsed time
//
Expand Down
6 changes: 0 additions & 6 deletions Marlin/src/libs/numtostr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ const char* i8tostr3rj(const int8_t x) {
conv[6] = DIGIMOD(xx, 10);
return &conv[3];
}
else if (xx % 100 == 0) {
conv[4] = ' ';
conv[5] = RJDIGIT(xx, 1000);
conv[6] = DIGIMOD(xx, 100);
return &conv[4];
}
else {
conv[3] = DIGIMOD(xx, 100);
conv[4] = '.';
Expand Down