Browse Source

Use static classes for job timers (#9938)

Scott Lahteine 6 years ago
parent
commit
36262a0479
No account linked to committer's email address

+ 3
- 5
Marlin/src/Marlin.cpp View File

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

+ 25
- 23
Marlin/src/libs/stopwatch.cpp View File

@@ -20,21 +20,23 @@
20 20
  *
21 21
  */
22 22
 
23
-#include "../Marlin.h"
24 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 32
 bool Stopwatch::stop() {
31 33
   #if ENABLED(DEBUG_STOPWATCH)
32 34
     Stopwatch::debug(PSTR("stop"));
33 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 40
     return true;
39 41
   }
40 42
   else return false;
@@ -45,9 +47,9 @@ bool Stopwatch::pause() {
45 47
     Stopwatch::debug(PSTR("pause"));
46 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 53
     return true;
52 54
   }
53 55
   else return false;
@@ -58,12 +60,12 @@ bool Stopwatch::start() {
58 60
     Stopwatch::debug(PSTR("start"));
59 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 69
     return true;
68 70
   }
69 71
   else return false;
@@ -74,23 +76,23 @@ void Stopwatch::reset() {
74 76
     Stopwatch::debug(PSTR("reset"));
75 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 85
 bool Stopwatch::isRunning() {
84
-  return (this->state == RUNNING) ? true : false;
86
+  return (state == RUNNING) ? true : false;
85 87
 }
86 88
 
87 89
 bool Stopwatch::isPaused() {
88
-  return (this->state == PAUSED) ? true : false;
90
+  return (state == PAUSED) ? true : false;
89 91
 }
90 92
 
91 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 98
 #if ENABLED(DEBUG_STOPWATCH)

+ 28
- 32
Marlin/src/libs/stopwatch.h View File

@@ -23,11 +23,12 @@
23 23
 #ifndef STOPWATCH_H
24 24
 #define STOPWATCH_H
25 25
 
26
-#include "../core/types.h"
27
-
28 26
 // Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
29 27
 //#define DEBUG_STOPWATCH
30 28
 
29
+#include "../core/macros.h"
30
+#include "../core/types.h"
31
+
31 32
 /**
32 33
  * @brief Stopwatch class
33 34
  * @details This class acts as a timer proving stopwatch functionality including
@@ -41,21 +42,16 @@ class Stopwatch {
41 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 50
   public:
50 51
     /**
51
-     * @brief Class constructor
52
-     */
53
-    Stopwatch();
54
-
55
-    /**
56 52
      * @brief Initialize the stopwatch
57 53
      */
58
-    inline void init() {}
54
+    FORCE_INLINE static void init() { reset(); }
59 55
 
60 56
     /**
61 57
      * @brief Stops the stopwatch
@@ -63,56 +59,56 @@ class Stopwatch {
63 59
      * no timer is currently running.
64 60
      * @return true is method was successful
65 61
      */
66
-    bool stop();
62
+    static bool stop();
67 63
 
68 64
     /**
69 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 67
      * no timer is currently running.
72 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 75
      * timer is already running.
80 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 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 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 103
      * @return the delta since starting the stopwatch
108 104
      */
109
-    millis_t duration();
105
+    static millis_t duration();
110 106
 
111 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 113
       static void debug(const char func[]);
118 114
 

+ 65
- 63
Marlin/src/module/printcounter.cpp View File

@@ -22,74 +22,84 @@
22 22
 
23 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 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 46
 millis_t PrintCounter::deltaDuration() {
32 47
   #if ENABLED(DEBUG_PRINTCOUNTER)
33
-    PrintCounter::debug(PSTR("deltaDuration"));
48
+    debug(PSTR("deltaDuration"));
34 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 56
 void PrintCounter::incFilamentUsed(double const &amount) {
46 57
   #if ENABLED(DEBUG_PRINTCOUNTER)
47
-    PrintCounter::debug(PSTR("incFilamentUsed"));
58
+    debug(PSTR("incFilamentUsed"));
48 59
   #endif
49 60
 
50 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 67
 void PrintCounter::initStats() {
58 68
   #if ENABLED(DEBUG_PRINTCOUNTER)
59
-    PrintCounter::debug(PSTR("initStats"));
69
+    debug(PSTR("initStats"));
60 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 79
 void PrintCounter::loadStats() {
70 80
   #if ENABLED(DEBUG_PRINTCOUNTER)
71
-    PrintCounter::debug(PSTR("loadStats"));
81
+    debug(PSTR("loadStats"));
72 82
   #endif
73 83
 
74 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 92
 void PrintCounter::saveStats() {
83 93
   #if ENABLED(DEBUG_PRINTCOUNTER)
84
-    PrintCounter::debug(PSTR("saveStats"));
94
+    debug(PSTR("saveStats"));
85 95
   #endif
86 96
 
87 97
   // Refuses to save data if object is not loaded
88
-  if (!this->isLoaded()) return;
98
+  if (!isLoaded()) return;
89 99
 
90 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 105
 void PrintCounter::showStats() {
@@ -98,19 +108,19 @@ void PrintCounter::showStats() {
98 108
   SERIAL_PROTOCOLPGM(MSG_STATS);
99 109
 
100 110
   SERIAL_ECHOPGM("Prints: ");
101
-  SERIAL_ECHO(this->data.totalPrints);
111
+  SERIAL_ECHO(data.totalPrints);
102 112
 
103 113
   SERIAL_ECHOPGM(", Finished: ");
104
-  SERIAL_ECHO(this->data.finishedPrints);
114
+  SERIAL_ECHO(data.finishedPrints);
105 115
 
106 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 120
   SERIAL_EOL();
111 121
   SERIAL_PROTOCOLPGM(MSG_STATS);
112 122
 
113
-  duration_t elapsed = this->data.printTime;
123
+  duration_t elapsed = data.printTime;
114 124
   elapsed.toString(buffer);
115 125
 
116 126
   SERIAL_ECHOPGM("Total time: ");
@@ -118,11 +128,11 @@ void PrintCounter::showStats() {
118 128
 
119 129
   #if ENABLED(DEBUG_PRINTCOUNTER)
120 130
     SERIAL_ECHOPGM(" (");
121
-    SERIAL_ECHO(this->data.printTime);
131
+    SERIAL_ECHO(data.printTime);
122 132
     SERIAL_CHAR(')');
123 133
   #endif
124 134
 
125
-  elapsed = this->data.longestPrint;
135
+  elapsed = data.longestPrint;
126 136
   elapsed.toString(buffer);
127 137
 
128 138
   SERIAL_ECHOPGM(", Longest job: ");
@@ -130,7 +140,7 @@ void PrintCounter::showStats() {
130 140
 
131 141
   #if ENABLED(DEBUG_PRINTCOUNTER)
132 142
     SERIAL_ECHOPGM(" (");
133
-    SERIAL_ECHO(this->data.longestPrint);
143
+    SERIAL_ECHO(data.longestPrint);
134 144
     SERIAL_CHAR(')');
135 145
   #endif
136 146
 
@@ -138,14 +148,14 @@ void PrintCounter::showStats() {
138 148
   SERIAL_PROTOCOLPGM(MSG_STATS);
139 149
 
140 150
   SERIAL_ECHOPGM("Filament used: ");
141
-  SERIAL_ECHO(this->data.filamentUsed / 1000);
151
+  SERIAL_ECHO(data.filamentUsed / 1000);
142 152
   SERIAL_CHAR('m');
143 153
 
144 154
   SERIAL_EOL();
145 155
 }
146 156
 
147 157
 void PrintCounter::tick() {
148
-  if (!this->isRunning()) return;
158
+  if (!isRunning()) return;
149 159
 
150 160
   static uint32_t update_last = millis(),
151 161
                   eeprom_last = millis();
@@ -153,37 +163,37 @@ void PrintCounter::tick() {
153 163
   millis_t now = millis();
154 164
 
155 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 168
   if (now - update_last >= i) {
159 169
     #if ENABLED(DEBUG_PRINTCOUNTER)
160
-      PrintCounter::debug(PSTR("tick"));
170
+      debug(PSTR("tick"));
161 171
     #endif
162 172
 
163
-    this->data.printTime += this->deltaDuration();
173
+    data.printTime += deltaDuration();
164 174
     update_last = now;
165 175
   }
166 176
 
167 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 179
   if (now - eeprom_last >= j) {
170 180
     eeprom_last = now;
171
-    this->saveStats();
181
+    saveStats();
172 182
   }
173 183
 }
174 184
 
175 185
 // @Override
176 186
 bool PrintCounter::start() {
177 187
   #if ENABLED(DEBUG_PRINTCOUNTER)
178
-    PrintCounter::debug(PSTR("start"));
188
+    debug(PSTR("start"));
179 189
   #endif
180 190
 
181
-  bool paused = this->isPaused();
191
+  bool paused = isPaused();
182 192
 
183 193
   if (super::start()) {
184 194
     if (!paused) {
185
-      this->data.totalPrints++;
186
-      this->lastDuration = 0;
195
+      data.totalPrints++;
196
+      lastDuration = 0;
187 197
     }
188 198
     return true;
189 199
   }
@@ -194,17 +204,17 @@ bool PrintCounter::start() {
194 204
 // @Override
195 205
 bool PrintCounter::stop() {
196 206
   #if ENABLED(DEBUG_PRINTCOUNTER)
197
-    PrintCounter::debug(PSTR("stop"));
207
+    debug(PSTR("stop"));
198 208
   #endif
199 209
 
200 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 218
     return true;
209 219
   }
210 220
   else return false;
@@ -213,11 +223,11 @@ bool PrintCounter::stop() {
213 223
 // @Override
214 224
 void PrintCounter::reset() {
215 225
   #if ENABLED(DEBUG_PRINTCOUNTER)
216
-    PrintCounter::debug(PSTR("stop"));
226
+    debug(PSTR("stop"));
217 227
   #endif
218 228
 
219 229
   super::reset();
220
-  this->lastDuration = 0;
230
+  lastDuration = 0;
221 231
 }
222 232
 
223 233
 #if ENABLED(DEBUG_PRINTCOUNTER)
@@ -231,12 +241,4 @@ void PrintCounter::reset() {
231 241
   }
232 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 244
 #endif // PRINTCOUNTER

+ 50
- 43
Marlin/src/module/printcounter.h View File

@@ -23,13 +23,20 @@
23 23
 #ifndef PRINTCOUNTER_H
24 24
 #define PRINTCOUNTER_H
25 25
 
26
-#include "../inc/MarlinConfig.h"
27 26
 #include "../libs/stopwatch.h"
28 27
 #include "../libs/duration_t.h"
28
+#include "../inc/MarlinConfig.h"
29 29
 
30 30
 // Print debug messages with M111 S2
31 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 40
 struct printStatistics {    // 16 bytes (20 with real doubles)
34 41
   //const uint8_t magic;    // Magic header, it will always be 0x16
35 42
   uint16_t totalPrints;     // Number of prints
@@ -43,20 +50,20 @@ class PrintCounter: public Stopwatch {
43 50
   private:
44 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 62
      * @brief EEPROM address
50 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 68
      * @brief Interval in seconds between counter updates
62 69
      * @details This const value defines what will be the time between each
@@ -65,7 +72,7 @@ class PrintCounter: public Stopwatch {
65 72
      * @note The max value for this option is 60(s), otherwise integer
66 73
      * overflow will happen.
67 74
      */
68
-    const uint16_t updateInterval = 10;
75
+    static const uint16_t updateInterval;
69 76
 
70 77
     /**
71 78
      * @brief Interval in seconds between EEPROM saves
@@ -73,114 +80,114 @@ class PrintCounter: public Stopwatch {
73 80
      * EEPROM save cycle, the development team recommends to set this value
74 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 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 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 94
      * @details If set to true it indicates if the statistical data was already
88 95
      * loaded from the EEPROM.
89 96
      */
90
-    bool loaded = false;
97
+    static bool loaded;
91 98
 
92 99
   protected:
93 100
     /**
94 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 103
      * used internally for print statistics accounting is not intended to be a
97 104
      * user callable function.
98 105
      */
99
-    millis_t deltaDuration();
106
+    static millis_t deltaDuration();
100 107
 
101 108
   public:
102 109
 
103 110
     /**
104 111
      * @brief Initialize the print counter
105 112
      */
106
-    inline void init() {
113
+    static inline void init() {
107 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 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 127
      * @details The total filament used counter will be incremented by "amount".
121 128
      *
122 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 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 153
      * @brief Serial output the Print Statistics
147 154
      * @details This function may change in the future, for now it directly
148 155
      * prints the statistical data to serial.
149 156
      */
150
-    void showStats();
157
+    static void showStats();
151 158
 
152 159
     /**
153 160
      * @brief Return the currently loaded statistics
154 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 166
      * @brief Loop function
160 167
      * @details This function should be called at loop, it will take care of
161 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 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 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 185
       static void debug(const char func[]);
179 186
 
180 187
     #endif
181 188
 };
182 189
 
183
-// Print Job Timer
190
+// Global Print Job Timer instance
184 191
 #if ENABLED(PRINTCOUNTER)
185 192
   extern PrintCounter print_job_timer;
186 193
 #else

Loading…
Cancel
Save