Use static classes for job timers (#9938)
This commit is contained in:
parent
930720bbbb
commit
36262a0479
@ -731,10 +731,6 @@ void setup() {
|
|||||||
// This also updates variables in the planner, elsewhere
|
// This also updates variables in the planner, elsewhere
|
||||||
(void)settings.load();
|
(void)settings.load();
|
||||||
|
|
||||||
#if ENABLED(PRINTCOUNTER)
|
|
||||||
print_job_timer.init();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_M206_COMMAND
|
#if HAS_M206_COMMAND
|
||||||
// Initialize current position based on home_offset
|
// Initialize current position based on home_offset
|
||||||
COPY(current_position, home_offset);
|
COPY(current_position, home_offset);
|
||||||
@ -747,6 +743,8 @@ void setup() {
|
|||||||
|
|
||||||
thermalManager.init(); // Initialize temperature loop
|
thermalManager.init(); // Initialize temperature loop
|
||||||
|
|
||||||
|
print_job_timer.init(); // Initial setup of print job timer
|
||||||
|
|
||||||
stepper.init(); // Initialize stepper, this enables interrupts!
|
stepper.init(); // Initialize stepper, this enables interrupts!
|
||||||
|
|
||||||
#if HAS_SERVOS
|
#if HAS_SERVOS
|
||||||
|
@ -20,21 +20,23 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../Marlin.h"
|
|
||||||
#include "stopwatch.h"
|
#include "stopwatch.h"
|
||||||
|
|
||||||
Stopwatch::Stopwatch() {
|
#include "../inc/MarlinConfig.h"
|
||||||
this->reset();
|
|
||||||
}
|
Stopwatch::State Stopwatch::state;
|
||||||
|
millis_t Stopwatch::accumulator;
|
||||||
|
millis_t Stopwatch::startTimestamp;
|
||||||
|
millis_t Stopwatch::stopTimestamp;
|
||||||
|
|
||||||
bool Stopwatch::stop() {
|
bool Stopwatch::stop() {
|
||||||
#if ENABLED(DEBUG_STOPWATCH)
|
#if ENABLED(DEBUG_STOPWATCH)
|
||||||
Stopwatch::debug(PSTR("stop"));
|
Stopwatch::debug(PSTR("stop"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (this->isRunning() || this->isPaused()) {
|
if (isRunning() || isPaused()) {
|
||||||
this->state = STOPPED;
|
state = STOPPED;
|
||||||
this->stopTimestamp = millis();
|
stopTimestamp = millis();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
@ -45,9 +47,9 @@ bool Stopwatch::pause() {
|
|||||||
Stopwatch::debug(PSTR("pause"));
|
Stopwatch::debug(PSTR("pause"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (this->isRunning()) {
|
if (isRunning()) {
|
||||||
this->state = PAUSED;
|
state = PAUSED;
|
||||||
this->stopTimestamp = millis();
|
stopTimestamp = millis();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
@ -58,12 +60,12 @@ bool Stopwatch::start() {
|
|||||||
Stopwatch::debug(PSTR("start"));
|
Stopwatch::debug(PSTR("start"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!this->isRunning()) {
|
if (!isRunning()) {
|
||||||
if (this->isPaused()) this->accumulator = this->duration();
|
if (isPaused()) accumulator = duration();
|
||||||
else this->reset();
|
else reset();
|
||||||
|
|
||||||
this->state = RUNNING;
|
state = RUNNING;
|
||||||
this->startTimestamp = millis();
|
startTimestamp = millis();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
@ -74,23 +76,23 @@ void Stopwatch::reset() {
|
|||||||
Stopwatch::debug(PSTR("reset"));
|
Stopwatch::debug(PSTR("reset"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
this->state = STOPPED;
|
state = STOPPED;
|
||||||
this->startTimestamp = 0;
|
startTimestamp = 0;
|
||||||
this->stopTimestamp = 0;
|
stopTimestamp = 0;
|
||||||
this->accumulator = 0;
|
accumulator = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stopwatch::isRunning() {
|
bool Stopwatch::isRunning() {
|
||||||
return (this->state == RUNNING) ? true : false;
|
return (state == RUNNING) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stopwatch::isPaused() {
|
bool Stopwatch::isPaused() {
|
||||||
return (this->state == PAUSED) ? true : false;
|
return (state == PAUSED) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
millis_t Stopwatch::duration() {
|
millis_t Stopwatch::duration() {
|
||||||
return (((this->isRunning()) ? millis() : this->stopTimestamp)
|
return (((isRunning()) ? millis() : stopTimestamp)
|
||||||
- this->startTimestamp) / 1000UL + this->accumulator;
|
- startTimestamp) / 1000UL + accumulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLED(DEBUG_STOPWATCH)
|
#if ENABLED(DEBUG_STOPWATCH)
|
||||||
|
@ -23,11 +23,12 @@
|
|||||||
#ifndef STOPWATCH_H
|
#ifndef STOPWATCH_H
|
||||||
#define STOPWATCH_H
|
#define STOPWATCH_H
|
||||||
|
|
||||||
#include "../core/types.h"
|
|
||||||
|
|
||||||
// Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
|
// Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
|
||||||
//#define DEBUG_STOPWATCH
|
//#define DEBUG_STOPWATCH
|
||||||
|
|
||||||
|
#include "../core/macros.h"
|
||||||
|
#include "../core/types.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stopwatch class
|
* @brief Stopwatch class
|
||||||
* @details This class acts as a timer proving stopwatch functionality including
|
* @details This class acts as a timer proving stopwatch functionality including
|
||||||
@ -41,21 +42,16 @@ class Stopwatch {
|
|||||||
PAUSED
|
PAUSED
|
||||||
};
|
};
|
||||||
|
|
||||||
Stopwatch::State state;
|
static Stopwatch::State state;
|
||||||
millis_t accumulator;
|
static millis_t accumulator;
|
||||||
millis_t startTimestamp;
|
static millis_t startTimestamp;
|
||||||
millis_t stopTimestamp;
|
static millis_t stopTimestamp;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* @brief Class constructor
|
|
||||||
*/
|
|
||||||
Stopwatch();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the stopwatch
|
* @brief Initialize the stopwatch
|
||||||
*/
|
*/
|
||||||
inline void init() {}
|
FORCE_INLINE static void init() { reset(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stops the stopwatch
|
* @brief Stops the stopwatch
|
||||||
@ -63,56 +59,56 @@ class Stopwatch {
|
|||||||
* no timer is currently running.
|
* no timer is currently running.
|
||||||
* @return true is method was successful
|
* @return true is method was successful
|
||||||
*/
|
*/
|
||||||
bool stop();
|
static bool stop();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Pause the stopwatch
|
* @brief Pause the stopwatch
|
||||||
* @details Pauses the running timer, it will silently ignore the request if
|
* @details Pause the running timer, it will silently ignore the request if
|
||||||
* no timer is currently running.
|
* no timer is currently running.
|
||||||
* @return true is method was successful
|
* @return true is method was successful
|
||||||
*/
|
*/
|
||||||
bool pause();
|
static bool pause();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Starts the stopwatch
|
* @brief Start the stopwatch
|
||||||
* @details Starts the timer, it will silently ignore the request if the
|
* @details Start the timer, it will silently ignore the request if the
|
||||||
* timer is already running.
|
* timer is already running.
|
||||||
* @return true is method was successful
|
* @return true is method was successful
|
||||||
*/
|
*/
|
||||||
bool start();
|
static bool start();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Resets the stopwatch
|
* @brief Reset the stopwatch
|
||||||
* @details Resets all settings to their default values.
|
* @details Reset all settings to their default values.
|
||||||
*/
|
*/
|
||||||
void reset();
|
static void reset();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if the timer is running
|
* @brief Check if the timer is running
|
||||||
* @details Returns true if the timer is currently running, false otherwise.
|
* @details Return true if the timer is currently running, false otherwise.
|
||||||
* @return true if stopwatch is running
|
* @return true if stopwatch is running
|
||||||
*/
|
*/
|
||||||
bool isRunning();
|
static bool isRunning();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if the timer is paused
|
* @brief Check if the timer is paused
|
||||||
* @details Returns true if the timer is currently paused, false otherwise.
|
* @details Return true if the timer is currently paused, false otherwise.
|
||||||
* @return true if stopwatch is paused
|
* @return true if stopwatch is paused
|
||||||
*/
|
*/
|
||||||
bool isPaused();
|
static bool isPaused();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the running time
|
* @brief Get the running time
|
||||||
* @details Returns the total number of seconds the timer has been running.
|
* @details Return the total number of seconds the timer has been running.
|
||||||
* @return the delta since starting the stopwatch
|
* @return the delta since starting the stopwatch
|
||||||
*/
|
*/
|
||||||
millis_t duration();
|
static millis_t duration();
|
||||||
|
|
||||||
#ifdef DEBUG_STOPWATCH
|
#ifdef DEBUG_STOPWATCH
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints a debug message
|
* @brief Print a debug message
|
||||||
* @details Prints a simple debug message "Stopwatch::function"
|
* @details Print a simple debug message "Stopwatch::function"
|
||||||
*/
|
*/
|
||||||
static void debug(const char func[]);
|
static void debug(const char func[]);
|
||||||
|
|
||||||
|
@ -22,74 +22,84 @@
|
|||||||
|
|
||||||
#include "../inc/MarlinConfig.h"
|
#include "../inc/MarlinConfig.h"
|
||||||
|
|
||||||
#if ENABLED(PRINTCOUNTER)
|
#if DISABLED(PRINTCOUNTER)
|
||||||
|
|
||||||
|
#include "../libs/stopwatch.h"
|
||||||
|
Stopwatch print_job_timer; // Global Print Job Timer instance
|
||||||
|
|
||||||
|
#else // PRINTCOUNTER
|
||||||
|
|
||||||
#include "printcounter.h"
|
#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
|
||||||
|
@ -23,13 +23,20 @@
|
|||||||
#ifndef PRINTCOUNTER_H
|
#ifndef PRINTCOUNTER_H
|
||||||
#define PRINTCOUNTER_H
|
#define PRINTCOUNTER_H
|
||||||
|
|
||||||
#include "../inc/MarlinConfig.h"
|
|
||||||
#include "../libs/stopwatch.h"
|
#include "../libs/stopwatch.h"
|
||||||
#include "../libs/duration_t.h"
|
#include "../libs/duration_t.h"
|
||||||
|
#include "../inc/MarlinConfig.h"
|
||||||
|
|
||||||
// Print debug messages with M111 S2
|
// Print debug messages with M111 S2
|
||||||
//#define DEBUG_PRINTCOUNTER
|
//#define DEBUG_PRINTCOUNTER
|
||||||
|
|
||||||
|
#if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM)
|
||||||
|
// round up address to next page boundary (assuming 32 byte pages)
|
||||||
|
#define STATS_EEPROM_ADDRESS 0x40
|
||||||
|
#else
|
||||||
|
#define STATS_EEPROM_ADDRESS 0x32
|
||||||
|
#endif
|
||||||
|
|
||||||
struct printStatistics { // 16 bytes (20 with real doubles)
|
struct printStatistics { // 16 bytes (20 with real doubles)
|
||||||
//const uint8_t magic; // Magic header, it will always be 0x16
|
//const uint8_t magic; // Magic header, it will always be 0x16
|
||||||
uint16_t totalPrints; // Number of prints
|
uint16_t totalPrints; // Number of prints
|
||||||
@ -43,20 +50,20 @@ class PrintCounter: public Stopwatch {
|
|||||||
private:
|
private:
|
||||||
typedef Stopwatch super;
|
typedef Stopwatch super;
|
||||||
|
|
||||||
printStatistics data;
|
#if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM) || defined(CPU_32_BIT)
|
||||||
|
typedef uint32_t promdress;
|
||||||
|
#else
|
||||||
|
typedef uint16_t promdress;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static printStatistics data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief EEPROM address
|
* @brief EEPROM address
|
||||||
* @details Defines the start offset address where the data is stored.
|
* @details Defines the start offset address where the data is stored.
|
||||||
*/
|
*/
|
||||||
#if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM)
|
static const promdress address;
|
||||||
// round up address to next page boundary (assuming 32 byte pages)
|
|
||||||
const uint32_t address = 0x40;
|
|
||||||
#elif defined(CPU_32_BIT)
|
|
||||||
const uint32_t address = 0x32;
|
|
||||||
#else
|
|
||||||
const uint16_t address = 0x32;
|
|
||||||
#endif
|
|
||||||
/**
|
/**
|
||||||
* @brief Interval in seconds between counter updates
|
* @brief Interval in seconds between counter updates
|
||||||
* @details This const value defines what will be the time between each
|
* @details This const value defines what will be the time between each
|
||||||
@ -65,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.
|
||||||
*/
|
*/
|
||||||
const uint16_t updateInterval = 10;
|
static const uint16_t updateInterval;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Interval in seconds between EEPROM saves
|
* @brief Interval in seconds between EEPROM saves
|
||||||
@ -73,114 +80,114 @@ 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).
|
||||||
*/
|
*/
|
||||||
const uint16_t saveInterval = 3600;
|
static const uint16_t saveInterval;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Timestamp of the last call to deltaDuration()
|
* @brief Timestamp of the last call to deltaDuration()
|
||||||
* @details Stores the timestamp of the last deltaDuration(), this is
|
* @details Store the timestamp of the last deltaDuration(), this is
|
||||||
* required due to the updateInterval cycle.
|
* required due to the updateInterval cycle.
|
||||||
*/
|
*/
|
||||||
millis_t lastDuration;
|
static millis_t lastDuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stats were loaded from EERPROM
|
* @brief Stats were loaded from EEPROM
|
||||||
* @details If set to true it indicates if the statistical data was already
|
* @details If set to true it indicates if the statistical data was already
|
||||||
* loaded from the EEPROM.
|
* loaded from the EEPROM.
|
||||||
*/
|
*/
|
||||||
bool loaded = false;
|
static bool loaded;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief dT since the last call
|
* @brief dT since the last call
|
||||||
* @details Returns the elapsed time in seconds since the last call, this is
|
* @details Return the elapsed time in seconds since the last call, this is
|
||||||
* used internally for print statistics accounting is not intended to be a
|
* used internally for print statistics accounting is not intended to be a
|
||||||
* user callable function.
|
* user callable function.
|
||||||
*/
|
*/
|
||||||
millis_t deltaDuration();
|
static millis_t deltaDuration();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the print counter
|
* @brief Initialize the print counter
|
||||||
*/
|
*/
|
||||||
inline void init() {
|
static inline void init() {
|
||||||
super::init();
|
super::init();
|
||||||
this->loadStats();
|
loadStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if Print Statistics has been loaded
|
* @brief Check if Print Statistics has been loaded
|
||||||
* @details Returns true if the statistical data has been loaded.
|
* @details Return true if the statistical data has been loaded.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
bool isLoaded();
|
FORCE_INLINE static bool isLoaded() { return loaded; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Increments the total filament used
|
* @brief Increment the total filament used
|
||||||
* @details The total filament used counter will be incremented by "amount".
|
* @details The total filament used counter will be incremented by "amount".
|
||||||
*
|
*
|
||||||
* @param amount The amount of filament used in mm
|
* @param amount The amount of filament used in mm
|
||||||
*/
|
*/
|
||||||
void incFilamentUsed(double const &amount);
|
static void incFilamentUsed(double const &amount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Resets the Print Statistics
|
* @brief Reset the Print Statistics
|
||||||
* @details Resets the statistics to zero and saves them to EEPROM creating
|
* @details Reset the statistics to zero and saves them to EEPROM creating
|
||||||
* also the magic header.
|
* also the magic header.
|
||||||
*/
|
*/
|
||||||
void initStats();
|
static void initStats();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads the Print Statistics
|
* @brief Load the Print Statistics
|
||||||
* @details Loads the statistics from EEPROM
|
* @details Load the statistics from EEPROM
|
||||||
*/
|
*/
|
||||||
void loadStats();
|
static void loadStats();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Saves the Print Statistics
|
* @brief Save the Print Statistics
|
||||||
* @details Saves the statistics to EEPROM
|
* @details Save the statistics to EEPROM
|
||||||
*/
|
*/
|
||||||
void saveStats();
|
static void saveStats();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Serial output the Print Statistics
|
* @brief Serial output the Print Statistics
|
||||||
* @details This function may change in the future, for now it directly
|
* @details This function may change in the future, for now it directly
|
||||||
* prints the statistical data to serial.
|
* prints the statistical data to serial.
|
||||||
*/
|
*/
|
||||||
void showStats();
|
static void showStats();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the currently loaded statistics
|
* @brief Return the currently loaded statistics
|
||||||
* @details Return the raw data, in the same structure used internally
|
* @details Return the raw data, in the same structure used internally
|
||||||
*/
|
*/
|
||||||
printStatistics getStats() { return this->data; }
|
static printStatistics getStats() { return data; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loop function
|
* @brief Loop function
|
||||||
* @details This function should be called at loop, it will take care of
|
* @details This function should be called at loop, it will take care of
|
||||||
* periodically save the statistical data to EEPROM and do time keeping.
|
* periodically save the statistical data to EEPROM and do time keeping.
|
||||||
*/
|
*/
|
||||||
void tick();
|
static void tick();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The following functions are being overridden
|
* The following functions are being overridden
|
||||||
*/
|
*/
|
||||||
bool start();
|
static bool start();
|
||||||
bool stop();
|
static bool stop();
|
||||||
void reset();
|
static void reset();
|
||||||
|
|
||||||
#if ENABLED(DEBUG_PRINTCOUNTER)
|
#if ENABLED(DEBUG_PRINTCOUNTER)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints a debug message
|
* @brief Print a debug message
|
||||||
* @details Prints a simple debug message "PrintCounter::function"
|
* @details Print a simple debug message
|
||||||
*/
|
*/
|
||||||
static void debug(const char func[]);
|
static void debug(const char func[]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// Print Job Timer
|
// Global Print Job Timer instance
|
||||||
#if ENABLED(PRINTCOUNTER)
|
#if ENABLED(PRINTCOUNTER)
|
||||||
extern PrintCounter print_job_timer;
|
extern PrintCounter print_job_timer;
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user