|
@ -39,8 +39,6 @@ printStatistics PrintCounter::data; |
|
|
|
|
|
|
|
|
const PrintCounter::promdress PrintCounter::address = STATS_EEPROM_ADDRESS; |
|
|
const PrintCounter::promdress PrintCounter::address = STATS_EEPROM_ADDRESS; |
|
|
|
|
|
|
|
|
const uint16_t PrintCounter::updateInterval = 10; |
|
|
|
|
|
const uint16_t PrintCounter::saveInterval = 3600; |
|
|
|
|
|
millis_t PrintCounter::lastDuration; |
|
|
millis_t PrintCounter::lastDuration; |
|
|
bool PrintCounter::loaded = false; |
|
|
bool PrintCounter::loaded = false; |
|
|
|
|
|
|
|
@ -74,7 +72,6 @@ void PrintCounter::initStats() { |
|
|
data = { 0, 0, 0, 0, 0.0 }; |
|
|
data = { 0, 0, 0, 0, 0.0 }; |
|
|
|
|
|
|
|
|
saveStats(); |
|
|
saveStats(); |
|
|
|
|
|
|
|
|
persistentStore.access_start(); |
|
|
persistentStore.access_start(); |
|
|
persistentStore.write_data(address, (uint8_t)0x16); |
|
|
persistentStore.write_data(address, (uint8_t)0x16); |
|
|
persistentStore.access_finish(); |
|
|
persistentStore.access_finish(); |
|
@ -166,27 +163,20 @@ void PrintCounter::showStats() { |
|
|
void PrintCounter::tick() { |
|
|
void PrintCounter::tick() { |
|
|
if (!isRunning()) return; |
|
|
if (!isRunning()) return; |
|
|
|
|
|
|
|
|
static uint32_t update_last = millis(), |
|
|
|
|
|
eeprom_last = millis(); |
|
|
|
|
|
|
|
|
|
|
|
millis_t now = millis(); |
|
|
millis_t now = millis(); |
|
|
|
|
|
|
|
|
// Trying to get the amount of calculations down to the bare min
|
|
|
static uint32_t update_next; // = 0
|
|
|
const static uint16_t i = updateInterval * 1000; |
|
|
if (ELAPSED(now, update_next)) { |
|
|
|
|
|
|
|
|
if (now - update_last >= i) { |
|
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
|
debug(PSTR("tick")); |
|
|
debug(PSTR("tick")); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
data.printTime += deltaDuration(); |
|
|
data.printTime += deltaDuration(); |
|
|
update_last = now; |
|
|
update_next = now + updateInterval * 1000; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Trying to get the amount of calculations down to the bare min
|
|
|
static uint32_t eeprom_next; // = 0
|
|
|
const static millis_t j = saveInterval * 1000; |
|
|
if (ELAPSED(now, eeprom_next)) { |
|
|
if (now - eeprom_last >= j) { |
|
|
eeprom_next = now + saveInterval * 1000; |
|
|
eeprom_last = now; |
|
|
|
|
|
saveStats(); |
|
|
saveStats(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|