|
@ -41,13 +41,25 @@ bool PrintCounter::isLoaded() { |
|
|
return this->loaded; |
|
|
return this->loaded; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PrintCounter::incFilamentUsed(double const &amount) { |
|
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
|
|
|
|
PrintCounter::debug(PSTR("incFilamentUsed")); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// Refuses to update data if object is not loaded
|
|
|
|
|
|
if (!this->isLoaded()) return; |
|
|
|
|
|
|
|
|
|
|
|
this->data.filamentUsed += amount; // mm
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PrintCounter::initStats() { |
|
|
void PrintCounter::initStats() { |
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
|
PrintCounter::debug(PSTR("initStats")); |
|
|
PrintCounter::debug(PSTR("initStats")); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
this->loaded = true; |
|
|
this->loaded = true; |
|
|
this->data = { 0, 0, 0, 0 }; |
|
|
this->data = { 0, 0, 0, 0, 0.0 }; |
|
|
|
|
|
|
|
|
this->saveStats(); |
|
|
this->saveStats(); |
|
|
eeprom_write_byte((uint8_t *) this->address, 0x16); |
|
|
eeprom_write_byte((uint8_t *) this->address, 0x16); |
|
@ -60,7 +72,8 @@ void PrintCounter::loadStats() { |
|
|
|
|
|
|
|
|
// Checks if the EEPROM block is initialized
|
|
|
// Checks if the EEPROM block is initialized
|
|
|
if (eeprom_read_byte((uint8_t *) this->address) != 0x16) this->initStats(); |
|
|
if (eeprom_read_byte((uint8_t *) this->address) != 0x16) this->initStats(); |
|
|
else eeprom_read_block(&this->data, (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics)); |
|
|
else eeprom_read_block(&this->data, |
|
|
|
|
|
(void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics)); |
|
|
|
|
|
|
|
|
this->loaded = true; |
|
|
this->loaded = true; |
|
|
} |
|
|
} |
|
@ -70,31 +83,40 @@ void PrintCounter::saveStats() { |
|
|
PrintCounter::debug(PSTR("saveStats")); |
|
|
PrintCounter::debug(PSTR("saveStats")); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
// Refuses to save data is object is not loaded
|
|
|
// Refuses to save data if object is not loaded
|
|
|
if (!this->isLoaded()) return; |
|
|
if (!this->isLoaded()) return; |
|
|
|
|
|
|
|
|
// Saves the struct to EEPROM
|
|
|
// Saves the struct to EEPROM
|
|
|
eeprom_update_block(&this->data, (void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics)); |
|
|
eeprom_update_block(&this->data, |
|
|
|
|
|
(void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void PrintCounter::showStats() { |
|
|
void PrintCounter::showStats() { |
|
|
SERIAL_ECHOPGM("Print statistics: Total: "); |
|
|
SERIAL_PROTOCOLPGM(MSG_STATS); |
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("Prints: "); |
|
|
SERIAL_ECHO(this->data.totalPrints); |
|
|
SERIAL_ECHO(this->data.totalPrints); |
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM(", Finished: "); |
|
|
SERIAL_ECHOPGM(", Finished: "); |
|
|
SERIAL_ECHO(this->data.finishedPrints); |
|
|
SERIAL_ECHO(this->data.finishedPrints); |
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM(", Failed: "); |
|
|
SERIAL_ECHOPGM(", Failed: "); // Note: Removes 1 from failures with an active counter
|
|
|
SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints |
|
|
SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints |
|
|
- ((this->isRunning() || this->isPaused()) ? 1 : 0)); // Removes 1 from failures with an active counter
|
|
|
- ((this->isRunning() || this->isPaused()) ? 1 : 0)); |
|
|
|
|
|
|
|
|
|
|
|
SERIAL_EOL; |
|
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_STATS); |
|
|
|
|
|
|
|
|
millis_t t = this->data.printTime / 60; // minutes from seconds
|
|
|
uint32_t t = this->data.printTime / 60; |
|
|
SERIAL_ECHOPGM(", Total print time: "); |
|
|
SERIAL_ECHOPGM("Total time: "); |
|
|
SERIAL_ECHO(t / 60); // hours
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHO(t / 60 / 24); |
|
|
|
|
|
SERIAL_ECHOPGM("d "); |
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHO((t / 60) % 24); |
|
|
SERIAL_ECHOPGM("h "); |
|
|
SERIAL_ECHOPGM("h "); |
|
|
SERIAL_ECHO(t % 60); // minutes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHO(t % 60); |
|
|
SERIAL_ECHOPGM("min"); |
|
|
SERIAL_ECHOPGM("min"); |
|
|
|
|
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
@ -103,34 +125,58 @@ void PrintCounter::showStats() { |
|
|
SERIAL_ECHOPGM(")"); |
|
|
SERIAL_ECHOPGM(")"); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
// @todo longestPrint missing implementation
|
|
|
uint32_t l = this->data.longestPrint / 60; |
|
|
|
|
|
SERIAL_ECHOPGM(", Longest job: "); |
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHO(l / 60 / 24); |
|
|
|
|
|
SERIAL_ECHOPGM("d "); |
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHO((l / 60) % 24); |
|
|
|
|
|
SERIAL_ECHOPGM("h "); |
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHO(l % 60); |
|
|
|
|
|
SERIAL_ECHOPGM("min"); |
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
|
|
|
|
SERIAL_ECHOPGM(" ("); |
|
|
|
|
|
SERIAL_ECHO(this->data.longestPrint); |
|
|
|
|
|
SERIAL_ECHOPGM(")"); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
SERIAL_EOL; |
|
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_STATS); |
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("Filament used: "); |
|
|
|
|
|
SERIAL_ECHO(this->data.filamentUsed / 1000); |
|
|
|
|
|
SERIAL_ECHOPGM("m"); |
|
|
|
|
|
|
|
|
SERIAL_EOL; |
|
|
SERIAL_EOL; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void PrintCounter::tick() { |
|
|
void PrintCounter::tick() { |
|
|
if (!this->isRunning()) return; |
|
|
if (!this->isRunning()) return; |
|
|
|
|
|
|
|
|
static millis_t update_before = millis(), |
|
|
static uint32_t update_last = millis(), |
|
|
eeprom_before = millis(); |
|
|
eeprom_last = millis(); |
|
|
|
|
|
|
|
|
millis_t now = millis(); |
|
|
millis_t now = millis(); |
|
|
|
|
|
|
|
|
// Trying to get the amount of calculations down to the bare min
|
|
|
// Trying to get the amount of calculations down to the bare min
|
|
|
const static uint16_t i = this->updateInterval * 1000; |
|
|
const static uint16_t i = this->updateInterval * 1000; |
|
|
|
|
|
|
|
|
if (now - update_before >= i) { |
|
|
if (now - update_last >= i) { |
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
|
#if ENABLED(DEBUG_PRINTCOUNTER) |
|
|
PrintCounter::debug(PSTR("tick")); |
|
|
PrintCounter::debug(PSTR("tick")); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
this->data.printTime += this->deltaDuration(); |
|
|
this->data.printTime += this->deltaDuration(); |
|
|
update_before = now; |
|
|
update_last = now; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Trying to get the amount of calculations down to the bare min
|
|
|
// Trying to get the amount of calculations down to the bare min
|
|
|
const static millis_t j = this->saveInterval * 1000; |
|
|
const static millis_t j = this->saveInterval * 1000; |
|
|
if (now - eeprom_before >= j) { |
|
|
if (now - eeprom_last >= j) { |
|
|
eeprom_before = now; |
|
|
eeprom_last = now; |
|
|
this->saveStats(); |
|
|
this->saveStats(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -162,6 +208,10 @@ bool PrintCounter::stop() { |
|
|
if (super::stop()) { |
|
|
if (super::stop()) { |
|
|
this->data.finishedPrints++; |
|
|
this->data.finishedPrints++; |
|
|
this->data.printTime += this->deltaDuration(); |
|
|
this->data.printTime += this->deltaDuration(); |
|
|
|
|
|
|
|
|
|
|
|
if (this->duration() > this->data.longestPrint) |
|
|
|
|
|
this->data.longestPrint = this->duration(); |
|
|
|
|
|
|
|
|
this->saveStats(); |
|
|
this->saveStats(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|