Browse Source

Allow stopwatch and printcounter to go over 18 hours

Scott Lahteine 8 years ago
parent
commit
e481b79af1

+ 1
- 2
Marlin/Marlin_main.cpp View File

@@ -1172,8 +1172,7 @@ inline void get_serial_commands() {
1172 1172
           print_job_timer.stop();
1173 1173
           char time[30];
1174 1174
           millis_t t = print_job_timer.duration();
1175
-          int hours = t / 60 / 60, minutes = (t / 60) % 60;
1176
-          sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
1175
+          sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), int(t / 60 / 60), int(t / 60) % 60);
1177 1176
           SERIAL_ECHO_START;
1178 1177
           SERIAL_ECHOLN(time);
1179 1178
           lcd_setstatus(time, true);

+ 1
- 1
Marlin/dogm_lcd_implementation.h View File

@@ -386,7 +386,7 @@ static void lcd_implementation_status_screen() {
386 386
     }
387 387
 
388 388
     u8g.setPrintPos(80,48);
389
-    uint16_t time = print_job_timer.duration() / 60;
389
+    millis_t time = print_job_timer.duration() / 60;
390 390
     if (time != 0) {
391 391
       lcd_print(itostr2(time/60));
392 392
       lcd_print(':');

+ 8
- 9
Marlin/printcounter.cpp View File

@@ -27,12 +27,12 @@ PrintCounter::PrintCounter(): super() {
27 27
   this->loadStats();
28 28
 }
29 29
 
30
-uint16_t PrintCounter::deltaDuration() {
30
+millis_t PrintCounter::deltaDuration() {
31 31
   #if ENABLED(DEBUG_PRINTCOUNTER)
32 32
     PrintCounter::debug(PSTR("deltaDuration"));
33 33
   #endif
34 34
 
35
-  uint16_t tmp = this->lastDuration;
35
+  millis_t tmp = this->lastDuration;
36 36
   this->lastDuration = this->duration();
37 37
   return this->lastDuration - tmp;
38 38
 }
@@ -88,12 +88,12 @@ void PrintCounter::showStats() {
88 88
   SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints
89 89
     - ((this->isRunning() || this->isPaused()) ? 1 : 0)); // Removes 1 from failures with an active counter
90 90
 
91
-  uint32_t t = this->data.printTime / 60;
91
+  millis_t t = this->data.printTime / 60; // minutes from seconds
92 92
   SERIAL_ECHOPGM(", Total print time: ");
93
-  SERIAL_ECHO(t / 60);
93
+  SERIAL_ECHO(t / 60); // hours
94 94
 
95 95
   SERIAL_ECHOPGM("h ");
96
-  SERIAL_ECHO(t % 60);
96
+  SERIAL_ECHO(t % 60); // minutes
97 97
 
98 98
   SERIAL_ECHOPGM("min");
99 99
 
@@ -110,10 +110,10 @@ void PrintCounter::showStats() {
110 110
 void PrintCounter::tick() {
111 111
   if (!this->isRunning()) return;
112 112
 
113
-  static uint32_t update_before = millis(),
113
+  static millis_t update_before = millis(),
114 114
                   eeprom_before = millis();
115 115
 
116
-  uint32_t now = millis();
116
+  millis_t now = millis();
117 117
 
118 118
   // Trying to get the amount of calculations down to the bare min
119 119
   const static uint16_t i = this->updateInterval * 1000;
@@ -128,8 +128,7 @@ void PrintCounter::tick() {
128 128
   }
129 129
 
130 130
   // Trying to get the amount of calculations down to the bare min
131
-  const static uint32_t j = this->saveInterval * 1000;
132
-
131
+  const static millis_t j = this->saveInterval * 1000;
133 132
   if (now - eeprom_before >= j) {
134 133
     eeprom_before = now;
135 134
     this->saveStats();

+ 4
- 4
Marlin/printcounter.h View File

@@ -35,8 +35,8 @@ struct printStatistics {    // 13 bytes
35 35
   //const uint8_t magic;    // Magic header, it will always be 0x16
36 36
   uint16_t totalPrints;     // Number of prints
37 37
   uint16_t finishedPrints;  // Number of complete prints
38
-  uint32_t printTime;       // Total printing time
39
-  uint32_t longestPrint;    // Longest print job - not in use
38
+  millis_t printTime;       // Total printing time
39
+  millis_t longestPrint;    // Longest print job - not in use
40 40
 };
41 41
 
42 42
 class PrintCounter: public Stopwatch {
@@ -74,7 +74,7 @@ class PrintCounter: public Stopwatch {
74 74
      * @details Stores the timestamp of the last deltaDuration(), this is
75 75
      * required due to the updateInterval cycle.
76 76
      */
77
-    uint16_t lastDuration;
77
+    millis_t lastDuration;
78 78
 
79 79
     /**
80 80
      * @brief Stats were loaded from EERPROM
@@ -90,7 +90,7 @@ class PrintCounter: public Stopwatch {
90 90
      * used internally for print statistics accounting is not intended to be a
91 91
      * user callable function.
92 92
      */
93
-    uint16_t deltaDuration();
93
+    millis_t deltaDuration();
94 94
 
95 95
   public:
96 96
     /**

+ 2
- 2
Marlin/stopwatch.cpp View File

@@ -88,9 +88,9 @@ bool Stopwatch::isPaused() {
88 88
   return (this->state == STOPWATCH_PAUSED) ? true : false;
89 89
 }
90 90
 
91
-uint16_t Stopwatch::duration() {
91
+millis_t Stopwatch::duration() {
92 92
   return (((this->isRunning()) ? millis() : this->stopTimestamp)
93
-          - this->startTimestamp) / 1000 + this->accumulator;
93
+          - this->startTimestamp) / 1000UL + this->accumulator;
94 94
 }
95 95
 
96 96
 #if ENABLED(DEBUG_STOPWATCH)

+ 4
- 4
Marlin/stopwatch.h View File

@@ -42,9 +42,9 @@ enum StopwatchState {
42 42
 class Stopwatch {
43 43
   private:
44 44
     StopwatchState state;
45
-    uint16_t accumulator;
46
-    uint32_t startTimestamp;
47
-    uint32_t stopTimestamp;
45
+    millis_t accumulator;
46
+    millis_t startTimestamp;
47
+    millis_t stopTimestamp;
48 48
 
49 49
   public:
50 50
     /**
@@ -101,7 +101,7 @@ class Stopwatch {
101 101
      * @details Returns the total number of seconds the timer has been running.
102 102
      * @return the delta since starting the stopwatch
103 103
      */
104
-    uint16_t duration();
104
+    millis_t duration();
105 105
 
106 106
     #if ENABLED(DEBUG_STOPWATCH)
107 107
 

+ 4
- 4
Marlin/ultralcd.cpp View File

@@ -1967,13 +1967,13 @@ void kill_screen(const char* lcd_msg) {
1967 1967
         print_job_counter.loadStats();
1968 1968
         printStatistics stats = print_job_counter.getStats();
1969 1969
 
1970
-        char printTime[6];
1971
-        sprintf(printTime, "%02d:%02d", int(stats.printTime / 3600), int(stats.printTime / 60) % 60);
1970
+        char timeString[8];
1971
+        sprintf_P(timeString, PSTR("%i:%02i"), int(stats.printTime / 60 / 60), int(stats.printTime / 60) % 60);
1972 1972
 
1973
-        START_SCREEN();
1973
+        START_SCREEN();                                                                              // 12345678901234567890
1974 1974
         STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints));        // Print Count : 999
1975 1975
         STATIC_ITEM(MSG_INFO_FINISHED_PRINTS ": ", false, false, itostr3left(stats.finishedPrints)); // Finished    : 666
1976
-        STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false, printTime);                              // Total Time  : 12:34
1976
+        STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false, timeString);                             // Total Time  : 123:45
1977 1977
         END_SCREEN();
1978 1978
       }
1979 1979
     #endif // PRINTCOUNTER

Loading…
Cancel
Save