|
91 | 91 | #define EXTRAS_BASELINE (40 + INFO_FONT_ASCENT)
|
92 | 92 | #define STATUS_BASELINE (LCD_PIXEL_HEIGHT - INFO_FONT_DESCENT)
|
93 | 93 |
|
| 94 | +#define PCENTERED // Center percent value over progress bar, else right-align |
| 95 | +#define PROGRESS_BAR_X TERN(PCENTERED, 54, 40) |
| 96 | +#define PROGRESS_BAR_Y (EXTRAS_BASELINE + TERN(PCENTERED, 1, -3)) |
| 97 | +#define PCT_X TERN(PCENTERED, PROGRESS_BAR_X, LCD_PIXEL_WIDTH - TERN(PRINT_PROGRESS_SHOW_DECIMALS, 5, 4) * INFO_FONT_WIDTH) |
| 98 | +#define PCT_Y (EXTRAS_BASELINE + TERN(PCENTERED, 0, 3)) |
| 99 | +#define PROGRESS_BAR_WIDTH TERN(PCENTERED, LCD_PIXEL_WIDTH - PROGRESS_BAR_X, PCT_X - PROGRESS_BAR_X - 1) |
| 100 | +#define PROGRESS_BAR_HEIGHT TERN(PCENTERED, 4, 5) |
| 101 | + |
| 102 | +#if DISABLED(PCENTERED) && HAS_TIME_DISPLAY |
| 103 | + #error "PCENTERED is required for extra progress display options." |
| 104 | +#endif |
| 105 | + |
94 | 106 | #if ANIM_HBCC
|
95 | 107 | enum HeatBits : uint8_t {
|
96 | 108 | DRAWBIT_HOTEND,
|
|
188 | 200 | }
|
189 | 201 | #endif
|
190 | 202 |
|
191 |
| -#define PROGRESS_BAR_X 54 |
192 |
| -#define PROGRESS_BAR_Y (EXTRAS_BASELINE + 1) |
193 |
| -#define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X) |
194 |
| - |
195 | 203 | FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, const uint8_t ty) {
|
196 | 204 | const char *str;
|
197 | 205 | uint8_t len;
|
@@ -471,46 +479,44 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
|
471 | 479 | // Prepare strings for progress display
|
472 | 480 | #if ANY(HAS_EXTRA_PROGRESS, HAS_PRINT_PROGRESS)
|
473 | 481 | static MarlinUI::progress_t progress = 0;
|
474 |
| - static char bufferc[13]; |
| 482 | + static MString<12> progressString; |
475 | 483 | #endif
|
476 | 484 |
|
477 | 485 | #if HAS_EXTRA_PROGRESS
|
478 | 486 |
|
479 |
| - static void prepare_time_string(const duration_t &time, char prefix) { |
480 |
| - char str[13]; |
481 |
| - memset(&bufferc[2], 0x20, 5); // partialy fill with spaces to avoid artifacts and terminator |
482 |
| - bufferc[0] = prefix; |
483 |
| - bufferc[1] = ':'; |
484 |
| - int str_length = time.toDigital(str, time.value >= 60*60*24L); |
485 |
| - strcpy(&bufferc[sizeof(bufferc) - str_length - 1], str); |
486 |
| - } |
487 |
| - |
| 487 | + #if HAS_TIME_DISPLAY |
| 488 | + static void prepare_time_string(const duration_t &time, char prefix) { |
| 489 | + char str[10]; |
| 490 | + const uint8_t time_len = time.toDigital(str, time.value >= 60*60*24L); // 5 to 8 chars |
| 491 | + progressString.set(prefix, ':', spaces_t(10 - time_len), str); // 2 to 5 spaces |
| 492 | + } |
| 493 | + #endif |
488 | 494 | #if ENABLED(SHOW_PROGRESS_PERCENT)
|
489 | 495 | void MarlinUI::drawPercent() {
|
490 |
| - if (progress != 0) { |
491 |
| - #define PCENTERED 1 // center percent value over progress bar, else align to the right |
492 |
| - #define PPOS TERN(PCENTERED, 4, 0) |
493 |
| - #define PLEN TERN(PRINT_PROGRESS_SHOW_DECIMALS, 4, 3) |
494 |
| - memset(&bufferc, 0x20, 12); |
495 |
| - memcpy(&bufferc[PPOS], TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))), PLEN); |
496 |
| - bufferc[PPOS+PLEN] = '%'; |
497 |
| - } |
| 496 | + if (progress == 0) return; |
| 497 | + progressString.set( |
| 498 | + OPTITEM(PCENTERED, spaces_t(4)) |
| 499 | + TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))), '%' |
| 500 | + ); |
498 | 501 | }
|
499 | 502 | #endif
|
500 | 503 | #if ENABLED(SHOW_REMAINING_TIME)
|
501 | 504 | void MarlinUI::drawRemain() {
|
502 | 505 | if (printJobOngoing() && get_remaining_time() != 0)
|
503 |
| - prepare_time_string(get_remaining_time(), 'R'); } |
| 506 | + prepare_time_string(get_remaining_time(), 'R'); |
| 507 | + } |
504 | 508 | #endif
|
505 | 509 | #if ENABLED(SHOW_INTERACTION_TIME)
|
506 | 510 | void MarlinUI::drawInter() {
|
507 | 511 | if (printingIsActive() && interaction_time)
|
508 |
| - prepare_time_string(interaction_time, 'C'); } |
| 512 | + prepare_time_string(interaction_time, 'C'); |
| 513 | + } |
509 | 514 | #endif
|
510 | 515 | #if ENABLED(SHOW_ELAPSED_TIME)
|
511 | 516 | void MarlinUI::drawElapsed() {
|
512 | 517 | if (printJobOngoing())
|
513 |
| - prepare_time_string(print_job_timer.duration(), 'E'); } |
| 518 | + prepare_time_string(print_job_timer.duration(), 'E'); |
| 519 | + } |
514 | 520 | #endif
|
515 | 521 |
|
516 | 522 | #endif // HAS_EXTRA_PROGRESS
|
@@ -779,17 +785,17 @@ void MarlinUI::draw_status_screen() {
|
779 | 785 |
|
780 | 786 | #if HAS_PRINT_PROGRESS
|
781 | 787 | // Progress bar frame
|
782 |
| - if (PAGE_CONTAINS(PROGRESS_BAR_Y, PROGRESS_BAR_Y + 3)) |
783 |
| - u8g.drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4); |
| 788 | + if (PAGE_CONTAINS(PROGRESS_BAR_Y, PROGRESS_BAR_Y + PROGRESS_BAR_HEIGHT - 1)) |
| 789 | + u8g.drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, PROGRESS_BAR_HEIGHT); |
784 | 790 |
|
785 | 791 | // Progress bar solid part
|
786 |
| - if (PAGE_CONTAINS(PROGRESS_BAR_Y + 1, PROGRESS_BAR_Y + 2)) |
787 |
| - u8g.drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2); |
| 792 | + if (PAGE_CONTAINS(PROGRESS_BAR_Y + 1, PROGRESS_BAR_Y + PROGRESS_BAR_HEIGHT - 3)) |
| 793 | + u8g.drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, PROGRESS_BAR_HEIGHT - 2); |
788 | 794 |
|
789 | 795 | // Progress strings
|
790 |
| - if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) { |
| 796 | + if (PAGE_CONTAINS(PCT_Y - INFO_FONT_ASCENT, PCT_Y - 1)) { |
791 | 797 | ui.rotate_progress();
|
792 |
| - lcd_put_u8str(PROGRESS_BAR_X, EXTRAS_BASELINE, bufferc); |
| 798 | + lcd_put_u8str(PCT_X, PCT_Y, progressString); |
793 | 799 | }
|
794 | 800 | #endif
|
795 | 801 |
|
|
0 commit comments