소스 검색

Use static classes for job timers (#9938)

Scott Lahteine 6 년 전
부모
커밋
36262a0479
No account linked to committer's email address
5개의 변경된 파일171개의 추가작업 그리고 166개의 파일을 삭제
  1. 3
    5
      Marlin/src/Marlin.cpp
  2. 25
    23
      Marlin/src/libs/stopwatch.cpp
  3. 28
    32
      Marlin/src/libs/stopwatch.h
  4. 65
    63
      Marlin/src/module/printcounter.cpp
  5. 50
    43
      Marlin/src/module/printcounter.h

+ 3
- 5
Marlin/src/Marlin.cpp 파일 보기

730
   // Load data from EEPROM if available (or use defaults)
730
   // Load data from EEPROM if available (or use defaults)
731
   // This also updates variables in the planner, elsewhere
731
   // This also updates variables in the planner, elsewhere
732
   (void)settings.load();
732
   (void)settings.load();
733
-  
734
-  #if ENABLED(PRINTCOUNTER)
735
-    print_job_timer.init();
736
-  #endif  
737
-  
733
+
738
   #if HAS_M206_COMMAND
734
   #if HAS_M206_COMMAND
739
     // Initialize current position based on home_offset
735
     // Initialize current position based on home_offset
740
     COPY(current_position, home_offset);
736
     COPY(current_position, home_offset);
747
 
743
 
748
   thermalManager.init();    // Initialize temperature loop
744
   thermalManager.init();    // Initialize temperature loop
749
 
745
 
746
+  print_job_timer.init();   // Initial setup of print job timer
747
+
750
   stepper.init();    // Initialize stepper, this enables interrupts!
748
   stepper.init();    // Initialize stepper, this enables interrupts!
751
 
749
 
752
   #if HAS_SERVOS
750
   #if HAS_SERVOS

+ 25
- 23
Marlin/src/libs/stopwatch.cpp 파일 보기

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#include "../Marlin.h"
24
 #include "stopwatch.h"
23
 #include "stopwatch.h"
25
 
24
 
26
-Stopwatch::Stopwatch() {
27
-  this->reset();
28
-}
25
+#include "../inc/MarlinConfig.h"
26
+
27
+Stopwatch::State Stopwatch::state;
28
+millis_t Stopwatch::accumulator;
29
+millis_t Stopwatch::startTimestamp;
30
+millis_t Stopwatch::stopTimestamp;
29
 
31
 
30
 bool Stopwatch::stop() {
32
 bool Stopwatch::stop() {
31
   #if ENABLED(DEBUG_STOPWATCH)
33
   #if ENABLED(DEBUG_STOPWATCH)
32
     Stopwatch::debug(PSTR("stop"));
34
     Stopwatch::debug(PSTR("stop"));
33
   #endif
35
   #endif
34
 
36
 
35
-  if (this->isRunning() || this->isPaused()) {
36
-    this->state = STOPPED;
37
-    this->stopTimestamp = millis();
37
+  if (isRunning() || isPaused()) {
38
+    state = STOPPED;
39
+    stopTimestamp = millis();
38
     return true;
40
     return true;
39
   }
41
   }
40
   else return false;
42
   else return false;
45
     Stopwatch::debug(PSTR("pause"));
47
     Stopwatch::debug(PSTR("pause"));
46
   #endif
48
   #endif
47
 
49
 
48
-  if (this->isRunning()) {
49
-    this->state = PAUSED;
50
-    this->stopTimestamp = millis();
50
+  if (isRunning()) {
51
+    state = PAUSED;
52
+    stopTimestamp = millis();
51
     return true;
53
     return true;
52
   }
54
   }
53
   else return false;
55
   else return false;
58
     Stopwatch::debug(PSTR("start"));
60
     Stopwatch::debug(PSTR("start"));
59
   #endif
61
   #endif
60
 
62
 
61
-  if (!this->isRunning()) {
62
-    if (this->isPaused()) this->accumulator = this->duration();
63
-    else this->reset();
63
+  if (!isRunning()) {
64
+    if (isPaused()) accumulator = duration();
65
+    else reset();
64
 
66
 
65
-    this->state = RUNNING;
66
-    this->startTimestamp = millis();
67
+    state = RUNNING;
68
+    startTimestamp = millis();
67
     return true;
69
     return true;
68
   }
70
   }
69
   else return false;
71
   else return false;
74
     Stopwatch::debug(PSTR("reset"));
76
     Stopwatch::debug(PSTR("reset"));
75
   #endif
77
   #endif
76
 
78
 
77
-  this->state = STOPPED;
78
-  this->startTimestamp = 0;
79
-  this->stopTimestamp = 0;
80
-  this->accumulator = 0;
79
+  state = STOPPED;
80
+  startTimestamp = 0;
81
+  stopTimestamp = 0;
82
+  accumulator = 0;
81
 }
83
 }
82
 
84
 
83
 bool Stopwatch::isRunning() {
85
 bool Stopwatch::isRunning() {
84
-  return (this->state == RUNNING) ? true : false;
86
+  return (state == RUNNING) ? true : false;
85
 }
87
 }
86
 
88
 
87
 bool Stopwatch::isPaused() {
89
 bool Stopwatch::isPaused() {
88
-  return (this->state == PAUSED) ? true : false;
90
+  return (state == PAUSED) ? true : false;
89
 }
91
 }
90
 
92
 
91
 millis_t Stopwatch::duration() {
93
 millis_t Stopwatch::duration() {
92
-  return (((this->isRunning()) ? millis() : this->stopTimestamp)
93
-          - this->startTimestamp) / 1000UL + this->accumulator;
94
+  return (((isRunning()) ? millis() : stopTimestamp)
95
+          - startTimestamp) / 1000UL + accumulator;
94
 }
96
 }
95
 
97
 
96
 #if ENABLED(DEBUG_STOPWATCH)
98
 #if ENABLED(DEBUG_STOPWATCH)

+ 28
- 32
Marlin/src/libs/stopwatch.h 파일 보기

23
 #ifndef STOPWATCH_H
23
 #ifndef STOPWATCH_H
24
 #define STOPWATCH_H
24
 #define STOPWATCH_H
25
 
25
 
26
-#include "../core/types.h"
27
-
28
 // Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
26
 // Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
29
 //#define DEBUG_STOPWATCH
27
 //#define DEBUG_STOPWATCH
30
 
28
 
29
+#include "../core/macros.h"
30
+#include "../core/types.h"
31
+
31
 /**
32
 /**
32
  * @brief Stopwatch class
33
  * @brief Stopwatch class
33
  * @details This class acts as a timer proving stopwatch functionality including
34
  * @details This class acts as a timer proving stopwatch functionality including
41
       PAUSED
42
       PAUSED
42
     };
43
     };
43
 
44
 
44
-    Stopwatch::State state;
45
-    millis_t accumulator;
46
-    millis_t startTimestamp;
47
-    millis_t stopTimestamp;
45
+    static Stopwatch::State state;
46
+    static millis_t accumulator;
47
+    static millis_t startTimestamp;
48
+    static millis_t stopTimestamp;
48
 
49
 
49
   public:
50
   public:
50
     /**
51
     /**
51
-     * @brief Class constructor
52
-     */
53
-    Stopwatch();
54
-
55
-    /**
56
      * @brief Initialize the stopwatch
52
      * @brief Initialize the stopwatch
57
      */
53
      */
58
-    inline void init() {}
54
+    FORCE_INLINE static void init() { reset(); }
59
 
55
 
60
     /**
56
     /**
61
      * @brief Stops the stopwatch
57
      * @brief Stops the stopwatch
63
      * no timer is currently running.
59
      * no timer is currently running.
64
      * @return true is method was successful
60
      * @return true is method was successful
65
      */
61
      */
66
-    bool stop();
62
+    static bool stop();
67
 
63
 
68
     /**
64
     /**
69
      * @brief Pause the stopwatch
65
      * @brief Pause the stopwatch
70
-     * @details Pauses the running timer, it will silently ignore the request if
66
+     * @details Pause the running timer, it will silently ignore the request if
71
      * no timer is currently running.
67
      * no timer is currently running.
72
      * @return true is method was successful
68
      * @return true is method was successful
73
      */
69
      */
74
-    bool pause();
70
+    static bool pause();
75
 
71
 
76
     /**
72
     /**
77
-     * @brief Starts the stopwatch
78
-     * @details Starts the timer, it will silently ignore the request if the
73
+     * @brief Start the stopwatch
74
+     * @details Start the timer, it will silently ignore the request if the
79
      * timer is already running.
75
      * timer is already running.
80
      * @return true is method was successful
76
      * @return true is method was successful
81
      */
77
      */
82
-    bool start();
78
+    static bool start();
83
 
79
 
84
     /**
80
     /**
85
-     * @brief Resets the stopwatch
86
-     * @details Resets all settings to their default values.
81
+     * @brief Reset the stopwatch
82
+     * @details Reset all settings to their default values.
87
      */
83
      */
88
-    void reset();
84
+    static void reset();
89
 
85
 
90
     /**
86
     /**
91
-     * @brief Checks if the timer is running
92
-     * @details Returns true if the timer is currently running, false otherwise.
87
+     * @brief Check if the timer is running
88
+     * @details Return true if the timer is currently running, false otherwise.
93
      * @return true if stopwatch is running
89
      * @return true if stopwatch is running
94
      */
90
      */
95
-    bool isRunning();
91
+    static bool isRunning();
96
 
92
 
97
     /**
93
     /**
98
-     * @brief Checks if the timer is paused
99
-     * @details Returns true if the timer is currently paused, false otherwise.
94
+     * @brief Check if the timer is paused
95
+     * @details Return true if the timer is currently paused, false otherwise.
100
      * @return true if stopwatch is paused
96
      * @return true if stopwatch is paused
101
      */
97
      */
102
-    bool isPaused();
98
+    static bool isPaused();
103
 
99
 
104
     /**
100
     /**
105
-     * @brief Gets the running time
106
-     * @details Returns the total number of seconds the timer has been running.
101
+     * @brief Get the running time
102
+     * @details Return the total number of seconds the timer has been running.
107
      * @return the delta since starting the stopwatch
103
      * @return the delta since starting the stopwatch
108
      */
104
      */
109
-    millis_t duration();
105
+    static millis_t duration();
110
 
106
 
111
     #ifdef DEBUG_STOPWATCH
107
     #ifdef DEBUG_STOPWATCH
112
 
108
 
113
       /**
109
       /**
114
-       * @brief Prints a debug message
115
-       * @details Prints a simple debug message "Stopwatch::function"
110
+       * @brief Print a debug message
111
+       * @details Print a simple debug message "Stopwatch::function"
116
        */
112
        */
117
       static void debug(const char func[]);
113
       static void debug(const char func[]);
118
 
114
 

+ 65
- 63
Marlin/src/module/printcounter.cpp 파일 보기

22
 
22
 
23
 #include "../inc/MarlinConfig.h"
23
 #include "../inc/MarlinConfig.h"
24
 
24
 
25
-#if ENABLED(PRINTCOUNTER)
25
+#if DISABLED(PRINTCOUNTER)
26
 
26
 
27
-#include "printcounter.h"
27
+#include "../libs/stopwatch.h"
28
+Stopwatch print_job_timer;      // Global Print Job Timer instance
28
 
29
 
30
+#else // PRINTCOUNTER
31
+
32
+#include "printcounter.h"
29
 #include "../Marlin.h"
33
 #include "../Marlin.h"
30
 
34
 
35
+PrintCounter print_job_timer;   // Global Print Job Timer instance
36
+
37
+printStatistics PrintCounter::data;
38
+
39
+const PrintCounter::promdress PrintCounter::address = STATS_EEPROM_ADDRESS;
40
+
41
+const uint16_t PrintCounter::updateInterval = 10;
42
+const uint16_t PrintCounter::saveInterval = 3600;
43
+millis_t PrintCounter::lastDuration;
44
+bool PrintCounter::loaded = false;
45
+
31
 millis_t PrintCounter::deltaDuration() {
46
 millis_t PrintCounter::deltaDuration() {
32
   #if ENABLED(DEBUG_PRINTCOUNTER)
47
   #if ENABLED(DEBUG_PRINTCOUNTER)
33
-    PrintCounter::debug(PSTR("deltaDuration"));
48
+    debug(PSTR("deltaDuration"));
34
   #endif
49
   #endif
35
 
50
 
36
-  millis_t tmp = this->lastDuration;
37
-  this->lastDuration = this->duration();
38
-  return this->lastDuration - tmp;
39
-}
40
-
41
-bool PrintCounter::isLoaded() {
42
-  return this->loaded;
51
+  millis_t tmp = lastDuration;
52
+  lastDuration = duration();
53
+  return lastDuration - tmp;
43
 }
54
 }
44
 
55
 
45
 void PrintCounter::incFilamentUsed(double const &amount) {
56
 void PrintCounter::incFilamentUsed(double const &amount) {
46
   #if ENABLED(DEBUG_PRINTCOUNTER)
57
   #if ENABLED(DEBUG_PRINTCOUNTER)
47
-    PrintCounter::debug(PSTR("incFilamentUsed"));
58
+    debug(PSTR("incFilamentUsed"));
48
   #endif
59
   #endif
49
 
60
 
50
   // Refuses to update data if object is not loaded
61
   // Refuses to update data if object is not loaded
51
-  if (!this->isLoaded()) return;
62
+  if (!isLoaded()) return;
52
 
63
 
53
-  this->data.filamentUsed += amount; // mm
64
+  data.filamentUsed += amount; // mm
54
 }
65
 }
55
 
66
 
56
-
57
 void PrintCounter::initStats() {
67
 void PrintCounter::initStats() {
58
   #if ENABLED(DEBUG_PRINTCOUNTER)
68
   #if ENABLED(DEBUG_PRINTCOUNTER)
59
-    PrintCounter::debug(PSTR("initStats"));
69
+    debug(PSTR("initStats"));
60
   #endif
70
   #endif
61
 
71
 
62
-  this->loaded = true;
63
-  this->data = { 0, 0, 0, 0, 0.0 };
72
+  loaded = true;
73
+  data = { 0, 0, 0, 0, 0.0 };
64
 
74
 
65
-  this->saveStats();
66
-  eeprom_write_byte((uint8_t *) this->address, 0x16);
75
+  saveStats();
76
+  eeprom_write_byte((uint8_t*)address, 0x16);
67
 }
77
 }
68
 
78
 
69
 void PrintCounter::loadStats() {
79
 void PrintCounter::loadStats() {
70
   #if ENABLED(DEBUG_PRINTCOUNTER)
80
   #if ENABLED(DEBUG_PRINTCOUNTER)
71
-    PrintCounter::debug(PSTR("loadStats"));
81
+    debug(PSTR("loadStats"));
72
   #endif
82
   #endif
73
 
83
 
74
   // Checks if the EEPROM block is initialized
84
   // Checks if the EEPROM block is initialized
75
-  if (eeprom_read_byte((uint8_t *) this->address) != 0x16) this->initStats();
76
-  else eeprom_read_block(&this->data,
77
-    (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
85
+  if (eeprom_read_byte((uint8_t*)address) != 0x16) initStats();
86
+  else eeprom_read_block(&data,
87
+    (void*)(address + sizeof(uint8_t)), sizeof(printStatistics));
78
 
88
 
79
-  this->loaded = true;
89
+  loaded = true;
80
 }
90
 }
81
 
91
 
82
 void PrintCounter::saveStats() {
92
 void PrintCounter::saveStats() {
83
   #if ENABLED(DEBUG_PRINTCOUNTER)
93
   #if ENABLED(DEBUG_PRINTCOUNTER)
84
-    PrintCounter::debug(PSTR("saveStats"));
94
+    debug(PSTR("saveStats"));
85
   #endif
95
   #endif
86
 
96
 
87
   // Refuses to save data if object is not loaded
97
   // Refuses to save data if object is not loaded
88
-  if (!this->isLoaded()) return;
98
+  if (!isLoaded()) return;
89
 
99
 
90
   // Saves the struct to EEPROM
100
   // Saves the struct to EEPROM
91
-  eeprom_update_block(&this->data,
92
-    (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
101
+  eeprom_update_block(&data,
102
+    (void*)(address + sizeof(uint8_t)), sizeof(printStatistics));
93
 }
103
 }
94
 
104
 
95
 void PrintCounter::showStats() {
105
 void PrintCounter::showStats() {
98
   SERIAL_PROTOCOLPGM(MSG_STATS);
108
   SERIAL_PROTOCOLPGM(MSG_STATS);
99
 
109
 
100
   SERIAL_ECHOPGM("Prints: ");
110
   SERIAL_ECHOPGM("Prints: ");
101
-  SERIAL_ECHO(this->data.totalPrints);
111
+  SERIAL_ECHO(data.totalPrints);
102
 
112
 
103
   SERIAL_ECHOPGM(", Finished: ");
113
   SERIAL_ECHOPGM(", Finished: ");
104
-  SERIAL_ECHO(this->data.finishedPrints);
114
+  SERIAL_ECHO(data.finishedPrints);
105
 
115
 
106
   SERIAL_ECHOPGM(", Failed: "); // Note: Removes 1 from failures with an active counter
116
   SERIAL_ECHOPGM(", Failed: "); // Note: Removes 1 from failures with an active counter
107
-  SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints
108
-    - ((this->isRunning() || this->isPaused()) ? 1 : 0));
117
+  SERIAL_ECHO(data.totalPrints - data.finishedPrints
118
+    - ((isRunning() || isPaused()) ? 1 : 0));
109
 
119
 
110
   SERIAL_EOL();
120
   SERIAL_EOL();
111
   SERIAL_PROTOCOLPGM(MSG_STATS);
121
   SERIAL_PROTOCOLPGM(MSG_STATS);
112
 
122
 
113
-  duration_t elapsed = this->data.printTime;
123
+  duration_t elapsed = data.printTime;
114
   elapsed.toString(buffer);
124
   elapsed.toString(buffer);
115
 
125
 
116
   SERIAL_ECHOPGM("Total time: ");
126
   SERIAL_ECHOPGM("Total time: ");
118
 
128
 
119
   #if ENABLED(DEBUG_PRINTCOUNTER)
129
   #if ENABLED(DEBUG_PRINTCOUNTER)
120
     SERIAL_ECHOPGM(" (");
130
     SERIAL_ECHOPGM(" (");
121
-    SERIAL_ECHO(this->data.printTime);
131
+    SERIAL_ECHO(data.printTime);
122
     SERIAL_CHAR(')');
132
     SERIAL_CHAR(')');
123
   #endif
133
   #endif
124
 
134
 
125
-  elapsed = this->data.longestPrint;
135
+  elapsed = data.longestPrint;
126
   elapsed.toString(buffer);
136
   elapsed.toString(buffer);
127
 
137
 
128
   SERIAL_ECHOPGM(", Longest job: ");
138
   SERIAL_ECHOPGM(", Longest job: ");
130
 
140
 
131
   #if ENABLED(DEBUG_PRINTCOUNTER)
141
   #if ENABLED(DEBUG_PRINTCOUNTER)
132
     SERIAL_ECHOPGM(" (");
142
     SERIAL_ECHOPGM(" (");
133
-    SERIAL_ECHO(this->data.longestPrint);
143
+    SERIAL_ECHO(data.longestPrint);
134
     SERIAL_CHAR(')');
144
     SERIAL_CHAR(')');
135
   #endif
145
   #endif
136
 
146
 
138
   SERIAL_PROTOCOLPGM(MSG_STATS);
148
   SERIAL_PROTOCOLPGM(MSG_STATS);
139
 
149
 
140
   SERIAL_ECHOPGM("Filament used: ");
150
   SERIAL_ECHOPGM("Filament used: ");
141
-  SERIAL_ECHO(this->data.filamentUsed / 1000);
151
+  SERIAL_ECHO(data.filamentUsed / 1000);
142
   SERIAL_CHAR('m');
152
   SERIAL_CHAR('m');
143
 
153
 
144
   SERIAL_EOL();
154
   SERIAL_EOL();
145
 }
155
 }
146
 
156
 
147
 void PrintCounter::tick() {
157
 void PrintCounter::tick() {
148
-  if (!this->isRunning()) return;
158
+  if (!isRunning()) return;
149
 
159
 
150
   static uint32_t update_last = millis(),
160
   static uint32_t update_last = millis(),
151
                   eeprom_last = millis();
161
                   eeprom_last = millis();
153
   millis_t now = millis();
163
   millis_t now = millis();
154
 
164
 
155
   // Trying to get the amount of calculations down to the bare min
165
   // Trying to get the amount of calculations down to the bare min
156
-  const static uint16_t i = this->updateInterval * 1000;
166
+  const static uint16_t i = updateInterval * 1000;
157
 
167
 
158
   if (now - update_last >= i) {
168
   if (now - update_last >= i) {
159
     #if ENABLED(DEBUG_PRINTCOUNTER)
169
     #if ENABLED(DEBUG_PRINTCOUNTER)
160
-      PrintCounter::debug(PSTR("tick"));
170
+      debug(PSTR("tick"));
161
     #endif
171
     #endif
162
 
172
 
163
-    this->data.printTime += this->deltaDuration();
173
+    data.printTime += deltaDuration();
164
     update_last = now;
174
     update_last = now;
165
   }
175
   }
166
 
176
 
167
   // Trying to get the amount of calculations down to the bare min
177
   // Trying to get the amount of calculations down to the bare min
168
-  const static millis_t j = this->saveInterval * 1000;
178
+  const static millis_t j = saveInterval * 1000;
169
   if (now - eeprom_last >= j) {
179
   if (now - eeprom_last >= j) {
170
     eeprom_last = now;
180
     eeprom_last = now;
171
-    this->saveStats();
181
+    saveStats();
172
   }
182
   }
173
 }
183
 }
174
 
184
 
175
 // @Override
185
 // @Override
176
 bool PrintCounter::start() {
186
 bool PrintCounter::start() {
177
   #if ENABLED(DEBUG_PRINTCOUNTER)
187
   #if ENABLED(DEBUG_PRINTCOUNTER)
178
-    PrintCounter::debug(PSTR("start"));
188
+    debug(PSTR("start"));
179
   #endif
189
   #endif
180
 
190
 
181
-  bool paused = this->isPaused();
191
+  bool paused = isPaused();
182
 
192
 
183
   if (super::start()) {
193
   if (super::start()) {
184
     if (!paused) {
194
     if (!paused) {
185
-      this->data.totalPrints++;
186
-      this->lastDuration = 0;
195
+      data.totalPrints++;
196
+      lastDuration = 0;
187
     }
197
     }
188
     return true;
198
     return true;
189
   }
199
   }
194
 // @Override
204
 // @Override
195
 bool PrintCounter::stop() {
205
 bool PrintCounter::stop() {
196
   #if ENABLED(DEBUG_PRINTCOUNTER)
206
   #if ENABLED(DEBUG_PRINTCOUNTER)
197
-    PrintCounter::debug(PSTR("stop"));
207
+    debug(PSTR("stop"));
198
   #endif
208
   #endif
199
 
209
 
200
   if (super::stop()) {
210
   if (super::stop()) {
201
-    this->data.finishedPrints++;
202
-    this->data.printTime += this->deltaDuration();
211
+    data.finishedPrints++;
212
+    data.printTime += deltaDuration();
203
 
213
 
204
-    if (this->duration() > this->data.longestPrint)
205
-      this->data.longestPrint = this->duration();
214
+    if (duration() > data.longestPrint)
215
+      data.longestPrint = duration();
206
 
216
 
207
-    this->saveStats();
217
+    saveStats();
208
     return true;
218
     return true;
209
   }
219
   }
210
   else return false;
220
   else return false;
213
 // @Override
223
 // @Override
214
 void PrintCounter::reset() {
224
 void PrintCounter::reset() {
215
   #if ENABLED(DEBUG_PRINTCOUNTER)
225
   #if ENABLED(DEBUG_PRINTCOUNTER)
216
-    PrintCounter::debug(PSTR("stop"));
226
+    debug(PSTR("stop"));
217
   #endif
227
   #endif
218
 
228
 
219
   super::reset();
229
   super::reset();
220
-  this->lastDuration = 0;
230
+  lastDuration = 0;
221
 }
231
 }
222
 
232
 
223
 #if ENABLED(DEBUG_PRINTCOUNTER)
233
 #if ENABLED(DEBUG_PRINTCOUNTER)
231
   }
241
   }
232
 #endif
242
 #endif
233
 
243
 
234
-
235
-PrintCounter print_job_timer = PrintCounter();
236
-
237
-#else
238
-
239
-#include "../libs/stopwatch.h"
240
-Stopwatch print_job_timer = Stopwatch();
241
-
242
 #endif // PRINTCOUNTER
244
 #endif // PRINTCOUNTER

+ 50
- 43
Marlin/src/module/printcounter.h 파일 보기

23
 #ifndef PRINTCOUNTER_H
23
 #ifndef PRINTCOUNTER_H
24
 #define PRINTCOUNTER_H
24
 #define PRINTCOUNTER_H
25
 
25
 
26
-#include "../inc/MarlinConfig.h"
27
 #include "../libs/stopwatch.h"
26
 #include "../libs/stopwatch.h"
28
 #include "../libs/duration_t.h"
27
 #include "../libs/duration_t.h"
28
+#include "../inc/MarlinConfig.h"
29
 
29
 
30
 // Print debug messages with M111 S2
30
 // Print debug messages with M111 S2
31
 //#define DEBUG_PRINTCOUNTER
31
 //#define DEBUG_PRINTCOUNTER
32
 
32
 
33
+#if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM)
34
+  // round up address to next page boundary (assuming 32 byte pages)
35
+  #define STATS_EEPROM_ADDRESS 0x40
36
+#else
37
+  #define STATS_EEPROM_ADDRESS 0x32
38
+#endif
39
+
33
 struct printStatistics {    // 16 bytes (20 with real doubles)
40
 struct printStatistics {    // 16 bytes (20 with real doubles)
34
   //const uint8_t magic;    // Magic header, it will always be 0x16
41
   //const uint8_t magic;    // Magic header, it will always be 0x16
35
   uint16_t totalPrints;     // Number of prints
42
   uint16_t totalPrints;     // Number of prints
43
   private:
50
   private:
44
     typedef Stopwatch super;
51
     typedef Stopwatch super;
45
 
52
 
46
-    printStatistics data;
53
+    #if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM) || defined(CPU_32_BIT)
54
+      typedef uint32_t promdress;
55
+    #else
56
+      typedef uint16_t promdress;
57
+    #endif
58
+
59
+    static printStatistics data;
47
 
60
 
48
     /**
61
     /**
49
      * @brief EEPROM address
62
      * @brief EEPROM address
50
      * @details Defines the start offset address where the data is stored.
63
      * @details Defines the start offset address where the data is stored.
51
      */
64
      */
52
-    #if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM)
53
-      // round up address to next page boundary (assuming 32 byte pages)
54
-      const uint32_t address = 0x40;
55
-    #elif defined(CPU_32_BIT)
56
-      const uint32_t address = 0x32;
57
-    #else
58
-      const uint16_t address = 0x32;
59
-    #endif
65
+    static const promdress address;
66
+
60
     /**
67
     /**
61
      * @brief Interval in seconds between counter updates
68
      * @brief Interval in seconds between counter updates
62
      * @details This const value defines what will be the time between each
69
      * @details This const value defines what will be the time between each
65
      * @note The max value for this option is 60(s), otherwise integer
72
      * @note The max value for this option is 60(s), otherwise integer
66
      * overflow will happen.
73
      * overflow will happen.
67
      */
74
      */
68
-    const uint16_t updateInterval = 10;
75
+    static const uint16_t updateInterval;
69
 
76
 
70
     /**
77
     /**
71
      * @brief Interval in seconds between EEPROM saves
78
      * @brief Interval in seconds between EEPROM saves
73
      * EEPROM save cycle, the development team recommends to set this value
80
      * EEPROM save cycle, the development team recommends to set this value
74
      * no lower than 3600 secs (1 hour).
81
      * no lower than 3600 secs (1 hour).
75
      */
82
      */
76
-    const uint16_t saveInterval = 3600;
83
+    static const uint16_t saveInterval;
77
 
84
 
78
     /**
85
     /**
79
      * @brief Timestamp of the last call to deltaDuration()
86
      * @brief Timestamp of the last call to deltaDuration()
80
-     * @details Stores the timestamp of the last deltaDuration(), this is
87
+     * @details Store the timestamp of the last deltaDuration(), this is
81
      * required due to the updateInterval cycle.
88
      * required due to the updateInterval cycle.
82
      */
89
      */
83
-    millis_t lastDuration;
90
+    static millis_t lastDuration;
84
 
91
 
85
     /**
92
     /**
86
-     * @brief Stats were loaded from EERPROM
93
+     * @brief Stats were loaded from EEPROM
87
      * @details If set to true it indicates if the statistical data was already
94
      * @details If set to true it indicates if the statistical data was already
88
      * loaded from the EEPROM.
95
      * loaded from the EEPROM.
89
      */
96
      */
90
-    bool loaded = false;
97
+    static bool loaded;
91
 
98
 
92
   protected:
99
   protected:
93
     /**
100
     /**
94
      * @brief dT since the last call
101
      * @brief dT since the last call
95
-     * @details Returns the elapsed time in seconds since the last call, this is
102
+     * @details Return the elapsed time in seconds since the last call, this is
96
      * used internally for print statistics accounting is not intended to be a
103
      * used internally for print statistics accounting is not intended to be a
97
      * user callable function.
104
      * user callable function.
98
      */
105
      */
99
-    millis_t deltaDuration();
106
+    static millis_t deltaDuration();
100
 
107
 
101
   public:
108
   public:
102
 
109
 
103
     /**
110
     /**
104
      * @brief Initialize the print counter
111
      * @brief Initialize the print counter
105
      */
112
      */
106
-    inline void init() {
113
+    static inline void init() {
107
       super::init();
114
       super::init();
108
-      this->loadStats();
115
+      loadStats();
109
     }
116
     }
110
 
117
 
111
     /**
118
     /**
112
-     * @brief Checks if Print Statistics has been loaded
113
-     * @details Returns true if the statistical data has been loaded.
119
+     * @brief Check if Print Statistics has been loaded
120
+     * @details Return true if the statistical data has been loaded.
114
      * @return bool
121
      * @return bool
115
      */
122
      */
116
-    bool isLoaded();
123
+    FORCE_INLINE static bool isLoaded() { return loaded; }
117
 
124
 
118
     /**
125
     /**
119
-     * @brief Increments the total filament used
126
+     * @brief Increment the total filament used
120
      * @details The total filament used counter will be incremented by "amount".
127
      * @details The total filament used counter will be incremented by "amount".
121
      *
128
      *
122
      * @param amount The amount of filament used in mm
129
      * @param amount The amount of filament used in mm
123
      */
130
      */
124
-    void incFilamentUsed(double const &amount);
131
+    static void incFilamentUsed(double const &amount);
125
 
132
 
126
     /**
133
     /**
127
-     * @brief Resets the Print Statistics
128
-     * @details Resets the statistics to zero and saves them to EEPROM creating
134
+     * @brief Reset the Print Statistics
135
+     * @details Reset the statistics to zero and saves them to EEPROM creating
129
      * also the magic header.
136
      * also the magic header.
130
      */
137
      */
131
-    void initStats();
138
+    static void initStats();
132
 
139
 
133
     /**
140
     /**
134
-     * @brief Loads the Print Statistics
135
-     * @details Loads the statistics from EEPROM
141
+     * @brief Load the Print Statistics
142
+     * @details Load the statistics from EEPROM
136
      */
143
      */
137
-    void loadStats();
144
+    static void loadStats();
138
 
145
 
139
     /**
146
     /**
140
-     * @brief Saves the Print Statistics
141
-     * @details Saves the statistics to EEPROM
147
+     * @brief Save the Print Statistics
148
+     * @details Save the statistics to EEPROM
142
      */
149
      */
143
-    void saveStats();
150
+    static void saveStats();
144
 
151
 
145
     /**
152
     /**
146
      * @brief Serial output the Print Statistics
153
      * @brief Serial output the Print Statistics
147
      * @details This function may change in the future, for now it directly
154
      * @details This function may change in the future, for now it directly
148
      * prints the statistical data to serial.
155
      * prints the statistical data to serial.
149
      */
156
      */
150
-    void showStats();
157
+    static void showStats();
151
 
158
 
152
     /**
159
     /**
153
      * @brief Return the currently loaded statistics
160
      * @brief Return the currently loaded statistics
154
      * @details Return the raw data, in the same structure used internally
161
      * @details Return the raw data, in the same structure used internally
155
      */
162
      */
156
-    printStatistics getStats() { return this->data; }
163
+    static printStatistics getStats() { return data; }
157
 
164
 
158
     /**
165
     /**
159
      * @brief Loop function
166
      * @brief Loop function
160
      * @details This function should be called at loop, it will take care of
167
      * @details This function should be called at loop, it will take care of
161
      * periodically save the statistical data to EEPROM and do time keeping.
168
      * periodically save the statistical data to EEPROM and do time keeping.
162
      */
169
      */
163
-    void tick();
170
+    static void tick();
164
 
171
 
165
     /**
172
     /**
166
      * The following functions are being overridden
173
      * The following functions are being overridden
167
      */
174
      */
168
-    bool start();
169
-    bool stop();
170
-    void reset();
175
+    static bool start();
176
+    static bool stop();
177
+    static void reset();
171
 
178
 
172
     #if ENABLED(DEBUG_PRINTCOUNTER)
179
     #if ENABLED(DEBUG_PRINTCOUNTER)
173
 
180
 
174
       /**
181
       /**
175
-       * @brief Prints a debug message
176
-       * @details Prints a simple debug message "PrintCounter::function"
182
+       * @brief Print a debug message
183
+       * @details Print a simple debug message
177
        */
184
        */
178
       static void debug(const char func[]);
185
       static void debug(const char func[]);
179
 
186
 
180
     #endif
187
     #endif
181
 };
188
 };
182
 
189
 
183
-// Print Job Timer
190
+// Global Print Job Timer instance
184
 #if ENABLED(PRINTCOUNTER)
191
 #if ENABLED(PRINTCOUNTER)
185
   extern PrintCounter print_job_timer;
192
   extern PrintCounter print_job_timer;
186
 #else
193
 #else

Loading…
취소
저장