Browse Source

Merge pull request #5378 from thinkyhead/rc_duration_rj

Better alignment of elapsed print time
Scott Lahteine 8 years ago
parent
commit
818f8b93d3
3 changed files with 39 additions and 23 deletions
  1. 12
    5
      Marlin/duration_t.h
  2. 23
    14
      Marlin/ultralcd_impl_DOGM.h
  3. 4
    4
      Marlin/ultralcd_impl_HD44780.h

+ 12
- 5
Marlin/duration_t.h View File

@@ -145,15 +145,22 @@ struct duration_t {
145 145
    *  99:59
146 146
    *  11d 12:33
147 147
    */
148
-  void toDigital(char *buffer, bool with_days=false) const {
148
+  uint8_t toDigital(char *buffer, bool with_days=false) const {
149 149
     uint16_t h = uint16_t(this->hour()),
150 150
              m = uint16_t(this->minute() % 60UL);
151
-    if (with_days)
152
-      sprintf_P(buffer, PSTR("%ud %02u:%02u"), this->day(), h, m);
153
-    else if (h < 100)
151
+    if (with_days) {
152
+      uint16_t d = this->day();
153
+      sprintf_P(buffer, PSTR("%ud %02u:%02u"), d, h, m);
154
+      return d >= 10 ? 8 : 7;
155
+    }
156
+    else if (h < 100) {
154 157
       sprintf_P(buffer, PSTR("%02u:%02u"), h % 24, m);
155
-    else
158
+      return 5;
159
+    }
160
+    else {
156 161
       sprintf_P(buffer, PSTR("%u:%02u"), h, m);
162
+      return 6;
163
+    }
157 164
   }
158 165
 };
159 166
 

+ 23
- 14
Marlin/ultralcd_impl_DOGM.h View File

@@ -452,8 +452,14 @@ static void lcd_implementation_status_screen() {
452 452
     // Progress bar frame
453 453
     //
454 454
 
455
-    if (PAGE_CONTAINS(49, 52 - (TALL_FONT_CORRECTION)))
456
-      u8g.drawFrame(54, 49, 73, 4 - (TALL_FONT_CORRECTION));  // 49-52 (or 49-51)
455
+    #define PROGRESS_BAR_X 54
456
+    #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
457
+
458
+    if (PAGE_CONTAINS(49, 52 - (TALL_FONT_CORRECTION)))       // 49-52 (or 49-51)
459
+      u8g.drawFrame(
460
+        PROGRESS_BAR_X, 49,
461
+        PROGRESS_BAR_WIDTH, 4 - (TALL_FONT_CORRECTION)
462
+      );
457 463
 
458 464
     if (IS_SD_PRINTING) {
459 465
 
@@ -461,8 +467,11 @@ static void lcd_implementation_status_screen() {
461 467
       // Progress bar solid part
462 468
       //
463 469
 
464
-      if (PAGE_CONTAINS(50, 51 - (TALL_FONT_CORRECTION)))
465
-        u8g.drawBox(55, 50, (unsigned int)(71 * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION));
470
+      if (PAGE_CONTAINS(50, 51 - (TALL_FONT_CORRECTION)))     // 50-51 (or just 50)
471
+        u8g.drawBox(
472
+          PROGRESS_BAR_X + 1, 50,
473
+          (unsigned int)((PROGRESS_BAR_WIDTH - 2) * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION)
474
+        );
466 475
 
467 476
       //
468 477
       // SD Percent Complete
@@ -483,9 +492,9 @@ static void lcd_implementation_status_screen() {
483 492
     //
484 493
 
485 494
     #if DISABLED(DOGM_SD_PERCENT)
486
-      #define SD_DURATION_X 71
495
+      #define SD_DURATION_X (PROGRESS_BAR_X + (PROGRESS_BAR_WIDTH / 2) - len * (DOG_CHAR_WIDTH / 2))
487 496
     #else
488
-      #define SD_DURATION_X 89
497
+      #define SD_DURATION_X (LCD_PIXEL_WIDTH - len * DOG_CHAR_WIDTH)
489 498
     #endif
490 499
 
491 500
     if (PAGE_CONTAINS(41, 48)) {
@@ -493,9 +502,8 @@ static void lcd_implementation_status_screen() {
493 502
       char buffer[10];
494 503
       duration_t elapsed = print_job_timer.duration();
495 504
       bool has_days = (elapsed.value > 60*60*24L);
496
-      elapsed.toDigital(buffer, has_days);
497
-
498
-      u8g.setPrintPos(SD_DURATION_X + (has_days ? 0 : 9), 48);
505
+      uint8_t len = elapsed.toDigital(buffer, has_days);
506
+      u8g.setPrintPos(SD_DURATION_X, 48);
499 507
       lcd_print(buffer);
500 508
     }
501 509
 
@@ -749,11 +757,12 @@ static void lcd_implementation_status_screen() {
749 757
   #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
750 758
 
751 759
   void lcd_implementation_drawedit(const char* const pstr, const char* const value=NULL) {
752
-    const uint8_t labellen = lcd_strlen_P(pstr), vallen = lcd_strlen(value);
753
-    uint8_t lcd_width, char_width,
754
-            rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
760
+    const uint8_t labellen = lcd_strlen_P(pstr),
761
+                  vallen = lcd_strlen(value),
762
+                  rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
755 763
 
756 764
     #if ENABLED(USE_BIG_EDIT_FONT)
765
+      uint8_t lcd_width, char_width;
757 766
       if (labellen <= LCD_WIDTH_EDIT - 1) {
758 767
         if (labellen >= LCD_WIDTH_EDIT - vallen) rows = 2;
759 768
         lcd_width = LCD_WIDTH_EDIT + 1;
@@ -766,8 +775,8 @@ static void lcd_implementation_status_screen() {
766 775
         lcd_setFont(FONT_MENU);
767 776
       }
768 777
     #else
769
-      lcd_width = LCD_WIDTH - (START_COL);
770
-      char_width = DOG_CHAR_WIDTH;
778
+      constexpr uint8_t lcd_width = LCD_WIDTH - (START_COL),
779
+                        char_width = DOG_CHAR_WIDTH;
771 780
     #endif
772 781
 
773 782
     // Center either one or two rows

+ 4
- 4
Marlin/ultralcd_impl_HD44780.h View File

@@ -733,12 +733,12 @@ static void lcd_implementation_status_screen() {
733 733
 
734 734
     #endif // LCD_WIDTH >= 20 && SDSUPPORT
735 735
 
736
-    lcd.setCursor(LCD_WIDTH - 6, 2);
737
-    lcd.print(LCD_STR_CLOCK[0]);
738
-
739 736
     char buffer[10];
740 737
     duration_t elapsed = print_job_timer.duration();
741
-    elapsed.toDigital(buffer);
738
+    uint8_t len = elapsed.toDigital(buffer);
739
+
740
+    lcd.setCursor(LCD_WIDTH - len - 1, 2);
741
+    lcd.print(LCD_STR_CLOCK[0]);
742 742
     lcd_print(buffer);
743 743
 
744 744
   #endif // LCD_HEIGHT > 3

Loading…
Cancel
Save