Estimate Remaining Time (graphical display) (#15497)

This commit is contained in:
LinFor
2019-10-11 05:03:33 +03:00
committed by Scott Lahteine
parent 5641adb01b
commit b20d5a7cc6
118 changed files with 747 additions and 103 deletions

View File

@ -99,6 +99,9 @@
#define STATUS_HEATERS_BOT (STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1)
#define PROGRESS_BAR_X 54
#define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
#if ENABLED(MARLIN_DEV_MODE)
#define SHOW_ON_STATE READ(X_MIN_PIN)
#else
@ -257,7 +260,7 @@ FORCE_INLINE void _draw_heater_status(const heater_ind_t heater, const bool blin
FORCE_INLINE void _draw_chamber_status(const bool blink) {
#if ENABLED(MARLIN_DEV_MODE)
const float temp = 10 + (millis() >> 8) % CHAMBER_MAXTEMP,
const float temp = 10 + (millis() >> 8) % CHAMBER_MAXTEMP,
target = CHAMBER_MAXTEMP;
#else
const float temp = thermalManager.degChamber();
@ -330,6 +333,26 @@ void MarlinUI::draw_status_screen() {
static char wstring[5], mstring[4];
#endif
#if HAS_PRINT_PROGRESS
#if DISABLED(DOGM_SD_PERCENT)
#define _SD_DURATION_X(len) (PROGRESS_BAR_X + (PROGRESS_BAR_WIDTH) / 2 - (len) * (MENU_FONT_WIDTH) / 2)
#else
#define _SD_DURATION_X(len) (LCD_PIXEL_WIDTH - (len) * (MENU_FONT_WIDTH))
#endif
static uint8_t progress_bar_solid_width = 0, lastProgress = 0;
#if ENABLED(DOGM_SD_PERCENT)
static char progress_string[5];
#endif
static uint8_t lastElapsed = 0, elapsed_x_pos = 0;
static char elapsed_string[10];
#if ENABLED(SHOW_REMAINING_TIME)
#define SHOW_REMAINING_TIME_PREFIX 'E'
static uint8_t estimation_x_pos = 0;
static char estimation_string[10];
#endif
#endif
// At the first page, generate new display values
if (first_page) {
#if ANIM_HBC
@ -353,6 +376,50 @@ void MarlinUI::draw_status_screen() {
strcpy(wstring, ftostr12ns(filwidth.measured_mm));
strcpy(mstring, i16tostr3(planner.volumetric_percent(parser.volumetric_enabled)));
#endif
// Progress / elapsed / estimation updates and string formatting to avoid float math on each LCD draw
#if HAS_PRINT_PROGRESS
const progress_t progress =
#if HAS_PRINT_PROGRESS_PERMYRIAD
get_progress_permyriad()
#else
get_progress_percent()
#endif
;
duration_t elapsed = print_job_timer.duration();
const uint8_t p = progress & 0xFF, ev = elapsed.value & 0xFF;
if (progress > 1 && p != lastProgress) {
lastProgress = p;
progress_bar_solid_width = uint8_t((PROGRESS_BAR_WIDTH - 2) * progress / (PROGRESS_SCALE) * 0.01f);
#if ENABLED(DOGM_SD_PERCENT)
strcpy(progress_string, (
#if ENABLED(PRINT_PROGRESS_SHOW_DECIMALS)
permyriadtostr4(progress)
#else
ui8tostr3(progress / (PROGRESS_SCALE))
#endif
));
#endif
}
if (ev != lastElapsed) {
lastElapsed = ev;
const bool has_days = (elapsed.value >= 60*60*24L);
const uint8_t len = elapsed.toDigital(elapsed_string, has_days);
elapsed_x_pos = _SD_DURATION_X(len);
#if ENABLED(SHOW_REMAINING_TIME)
if (!(ev & 0x3)) {
duration_t estimation = elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress;
const bool has_days = (estimation.value >= 60*60*24L);
const uint8_t len = estimation.toDigital(estimation_string, has_days);
estimation_x_pos = _SD_DURATION_X(len + 1);
}
#endif
}
#endif
}
const bool blink = get_blink();
@ -485,55 +552,44 @@ void MarlinUI::draw_status_screen() {
//
// Progress bar frame
//
#define PROGRESS_BAR_X 54
#define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
if (PAGE_CONTAINS(49, 52))
u8g.drawFrame(PROGRESS_BAR_X, 49, PROGRESS_BAR_WIDTH, 4);
const uint8_t progress = get_progress();
//
// Progress bar solid part
//
if (progress > 1) {
if (PAGE_CONTAINS(50, 51)) // 50-51 (or just 50)
u8g.drawBox(PROGRESS_BAR_X + 1, 50, progress_bar_solid_width, 2);
//
// Progress bar solid part
//
//
// SD Percent Complete
//
if (PAGE_CONTAINS(50, 51)) // 50-51 (or just 50)
u8g.drawBox(
PROGRESS_BAR_X + 1, 50,
(uint16_t)((PROGRESS_BAR_WIDTH - 2) * progress * 0.01), 2
);
//
// SD Percent Complete
//
#if ENABLED(DOGM_SD_PERCENT)
#if ENABLED(DOGM_SD_PERCENT)
if (progress_string[0] != '\0')
if (PAGE_CONTAINS(41, 48)) {
// Percent complete
lcd_put_u8str(55, 48, ui8tostr3(progress));
lcd_put_u8str(55, 48, progress_string);
lcd_put_wchar('%');
}
#endif
}
#endif
//
// Elapsed Time
//
#if DISABLED(DOGM_SD_PERCENT)
#define SD_DURATION_X (PROGRESS_BAR_X + (PROGRESS_BAR_WIDTH / 2) - len * (MENU_FONT_WIDTH / 2))
#else
#define SD_DURATION_X (LCD_PIXEL_WIDTH - len * MENU_FONT_WIDTH)
#endif
if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) {
char buffer[13];
duration_t elapsed = print_job_timer.duration();
bool has_days = (elapsed.value >= 60*60*24L);
uint8_t len = elapsed.toDigital(buffer, has_days);
lcd_put_u8str(SD_DURATION_X, EXTRAS_BASELINE, buffer);
#if ENABLED(SHOW_REMAINING_TIME)
if (blink && (estimation_string[0] != '\0')) {
lcd_put_wchar(estimation_x_pos, EXTRAS_BASELINE, SHOW_REMAINING_TIME_PREFIX);
lcd_put_u8str(estimation_string);
}
else
#endif
lcd_put_u8str(elapsed_x_pos, EXTRAS_BASELINE, elapsed_string);
}
#endif // HAS_PRINT_PROGRESS

View File

@ -850,7 +850,7 @@ void ST7920_Lite_Status_Screen::update_progress(const bool forceUpdate) {
// when an update is actually necessary.
static uint8_t last_progress = 0;
const uint8_t progress = ui.get_progress();
const uint8_t progress = ui.get_progress_percent();
if (forceUpdate || last_progress != progress) {
last_progress = progress;
draw_progress_bar(progress);