Selaa lähdekoodia

Merge pull request #4376 from jbrazio/timestamp_t-short

Adds short format to timestamp_t
Scott Lahteine 9 vuotta sitten
vanhempi
commit
1766b990b8
5 muutettua tiedostoa jossa 82 lisäystä ja 55 poistoa
  1. 17
    4
      Marlin/language_en.h
  2. 31
    21
      Marlin/timestamp_t.h
  3. 19
    15
      Marlin/ultralcd.cpp
  4. 8
    6
      Marlin/ultralcd_impl_DOGM.h
  5. 7
    9
      Marlin/ultralcd_impl_HD44780.h

+ 17
- 4
Marlin/language_en.h Näytä tiedosto

@@ -561,22 +561,35 @@
561 561
     #define MSG_INFO_PRINT_COUNT              "Print Count"
562 562
   #endif
563 563
   #ifndef MSG_INFO_COMPLETED_PRINTS
564
-    #define MSG_INFO_COMPLETED_PRINTS         "Completed  "
564
+    #define MSG_INFO_COMPLETED_PRINTS         "Completed"
565 565
   #endif
566 566
   #ifndef MSG_INFO_PRINT_TIME
567
-    #define MSG_INFO_PRINT_TIME               "Total Time "
567
+    #define MSG_INFO_PRINT_TIME               "Total print time"
568
+  #endif
569
+  #ifndef MSG_INFO_PRINT_LONGEST
570
+    #define MSG_INFO_PRINT_LONGEST            "Longest job time"
571
+  #endif
572
+  #ifndef MSG_INFO_PRINT_FILAMENT
573
+    #define MSG_INFO_PRINT_FILAMENT           "Extruded total"
568 574
   #endif
569 575
 #else
570 576
   #ifndef MSG_INFO_PRINT_COUNT
571
-    #define MSG_INFO_PRINT_COUNT              "Prints   "
577
+    #define MSG_INFO_PRINT_COUNT              "Prints"
572 578
   #endif
573 579
   #ifndef MSG_INFO_COMPLETED_PRINTS
574 580
     #define MSG_INFO_COMPLETED_PRINTS         "Completed"
575 581
   #endif
576 582
   #ifndef MSG_INFO_PRINT_TIME
577
-    #define MSG_INFO_PRINT_TIME               "Duration "
583
+    #define MSG_INFO_PRINT_TIME               "Total"
584
+  #endif
585
+  #ifndef MSG_INFO_PRINT_LONGEST
586
+    #define MSG_INFO_PRINT_LONGEST            "Longest"
587
+  #endif
588
+  #ifndef MSG_INFO_PRINT_FILAMENT
589
+    #define MSG_INFO_PRINT_FILAMENT           "Extruded"
578 590
   #endif
579 591
 #endif
592
+
580 593
 #ifndef MSG_INFO_MIN_TEMP
581 594
   #define MSG_INFO_MIN_TEMP                   "Min Temp"
582 595
 #endif

+ 31
- 21
Marlin/timestamp_t.h Näytä tiedosto

