Browse Source

Printcounter improvements (#11689)

Scott Lahteine 7 years ago
parent
commit
d55f44edba
No account linked to committer's email address

+ 4
- 0
Marlin/src/inc/SanityCheck.h View File

1635
   #error "FAST_PWM_FAN only supported by 8 bit CPUs."
1635
   #error "FAST_PWM_FAN only supported by 8 bit CPUs."
1636
 #endif
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
 #endif // _SANITYCHECK_H_
1642
 #endif // _SANITYCHECK_H_

+ 6
- 16
Marlin/src/module/printcounter.cpp View File

39
 
39
 
40
 const PrintCounter::promdress PrintCounter::address = STATS_EEPROM_ADDRESS;
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
 millis_t PrintCounter::lastDuration;
42
 millis_t PrintCounter::lastDuration;
45
 bool PrintCounter::loaded = false;
43
 bool PrintCounter::loaded = false;
46
 
44
 
74
   data = { 0, 0, 0, 0, 0.0 };
72
   data = { 0, 0, 0, 0, 0.0 };
75
 
73
 
76
   saveStats();
74
   saveStats();
77
-
78
   persistentStore.access_start();
75
   persistentStore.access_start();
79
   persistentStore.write_data(address, (uint8_t)0x16);
76
   persistentStore.write_data(address, (uint8_t)0x16);
80
   persistentStore.access_finish();
77
   persistentStore.access_finish();
166
 void PrintCounter::tick() {
163
 void PrintCounter::tick() {
167
   if (!isRunning()) return;
164
   if (!isRunning()) return;
168
 
165
 
169
-  static uint32_t update_last = millis(),
170
-                  eeprom_last = millis();
171
-
172
   millis_t now = millis();
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
     #if ENABLED(DEBUG_PRINTCOUNTER)
170
     #if ENABLED(DEBUG_PRINTCOUNTER)
179
       debug(PSTR("tick"));
171
       debug(PSTR("tick"));
180
     #endif
172
     #endif
181
-
182
     data.printTime += deltaDuration();
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
     saveStats();
180
     saveStats();
191
   }
181
   }
192
 }
182
 }

+ 2
- 2
Marlin/src/module/printcounter.h View File

72
      * @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
73
      * overflow will happen.
73
      * overflow will happen.
74
      */
74
      */
75
-    static const uint16_t updateInterval;
75
+    static constexpr uint16_t updateInterval = 10;
76
 
76
 
77
     /**
77
     /**
78
      * @brief Interval in seconds between EEPROM saves
78
      * @brief Interval in seconds between EEPROM saves
80
      * EEPROM save cycle, the development team recommends to set this value
80
      * EEPROM save cycle, the development team recommends to set this value
81
      * no lower than 3600 secs (1 hour).
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
      * @brief Timestamp of the last call to deltaDuration()
86
      * @brief Timestamp of the last call to deltaDuration()

Loading…
Cancel
Save