Skip to content

Commit

Permalink
Remaining Time for Prusa-style LCD layout (MarlinFirmware#20148)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
2 people authored and W4tel-BiDi committed Apr 5, 2021
1 parent aa02aad commit 48d4f68
Showing 1 changed file with 38 additions and 34 deletions.
72 changes: 38 additions & 34 deletions Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,35 @@ void MarlinUI::draw_status_message(const bool blink) {
* |01234567890123456789|
*/

inline uint8_t draw_elapsed_or_remaining_time(uint8_t timepos) {
char buffer[14];

#if ENABLED(SHOW_REMAINING_TIME)
const bool show_remain = TERN1(ROTATE_PROGRESS_DISPLAY, blink) && (printingIsActive() || marlin_state == MF_SD_COMPLETE);
if (show_remain) {
#if ENABLED(USE_M73_REMAINING_TIME)
duration_t remaining = get_remaining_time();
#else
uint8_t progress = get_progress_percent();
uint32_t elapsed = print_job_timer.duration();
duration_t remaining = (progress > 0) ? ((elapsed * 25600 / progress) >> 8) - elapsed : 0;
#endif
timepos -= remaining.toDigital(buffer);
lcd_put_wchar(timepos, 2, 'R');
}
#else
constexpr bool show_remain = false;
#endif

if (!show_remain) {
duration_t elapsed = print_job_timer.duration();
timepos -= elapsed.toDigital(buffer);
lcd_put_wchar(timepos, 2, LCD_STR_CLOCK[0]);
}
lcd_put_u8str(buffer);
return timepos;
}

void MarlinUI::draw_status_screen() {

const bool blink = get_blink();
Expand Down Expand Up @@ -845,33 +874,7 @@ void MarlinUI::draw_status_screen() {
lcd_put_u8str(i16tostr3rj(feedrate_percentage));
lcd_put_wchar('%');

char buffer[14];
uint8_t timepos = 0;
#if ENABLED(SHOW_REMAINING_TIME)
const bool show_remain = TERN1(ROTATE_PROGRESS_DISPLAY, blink) && (printingIsActive() || marlin_state == MF_SD_COMPLETE);
if (show_remain) {
#if ENABLED(USE_M73_REMAINING_TIME)
duration_t remaining = get_remaining_time();
#else
uint8_t progress = get_progress_percent();
uint32_t elapsed = print_job_timer.duration();
duration_t remaining = (progress > 0) ? ((elapsed * 25600 / progress) >> 8) - elapsed : 0;
#endif
const uint8_t len = remaining.toDigital(buffer);
timepos = LCD_WIDTH - 1 - len;
lcd_put_wchar(timepos, 2, 'R');
}
#else
constexpr bool show_remain = false;
#endif

if (!show_remain) {
duration_t elapsed = print_job_timer.duration();
const uint8_t len = elapsed.toDigital(buffer);
timepos = LCD_WIDTH - 1 - len;
lcd_put_wchar(timepos, 2, LCD_STR_CLOCK[0]);
}
lcd_put_u8str(buffer);
const uint8_t timepos = draw_elapsed_or_remaining_time(LCD_WIDTH - 1);

#if LCD_WIDTH >= 20
lcd_moveto(timepos - 7, 2);
Expand Down Expand Up @@ -955,22 +958,23 @@ void MarlinUI::draw_status_screen() {
#elif HAS_MULTI_HOTEND && HAS_HEATED_BED
_draw_bed_status(blink);
#elif HAS_PRINT_PROGRESS
#define DREW_PRINT_PROGRESS
#define DREW_PRINT_PROGRESS 1
_draw_print_progress();
#endif

//
// Elapsed Time or SD Percent
//
lcd_moveto(LCD_WIDTH - 9, 2);
#if HAS_PRINT_PROGRESS && !defined(DREW_PRINT_PROGRESS)

#if HAS_PRINT_PROGRESS && !DREW_PRINT_PROGRESS

_draw_print_progress();

#else
duration_t elapsed = print_job_timer.duration();
char buffer[14];
(void)elapsed.toDigital(buffer);
lcd_put_wchar(LCD_STR_CLOCK[0]);
lcd_put_u8str(buffer);

(void)draw_elapsed_or_remaining_time(LCD_WIDTH - 4);

#endif

#endif // LCD_INFO_SCREEN_STYLE 1
Expand Down

0 comments on commit 48d4f68

Please sign in to comment.