|
@@ -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
|
}
|