|
|
@ -22,74 +22,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(PRINTCOUNTER)
|
|
|
|
#if DISABLED(PRINTCOUNTER)
|
|
|
|
|
|
|
|
|
|
|
|
#include "printcounter.h"
|
|
|
|
#include "../libs/stopwatch.h"
|
|
|
|
|
|
|
|
Stopwatch print_job_timer; // Global Print Job Timer instance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else // PRINTCOUNTER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "printcounter.h"
|
|
|
|
#include "../Marlin.h"
|
|
|
|
#include "../Marlin.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PrintCounter print_job_timer; // Global Print Job Timer instance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printStatistics PrintCounter::data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const PrintCounter::promdress PrintCounter::address = STATS_EEPROM_ADDRESS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uint16_t PrintCounter::updateInterval = 10;
|
|
|
|
|
|
|
|
const uint16_t PrintCounter::saveInterval = 3600;
|
|
|
|
|
|
|
|
millis_t PrintCounter::lastDuration;
|
|
|
|
|
|
|
|
bool PrintCounter::loaded = false;
|
|
|
|
|
|
|
|
|
|
|
|
millis_t PrintCounter::deltaDuration() {
|
|
|
|
millis_t PrintCounter::deltaDuration() {
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
PrintCounter::debug(PSTR("deltaDuration"));
|
|
|
|
debug(PSTR("deltaDuration"));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
millis_t tmp = this->lastDuration;
|
|
|
|
millis_t tmp = lastDuration;
|
|
|
|
this->lastDuration = this->duration();
|
|
|
|
lastDuration = duration();
|
|
|
|
return this->lastDuration - tmp;
|
|
|
|
return lastDuration - tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool PrintCounter::isLoaded() {
|
|
|
|
|
|
|
|
return this->loaded;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrintCounter::incFilamentUsed(double const &amount) {
|
|
|
|
void PrintCounter::incFilamentUsed(double const &amount) {
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
PrintCounter::debug(PSTR("incFilamentUsed"));
|
|
|
|
debug(PSTR("incFilamentUsed"));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Refuses to update data if object is not loaded
|
|
|
|
// Refuses to update data if object is not loaded
|
|
|
|
if (!this->isLoaded()) return;
|
|
|
|
if (!isLoaded()) return;
|
|
|
|
|
|
|
|
|
|
|
|
this->data.filamentUsed += amount; // mm
|
|
|
|
data.filamentUsed += amount; // mm
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PrintCounter::initStats() {
|
|
|
|
void PrintCounter::initStats() {
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
PrintCounter::debug(PSTR("initStats"));
|
|
|
|
debug(PSTR("initStats"));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
this->loaded = true;
|
|
|
|
loaded = true;
|
|
|
|
this->data = { 0, 0, 0, 0, 0.0 };
|
|
|
|
data = { 0, 0, 0, 0, 0.0 };
|
|
|
|
|
|
|
|
|
|
|
|
this->saveStats();
|
|
|
|
saveStats();
|
|
|
|
eeprom_write_byte((uint8_t *) this->address, 0x16);
|
|
|
|
eeprom_write_byte((uint8_t*)address, 0x16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrintCounter::loadStats() {
|
|
|
|
void PrintCounter::loadStats() {
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
PrintCounter::debug(PSTR("loadStats"));
|
|
|
|
debug(PSTR("loadStats"));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// 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*)address) != 0x16) initStats();
|
|
|
|
else eeprom_read_block(&this->data,
|
|
|
|
else eeprom_read_block(&data,
|
|
|
|
(void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
|
|
|
|
(void*)(address + sizeof(uint8_t)), sizeof(printStatistics));
|
|
|
|
|
|
|
|
|
|
|
|
this->loaded = true;
|
|
|
|
loaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrintCounter::saveStats() {
|
|
|
|
void PrintCounter::saveStats() {
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
PrintCounter::debug(PSTR("saveStats"));
|
|
|
|
debug(PSTR("saveStats"));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Refuses to save data if object is not loaded
|
|
|
|
// Refuses to save data if object is not loaded
|
|
|
|
if (!this->isLoaded()) return;
|
|
|
|
if (!isLoaded()) return;
|
|
|
|
|
|
|
|
|
|
|
|
// Saves the struct to EEPROM
|
|
|
|
// Saves the struct to EEPROM
|
|
|
|
eeprom_update_block(&this->data,
|
|
|
|
eeprom_update_block(&data,
|
|
|
|
(void *)(this->address + sizeof(uint8_t)), sizeof(printStatistics));
|
|
|
|
(void*)(address + sizeof(uint8_t)), sizeof(printStatistics));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrintCounter::showStats() {
|
|
|
|
void PrintCounter::showStats() {
|
|
|
@ -98,19 +108,19 @@ void PrintCounter::showStats() {
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_STATS);
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_STATS);
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("Prints: ");
|
|
|
|
SERIAL_ECHOPGM("Prints: ");
|
|
|
|
SERIAL_ECHO(this->data.totalPrints);
|
|
|
|
SERIAL_ECHO(data.totalPrints);
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM(", Finished: ");
|
|
|
|
SERIAL_ECHOPGM(", Finished: ");
|
|
|
|
SERIAL_ECHO(this->data.finishedPrints);
|
|
|
|
SERIAL_ECHO(data.finishedPrints);
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM(", Failed: "); // Note: Removes 1 from failures with an active counter
|
|
|
|
SERIAL_ECHOPGM(", Failed: "); // Note: Removes 1 from failures with an active counter
|
|
|
|
SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints
|
|
|
|
SERIAL_ECHO(data.totalPrints - data.finishedPrints
|
|
|
|
- ((this->isRunning() || this->isPaused()) ? 1 : 0));
|
|
|
|
- ((isRunning() || isPaused()) ? 1 : 0));
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_EOL();
|
|
|
|
SERIAL_EOL();
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_STATS);
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_STATS);
|
|
|
|
|
|
|
|
|
|
|
|
duration_t elapsed = this->data.printTime;
|
|
|
|
duration_t elapsed = data.printTime;
|
|
|
|
elapsed.toString(buffer);
|
|
|
|
elapsed.toString(buffer);
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("Total time: ");
|
|
|
|
SERIAL_ECHOPGM("Total time: ");
|
|
|
@ -118,11 +128,11 @@ void PrintCounter::showStats() {
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
SERIAL_ECHOPGM(" (");
|
|
|
|
SERIAL_ECHOPGM(" (");
|
|
|
|
SERIAL_ECHO(this->data.printTime);
|
|
|
|
SERIAL_ECHO(data.printTime);
|
|
|
|
SERIAL_CHAR(')');
|
|
|
|
SERIAL_CHAR(')');
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
elapsed = this->data.longestPrint;
|
|
|
|
elapsed = data.longestPrint;
|
|
|
|
elapsed.toString(buffer);
|
|
|
|
elapsed.toString(buffer);
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM(", Longest job: ");
|
|
|
|
SERIAL_ECHOPGM(", Longest job: ");
|
|
|
@ -130,7 +140,7 @@ void PrintCounter::showStats() {
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
SERIAL_ECHOPGM(" (");
|
|
|
|
SERIAL_ECHOPGM(" (");
|
|
|
|
SERIAL_ECHO(this->data.longestPrint);
|
|
|
|
SERIAL_ECHO(data.longestPrint);
|
|
|
|
SERIAL_CHAR(')');
|
|
|
|
SERIAL_CHAR(')');
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
@ -138,14 +148,14 @@ void PrintCounter::showStats() {
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_STATS);
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_STATS);
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("Filament used: ");
|
|
|
|
SERIAL_ECHOPGM("Filament used: ");
|
|
|
|
SERIAL_ECHO(this->data.filamentUsed / 1000);
|
|
|
|
SERIAL_ECHO(data.filamentUsed / 1000);
|
|
|
|
SERIAL_CHAR('m');
|
|
|
|
SERIAL_CHAR('m');
|
|
|
|
|
|
|
|
|
|
|
|
SERIAL_EOL();
|
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrintCounter::tick() {
|
|
|
|
void PrintCounter::tick() {
|
|
|
|
if (!this->isRunning()) return;
|
|
|
|
if (!isRunning()) return;
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t update_last = millis(),
|
|
|
|
static uint32_t update_last = millis(),
|
|
|
|
eeprom_last = millis();
|
|
|
|
eeprom_last = millis();
|
|
|
@ -153,37 +163,37 @@ void PrintCounter::tick() {
|
|
|
|
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 = updateInterval * 1000;
|
|
|
|
|
|
|
|
|
|
|
|
if (now - update_last >= i) {
|
|
|
|
if (now - update_last >= i) {
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
PrintCounter::debug(PSTR("tick"));
|
|
|
|
debug(PSTR("tick"));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
this->data.printTime += this->deltaDuration();
|
|
|
|
data.printTime += deltaDuration();
|
|
|
|
update_last = 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 = saveInterval * 1000;
|
|
|
|
if (now - eeprom_last >= j) {
|
|
|
|
if (now - eeprom_last >= j) {
|
|
|
|
eeprom_last = now;
|
|
|
|
eeprom_last = now;
|
|
|
|
this->saveStats();
|
|
|
|
saveStats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
// @Override
|
|
|
|
bool PrintCounter::start() {
|
|
|
|
bool PrintCounter::start() {
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
PrintCounter::debug(PSTR("start"));
|
|
|
|
debug(PSTR("start"));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
bool paused = this->isPaused();
|
|
|
|
bool paused = isPaused();
|
|
|
|
|
|
|
|
|
|
|
|
if (super::start()) {
|
|
|
|
if (super::start()) {
|
|
|
|
if (!paused) {
|
|
|
|
if (!paused) {
|
|
|
|
this->data.totalPrints++;
|
|
|
|
data.totalPrints++;
|
|
|
|
this->lastDuration = 0;
|
|
|
|
lastDuration = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -194,17 +204,17 @@ bool PrintCounter::start() {
|
|
|
|
// @Override
|
|
|
|
// @Override
|
|
|
|
bool PrintCounter::stop() {
|
|
|
|
bool PrintCounter::stop() {
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
PrintCounter::debug(PSTR("stop"));
|
|
|
|
debug(PSTR("stop"));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if (super::stop()) {
|
|
|
|
if (super::stop()) {
|
|
|
|
this->data.finishedPrints++;
|
|
|
|
data.finishedPrints++;
|
|
|
|
this->data.printTime += this->deltaDuration();
|
|
|
|
data.printTime += deltaDuration();
|
|
|
|
|
|
|
|
|
|
|
|
if (this->duration() > this->data.longestPrint)
|
|
|
|
if (duration() > data.longestPrint)
|
|
|
|
this->data.longestPrint = this->duration();
|
|
|
|
data.longestPrint = duration();
|
|
|
|
|
|
|
|
|
|
|
|
this->saveStats();
|
|
|
|
saveStats();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
else return false;
|
|
|
@ -213,11 +223,11 @@ bool PrintCounter::stop() {
|
|
|
|
// @Override
|
|
|
|
// @Override
|
|
|
|
void PrintCounter::reset() {
|
|
|
|
void PrintCounter::reset() {
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
PrintCounter::debug(PSTR("stop"));
|
|
|
|
debug(PSTR("stop"));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
super::reset();
|
|
|
|
super::reset();
|
|
|
|
this->lastDuration = 0;
|
|
|
|
lastDuration = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
|
|
@ -231,12 +241,4 @@ void PrintCounter::reset() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PrintCounter print_job_timer = PrintCounter();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "../libs/stopwatch.h"
|
|
|
|
|
|
|
|
Stopwatch print_job_timer = Stopwatch();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PRINTCOUNTER
|
|
|
|
#endif // PRINTCOUNTER
|
|
|
|