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

@ -566,7 +566,7 @@ FORCE_INLINE void _draw_bed_status(const bool blink) {
#if HAS_PRINT_PROGRESS
FORCE_INLINE void _draw_print_progress() {
const uint8_t progress = ui.get_progress();
const uint8_t progress = ui.get_progress_percent();
lcd_put_u8str_P(PSTR(
#if ENABLED(SDSUPPORT)
"SD"
@ -613,7 +613,7 @@ void MarlinUI::draw_status_message(const bool blink) {
// Draw the progress bar if the message has shown long enough
// or if there is no message set.
if (ELAPSED(millis(), progress_bar_ms + PROGRESS_BAR_MSG_TIME) || !has_status()) {
const uint8_t progress = get_progress();
const uint8_t progress = get_progress_percent();
if (progress > 2) return draw_progress_bar(progress);
}

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);

View File

@ -796,7 +796,7 @@ namespace ExtUI {
#endif
uint8_t getProgress_percent() {
return ui.get_progress();
return ui.get_progress_percent();
}
uint32_t getProgress_seconds_elapsed() {

View File

@ -45,7 +45,7 @@ bool printer_busy();
struct MenuEditItemInfo_##NAME { \
typedef TYPE type_t; \
static constexpr float scale = SCALE; \
static inline char* strfunc(const float value) { return STRFUNC((TYPE) value); } \
static inline const char* strfunc(const float value) { return STRFUNC((TYPE) value); } \
};
DECLARE_MENU_EDIT_TYPE(uint8_t, percent, ui8tostr4pct, 100.0/255); // 100% right-justified
@ -204,7 +204,7 @@ class MenuEditItemBase {
static screenFunc_t callbackFunc;
static bool liveEdit;
protected:
typedef char* (*strfunc_t)(const int32_t);
typedef const char* (*strfunc_t)(const int32_t);
typedef void (*loadfunc_t)(void *, const int32_t);
static void init(PGM_P const el, void * const ev, const int32_t minv, const int32_t maxv, const uint16_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le);
static void edit(strfunc_t, loadfunc_t);
@ -217,7 +217,7 @@ class TMenuEditItem : MenuEditItemBase {
static inline float unscale(const float value) { return value * (1.0f / NAME::scale); }
static inline float scale(const float value) { return value * NAME::scale; }
static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); }
static char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
static const char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
public:
static void action(
PGM_P const pstr, // Edit label

View File

@ -58,7 +58,7 @@
#endif
#if ENABLED(LCD_SET_PROGRESS_MANUALLY)
uint8_t MarlinUI::progress_override; // = 0
MarlinUI::progress_t MarlinUI::progress_override; // = 0
#endif
#if HAS_BUZZER
@ -515,7 +515,7 @@ void MarlinUI::status_screen() {
if (expire_status_ms > 0) {
// Expire the message if a job is active and the bar has ticks
if (get_progress() > 2 && !print_job_timer.isPaused()) {
if (get_progress_percent() > 2 && !print_job_timer.isPaused()) {
if (ELAPSED(ms, expire_status_ms)) {
status_message[0] = '\0';
expire_status_ms = 0;
@ -1534,18 +1534,24 @@ void MarlinUI::update() {
}
#if HAS_PRINT_PROGRESS
uint8_t MarlinUI::get_progress() {
MarlinUI::progress_t MarlinUI::_get_progress() {
#if ENABLED(LCD_SET_PROGRESS_MANUALLY)
const uint8_t p = progress_override & 0x7F;
const progress_t p = progress_override & PROGRESS_MASK;
#else
constexpr uint8_t p = 0;
constexpr progress_t p = 0;
#endif
return (p
#if ENABLED(SDSUPPORT)
?: card.percentDone()
#if HAS_PRINT_PROGRESS_PERMYRIAD
?: card.permyriadDone()
#else
?: card.percentDone()
#endif
#endif
);
}
#endif
#endif // HAS_DISPLAY

View File

@ -288,15 +288,28 @@ public:
static void resume_print();
#if HAS_PRINT_PROGRESS
#if ENABLED(LCD_SET_PROGRESS_MANUALLY)
static uint8_t progress_override;
static void set_progress(const uint8_t progress) { progress_override = _MIN(progress, 100); }
static void set_progress_done() { set_progress(0x80 + 100); }
static void progress_reset() { if (progress_override & 0x80) set_progress(0); }
#if HAS_PRINT_PROGRESS_PERMYRIAD
typedef uint16_t progress_t;
#define PROGRESS_SCALE 100U
#define PROGRESS_MASK 0x7FFF
#else
typedef uint8_t progress_t;
#define PROGRESS_SCALE 1U
#define PROGRESS_MASK 0x7F
#endif
static uint8_t get_progress();
#if ENABLED(LCD_SET_PROGRESS_MANUALLY)
static progress_t progress_override;
static void set_progress(const progress_t p) { progress_override = _MIN(p, 100U * (PROGRESS_SCALE)); }
static void set_progress_done() { progress_override = (PROGRESS_MASK + 1U) + 100U * (PROGRESS_SCALE); }
static void progress_reset() { if (progress_override & (PROGRESS_MASK + 1U)) set_progress(0); }
#endif
static progress_t _get_progress();
#if HAS_PRINT_PROGRESS_PERMYRIAD
static uint16_t get_progress_permyriad() { return _get_progress(); }
#endif
static uint8_t get_progress_percent() { return uint8_t(_get_progress() / (PROGRESS_SCALE)); }
#else
static constexpr uint8_t get_progress() { return 0; }
static constexpr uint8_t get_progress_percent() { return 0; }
#endif
#if HAS_SPI_LCD