Ver código fonte

Printcounter improvements (#11689)

Scott Lahteine 6 anos atrás
pai
commit
d55f44edba
Nenhuma conta vinculada ao e-mail do autor do commit

+ 4
- 0
Marlin/src/inc/SanityCheck.h Ver arquivo

@@ -1635,4 +1635,8 @@ static_assert(COUNT(sanity_arr_3) <= XYZE_N, "DEFAULT_MAX_ACCELERATION has too m
1635 1635
   #error "FAST_PWM_FAN only supported by 8 bit CPUs."
1636 1636
 #endif
1637 1637
 
1638
+#if ENABLED(PRINTCOUNTER) && DISABLED(EEPROM_SETTINGS)
1639
+  #error "PRINTCOUNTER requires EEPROM_SETTINGS. Please update your Configuration."
1640
+#endif
1641
+
1638 1642
 #endif // _SANITYCHECK_H_

+ 6
- 16
Marlin/src/module/printcounter.cpp Ver arquivo

@@ -39,8 +39,6 @@ printStatistics PrintCounter::data;
39 39
 
40 40
 const PrintCounter::promdress PrintCounter::address = STATS_EEPROM_ADDRESS;
41 41
 
42
-const uint16_t PrintCounter::updateInterval = 10;
43
-const uint16_t PrintCounter::saveInterval = 3600;
44 42
 millis_t PrintCounter::lastDuration;
45 43
 bool PrintCounter::loaded = false;
46 44
 
@@ -74,7 +72,6 @@ void PrintCounter::initStats() {
74 72
   data = { 0, 0, 0, 0, 0.0 };
75 73
 
76 74
   saveStats();
77
-
78 75
   persistentStore.access_start();
79 76
   persistentStore.write_data(address, (uint8_t)0x16);
80 77
   persistentStore.access_finish();
@@ -166,27 +163,20 @@ void PrintCounter::showStats() {
166 163
 void PrintCounter::tick() {
167 164
   if (!isRunning()) return;
168 165
 
169
-  static uint32_t update_last = millis(),
170
-                  eeprom_last = millis();
171
-
172 166
   millis_t now = millis();
173 167
 
174
-  // Trying to get the amount of calculations down to the bare min
175
-  const static uint16_t i = updateInterval * 1000;
176
-
177
-  if (now - update_last >= i) {
168
+  static uint32_t update_next; // = 0
169
+  if (ELAPSED(now, update_next)) {
178 170
     #if ENABLED(DEBUG_PRINTCOUNTER)
179 171
       debug(PSTR("tick"));
180 172
     #endif
181
-
182 173
     data.printTime += deltaDuration();
183
-    update_last = now;
174
+    update_next = now + updateInterval * 1000;
184 175
   }
185 176
 
186
-  // Trying to get the amount of calculations down to the bare min
187
-  const static millis_t j = saveInterval * 1000;
188
-  if (now - eeprom_last >= j) {
189
-    eeprom_last = now;
177
+  static uint32_t eeprom_next; // = 0
178
+  if (ELAPSED(now, eeprom_next)) {
179
+    eeprom_next = now + saveInterval * 1000;
190 180
     saveStats();
191 181
   }
192 182
 }

+ 2
- 2
Marlin/src/module/printcounter.h Ver arquivo

@@ -72,7 +72,7 @@ class PrintCounter: public Stopwatch {
72 72
      * @note The max value for this option is 60(s), otherwise integer
73 73
      * overflow will happen.
74 74
      */
75
-    static const uint16_t updateInterval;
75
+    static constexpr uint16_t updateInterval = 10;
76 76
 
77 77
     /**
78 78
      * @brief Interval in seconds between EEPROM saves
@@ -80,7 +80,7 @@ class PrintCounter: public Stopwatch {
80 80
      * EEPROM save cycle, the development team recommends to set this value
81 81
      * no lower than 3600 secs (1 hour).
82 82
      */
83
-    static const uint16_t saveInterval;
83
+    static constexpr uint16_t saveInterval = 3600;
84 84
 
85 85
     /**
86 86
      * @brief Timestamp of the last call to deltaDuration()

Carregando…
Cancelar
Salvar