Printcounter improvements (#11689)
This commit is contained in:
parent
6a3207391f
commit
d55f44edba
|
@ -1635,4 +1635,8 @@ static_assert(COUNT(sanity_arr_3) <= XYZE_N, "DEFAULT_MAX_ACCELERATION has too m
|
||||||
#error "FAST_PWM_FAN only supported by 8 bit CPUs."
|
#error "FAST_PWM_FAN only supported by 8 bit CPUs."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(PRINTCOUNTER) && DISABLED(EEPROM_SETTINGS)
|
||||||
|
#error "PRINTCOUNTER requires EEPROM_SETTINGS. Please update your Configuration."
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _SANITYCHECK_H_
|
#endif // _SANITYCHECK_H_
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ class PrintCounter: public Stopwatch {
|
||||||
* @note The max value for this option is 60(s), otherwise integer
|
* @note The max value for this option is 60(s), otherwise integer
|
||||||
* overflow will happen.
|
* overflow will happen.
|
||||||
*/
|
*/
|
||||||
static const uint16_t updateInterval;
|
static constexpr uint16_t updateInterval = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Interval in seconds between EEPROM saves
|
* @brief Interval in seconds between EEPROM saves
|
||||||
|
@ -80,7 +80,7 @@ class PrintCounter: public Stopwatch {
|
||||||
* EEPROM save cycle, the development team recommends to set this value
|
* EEPROM save cycle, the development team recommends to set this value
|
||||||
* no lower than 3600 secs (1 hour).
|
* no lower than 3600 secs (1 hour).
|
||||||
*/
|
*/
|
||||||
static const uint16_t saveInterval;
|
static constexpr uint16_t saveInterval = 3600;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timestamp of the last call to deltaDuration()
|
* @brief Timestamp of the last call to deltaDuration()
|
||||||
|
|
Loading…
Reference in a new issue