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
           print_job_timer.stop();
1172
           print_job_timer.stop();
1173
           char time[30];
1173
           char time[30];
1174
           millis_t t = print_job_timer.duration();
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
           SERIAL_ECHO_START;
1176
           SERIAL_ECHO_START;
1178
           SERIAL_ECHOLN(time);
1177
           SERIAL_ECHOLN(time);
1179
           lcd_setstatus(time, true);
1178
           lcd_setstatus(time, true);

+ 1
- 1
Marlin/dogm_lcd_implementation.h View File

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

+ 8
- 9
Marlin/printcounter.cpp View File

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

+ 4
- 4
Marlin/printcounter.h View File

35
   //const uint8_t magic;    // Magic header, it will always be 0x16
35
   //const uint8_t magic;    // Magic header, it will always be 0x16
36
   uint16_t totalPrints;     // Number of prints
36
   uint16_t totalPrints;     // Number of prints
37
   uint16_t finishedPrints;  // Number of complete prints
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
 class PrintCounter: public Stopwatch {
42
 class PrintCounter: public Stopwatch {
74
      * @details Stores the timestamp of the last deltaDuration(), this is
74
      * @details Stores the timestamp of the last deltaDuration(), this is
75
      * required due to the updateInterval cycle.
75
      * required due to the updateInterval cycle.
76
      */
76
      */
77
-    uint16_t lastDuration;
77
+    millis_t lastDuration;
78
 
78
 
79
     /**
79
     /**
80
      * @brief Stats were loaded from EERPROM
80
      * @brief Stats were loaded from EERPROM
90
      * used internally for print statistics accounting is not intended to be a
90
      * used internally for print statistics accounting is not intended to be a
91
      * user callable function.
91
      * user callable function.
92
      */
92
      */
93
-    uint16_t deltaDuration();
93
+    millis_t deltaDuration();
94
 
94
 
95
   public:
95
   public:
96
     /**
96
     /**

+ 2
- 2
Marlin/stopwatch.cpp View File

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

+ 4
- 4
Marlin/stopwatch.h View File

42
 class Stopwatch {
42
 class Stopwatch {
43
   private:
43
   private:
44
     StopwatchState state;
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
   public:
49
   public:
50
     /**
50
     /**
101
      * @details Returns the total number of seconds the timer has been running.
101
      * @details Returns the total number of seconds the timer has been running.
102
      * @return the delta since starting the stopwatch
102
      * @return the delta since starting the stopwatch
103
      */
103
      */
104
-    uint16_t duration();
104
+    millis_t duration();
105
 
105
 
106
     #if ENABLED(DEBUG_STOPWATCH)
106
     #if ENABLED(DEBUG_STOPWATCH)
107
 
107
 

+ 4
- 4
Marlin/ultralcd.cpp View File

1967
         print_job_counter.loadStats();
1967
         print_job_counter.loadStats();
1968
         printStatistics stats = print_job_counter.getStats();
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
         STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints));        // Print Count : 999
1974
         STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints));        // Print Count : 999
1975
         STATIC_ITEM(MSG_INFO_FINISHED_PRINTS ": ", false, false, itostr3left(stats.finishedPrints)); // Finished    : 666
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
         END_SCREEN();
1977
         END_SCREEN();
1978
       }
1978
       }
1979
     #endif // PRINTCOUNTER
1979
     #endif // PRINTCOUNTER

Loading…
Cancel
Save