@@ -30,13 +30,13 @@ struct timestamp_t {
30 30
   uint32_t timestamp;
31 31
 
32 32
   /**
33
-   * @brief Date time blank constructor
33
+   * @brief Timestamp blank constructor
34 34
    */
35 35
   timestamp_t()
36 36
     : timestamp_t(0) {};
37 37
 
38 38
   /**
39
-   * @brief Date time constructor
39
+   * @briefTimestamp constructor
40 40
    * @details Initializes the timestamp_t structure based on a number of seconds
41 41
    *
42 42
    * @param seconds The number of seconds
@@ -46,7 +46,7 @@ struct timestamp_t {
46 46
   }
47 47
 
48 48
   /**
49
-   * @brief Formats the date as number of years
49
+   * @brief Formats the timestamp in years
50 50
    * @return The number of years
51 51
    */
52 52
   inline uint8_t year() const {
@@ -54,7 +54,7 @@ struct timestamp_t {
54 54
   }
55 55
 
56 56
   /**
57
-   * @brief Formats the date as number of days
57
+   * @brief Formats the timestamp in days
58 58
    * @return The number of days
59 59
    */
60 60
   inline uint16_t day() const {
@@ -62,7 +62,7 @@ struct timestamp_t {
62 62
   }
63 63
 
64 64
   /**
65
-   * @brief Formats the date as number of hours
65
+   * @brief Formats the timestamp in hours
66 66
    * @return The number of hours
67 67
    */
68 68
   inline uint32_t hour() const {
@@ -70,7 +70,7 @@ struct timestamp_t {
70 70
   }
71 71
 
72 72
   /**
73
-   * @brief Formats the date as number of minutes
73
+   * @brief Formats the timestamp in minutes
74 74
    * @return The number of minutes
75 75
    */
76 76
   inline uint32_t minute() const {
@@ -78,7 +78,7 @@ struct timestamp_t {
78 78
   }
79 79
 
80 80
   /**
81
-   * @brief Formats the date as number of seconds
81
+   * @brief Formats the timestamp in seconds
82 82
    * @return The number of seconds
83 83
    */
84 84
   inline uint32_t second() const {
@@ -86,12 +86,14 @@ struct timestamp_t {
86 86
   }
87 87
 
88 88
   /**
89
-   * @brief Formats the date as a string
89
+   * @brief Formats the timestamp as a string
90 90
    * @details Returns the timestamp formated as a string
91 91
    *
92
-   * @param buffer The array pointed to must be able to accommodate 21 bytes
92
+   * @param buffer The array pointed to must be able to accommodate 21 bytes when
93
+   *               on standard mode or 10 bytes otherwise.
94
+   * @param shorty If true a short representation will be returned.
93 95
    *
94
-   * String output examples:
96
+   * Standard toString() output examples:
95 97
    *  123456789012345678901 (strlen)
96 98
    *  135y 364d 23h 59m 59s
97 99
    *  364d 23h 59m 59s
@@ -99,19 +101,27 @@ struct timestamp_t {
99 101
    *  59m 59s
100 102
    *  59s
101 103
    *
104
+   * Short toString() output examples:
105
+   *  1234567890 (strlen)
106
+   *  1193046:59
107
+   *
102 108
    */
103
-  void toString(char *buffer) const {
104
-    int y = this->year(),
105
-        d = this->day() % 365,
106
-        h = this->hour() % 24,
107
-        m = this->minute() % 60,
108
-        s = this->second() % 60;
109
+  void toString(char *buffer, bool const &shorty = false) const {
110
+    int h = this->hour() % 24,
111
+        m = this->minute() % 60;
112
+
113
+    if (shorty) sprintf_P(buffer, PSTR("%02i:%02i"), h, m);
114
+    else {
115
+      int y = this->year(),
116
+          d = this->day() % 365,
117
+          s = this->second() % 60;
109 118
 
110
-    if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
111
-    else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
112
-    else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
113
-    else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
114
-    else sprintf_P(buffer, PSTR("%is"), s);
119
+      if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
120
+      else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
121
+      else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
122
+      else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
123
+      else sprintf_P(buffer, PSTR("%is"), s);
124
+    }
115 125
   }
116 126
 };
117 127
 

+ 19
- 15
Marlin/ultralcd.cpp Näytä tiedosto

@@ -31,6 +31,7 @@
31 31
 
32 32
 #if ENABLED(PRINTCOUNTER)
33 33
   #include "printcounter.h"
34
+  #include "timestamp_t.h"
34 35
 #endif
35 36
 
36 37
 int preheatHotendTemp1, preheatBedTemp1, preheatFanSpeed1,
@@ -1971,23 +1972,26 @@ void kill_screen(const char* lcd_msg) {
1971 1972
       static void lcd_info_stats_menu() {
1972 1973
         if (LCD_CLICKED) { lcd_goto_previous_menu(true); return; }
1973 1974
 
1974
-        PrintCounter print_job_counter = PrintCounter();
1975
-        print_job_counter.loadStats();
1976
-        printStatistics stats = print_job_counter.getStats();
1975
+        char buffer[21];
1976
+        printStatistics stats = print_job_timer.getStats();
1977 1977
 
1978
-        char timeString[14];
1979
-        sprintf_P(timeString,
1980
-        PSTR("%i" MSG_SHORT_DAY " %i" MSG_SHORT_HOUR " %i" MSG_SHORT_MINUTE),
1981
-          int(stats.printTime / 60 / 60 / 24),
1982
-          int((stats.printTime / 60 / 60) % 24),
1983
-          int((stats.printTime / 60) % 60)
1984
-        );
1978
+        START_SCREEN();                                                                                // 12345678901234567890
1979
+        STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints));          // Print Count: 999
1980
+        STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS"  : ", false, false, itostr3left(stats.finishedPrints)); // Completed  : 666
1981
+
1982
+        timestamp_t time(stats.printTime);
1983
+        time.toString(buffer);
1984
+        STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false);                                           // Total print Time:
1985
+        STATIC_ITEM("", false, false, buffer);                                                         // 99y 364d 23h 59m 59s
1986
+
1987
+        time.timestamp = stats.longestPrint;
1988
+        time.toString(buffer);
1989
+        STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false);                                        // Longest job time:
1990
+        STATIC_ITEM("", false, false, buffer);                                                         // 99y 364d 23h 59m 59s
1985 1991
 
1986
-        START_SCREEN();                                                                              // 12345678901234567890
1987
-        STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints));        // Print Count: 999
1988
-        STATIC_ITEM(MSG_INFO_COMPLETED_PRINTS": ", false, false, itostr3left(stats.finishedPrints)); // Completed  : 666
1989
-        STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false);                                         // Total Time :
1990
-        STATIC_ITEM("  ", false, false, timeString);                                                 //   12345d 12h 34m
1992
+        sprintf_P(buffer, PSTR("%im"), stats.filamentUsed / 1000);
1993
+        STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false);                                       // Extruded total:
1994
+        STATIC_ITEM("", false, false, buffer);                                                         // 125m
1991 1995
         END_SCREEN();
1992 1996
       }
1993 1997
     #endif // PRINTCOUNTER

+ 8
- 6
Marlin/ultralcd_impl_DOGM.h Näytä tiedosto

@@ -58,6 +58,8 @@
58 58
 #include "ultralcd_st7920_u8glib_rrd.h"
59 59
 #include "Configuration.h"
60 60
 
61
+#include "timestamp_t.h"
62
+
61 63
 #if DISABLED(MAPPER_C2C3) && DISABLED(MAPPER_NON) && ENABLED(USE_BIG_EDIT_FONT)
62 64
   #undef USE_BIG_EDIT_FONT
63 65
 #endif
@@ -387,12 +389,12 @@ static void lcd_implementation_status_screen() {
387 389
     }
388 390
 
389 391
     u8g.setPrintPos(80,48);
390
-    millis_t time = print_job_timer.duration() / 60;
391
-    if (time != 0) {
392
-      lcd_print(itostr2(time/60));
393
-      lcd_print(':');
394
-      lcd_print(itostr2(time%60));
395
-    }
392
+
393
+    char buffer[10];
394
+    timestamp_t time(print_job_timer.duration());
395
+    time.toString(buffer, true);
396
+    if (time.timestamp != 0) lcd_print(buffer);
397
+    else lcd_printPGM(PSTR("--:--"));
396 398
   #endif
397 399
 
398 400
   // Extruders

+ 7
- 9
Marlin/ultralcd_impl_HD44780.h Näytä tiedosto

@@ -27,6 +27,8 @@
27 27
 * Implementation of the LCD display routines for a Hitachi HD44780 display. These are common LCD character displays.
28 28
 **/
29 29
 
30
+#include "timestamp_t.h"
31
+
30 32
 extern volatile uint8_t buttons;  //an extended version of the last checked buttons in a bit array.
31 33
 
32 34
 ////////////////////////////////////
@@ -760,15 +762,11 @@ static void lcd_implementation_status_screen() {
760 762
     lcd.setCursor(LCD_WIDTH - 6, 2);
761 763
     lcd.print(LCD_STR_CLOCK[0]);
762 764
 
763
-    uint16_t time = print_job_timer.duration() / 60;
764
-    if (time != 0) {
765
-      lcd.print(itostr2(time / 60));
766
-      lcd.print(':');
767
-      lcd.print(itostr2(time % 60));
768
-    }
769
-    else {
770
-      lcd_printPGM(PSTR("--:--"));
771
-    }
765
+    char buffer[10];
766
+    timestamp_t time(print_job_timer.duration());
767
+    time.toString(buffer, true);
768
+    if (time.timestamp != 0) lcd_print(buffer);
769
+    else lcd_printPGM(PSTR("--:--"));
772 770
 
773 771
   #endif // LCD_HEIGHT > 3
774 772
 

Loading…
Peruuta
Tallenna