Allow stopwatch and printcounter to go over 18 hours

master
Scott Lahteine 8 years ago
parent 6080924589
commit e481b79af1

@ -1172,8 +1172,7 @@ inline void get_serial_commands() {
print_job_timer.stop();
char time[30];
millis_t t = print_job_timer.duration();
int hours = t / 60 / 60, minutes = (t / 60) % 60;
sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), hours, minutes);
sprintf_P(time, PSTR("%i " MSG_END_HOUR " %i " MSG_END_MINUTE), int(t / 60 / 60), int(t / 60) % 60);
SERIAL_ECHO_START;
SERIAL_ECHOLN(time);
lcd_setstatus(time, true);

@ -386,7 +386,7 @@ static void lcd_implementation_status_screen() {
}
u8g.setPrintPos(80,48);
uint16_t time = print_job_timer.duration() / 60;
millis_t time = print_job_timer.duration() / 60;
if (time != 0) {
lcd_print(itostr2(time/60));
lcd_print(':');

@ -27,12 +27,12 @@ PrintCounter::PrintCounter(): super() {
this->loadStats();
}
uint16_t PrintCounter::deltaDuration() {
millis_t PrintCounter::deltaDuration() {
#if ENABLED(DEBUG_PRINTCOUNTER)
PrintCounter::debug(PSTR("deltaDuration"));
#endif
uint16_t tmp = this->lastDuration;
millis_t tmp = this->lastDuration;
this->lastDuration = this->duration();
return this->lastDuration - tmp;
}
@ -88,12 +88,12 @@ void PrintCounter::showStats() {
SERIAL_ECHO(this->data.totalPrints - this->data.finishedPrints
- ((this->isRunning() || this->isPaused()) ? 1 : 0)); // Removes 1 from failures with an active counter
uint32_t t = this->data.printTime / 60;
millis_t t = this->data.printTime / 60; // minutes from seconds
SERIAL_ECHOPGM(", Total print time: ");
SERIAL_ECHO(t / 60);
SERIAL_ECHO(t / 60); // hours
SERIAL_ECHOPGM("h ");
SERIAL_ECHO(t % 60);
SERIAL_ECHO(t % 60); // minutes
SERIAL_ECHOPGM("min");
@ -110,10 +110,10 @@ void PrintCounter::showStats() {
void PrintCounter::tick() {
if (!this->isRunning()) return;
static uint32_t update_before = millis(),
static millis_t update_before = millis(),
eeprom_before = millis();
uint32_t now = millis();
millis_t now = millis();
// Trying to get the amount of calculations down to the bare min
const static uint16_t i = this->updateInterval * 1000;
@ -128,8 +128,7 @@ void PrintCounter::tick() {
}
// Trying to get the amount of calculations down to the bare min
const static uint32_t j = this->saveInterval * 1000;
const static millis_t j = this->saveInterval * 1000;
if (now - eeprom_before >= j) {
eeprom_before = now;
this->saveStats();

@ -35,8 +35,8 @@ struct printStatistics { // 13 bytes
//const uint8_t magic; // Magic header, it will always be 0x16
uint16_t totalPrints; // Number of prints
uint16_t finishedPrints; // Number of complete prints
uint32_t printTime; // Total printing time
uint32_t longestPrint; // Longest print job - not in use
millis_t printTime; // Total printing time
millis_t longestPrint; // Longest print job - not in use
};
class PrintCounter: public Stopwatch {
@ -74,7 +74,7 @@ class PrintCounter: public Stopwatch {
* @details Stores the timestamp of the last deltaDuration(), this is
* required due to the updateInterval cycle.
*/
uint16_t lastDuration;
millis_t lastDuration;
/**
* @brief Stats were loaded from EERPROM
@ -90,7 +90,7 @@ class PrintCounter: public Stopwatch {
* used internally for print statistics accounting is not intended to be a
* user callable function.
*/
uint16_t deltaDuration();
millis_t deltaDuration();
public:
/**

@ -88,9 +88,9 @@ bool Stopwatch::isPaused() {
return (this->state == STOPWATCH_PAUSED) ? true : false;
}
uint16_t Stopwatch::duration() {
millis_t Stopwatch::duration() {
return (((this->isRunning()) ? millis() : this->stopTimestamp)
- this->startTimestamp) / 1000 + this->accumulator;
- this->startTimestamp) / 1000UL + this->accumulator;
}
#if ENABLED(DEBUG_STOPWATCH)

@ -42,9 +42,9 @@ enum StopwatchState {
class Stopwatch {
private:
StopwatchState state;
uint16_t accumulator;
uint32_t startTimestamp;
uint32_t stopTimestamp;
millis_t accumulator;
millis_t startTimestamp;
millis_t stopTimestamp;
public:
/**
@ -101,7 +101,7 @@ class Stopwatch {
* @details Returns the total number of seconds the timer has been running.
* @return the delta since starting the stopwatch
*/
uint16_t duration();
millis_t duration();
#if ENABLED(DEBUG_STOPWATCH)

@ -1967,13 +1967,13 @@ void kill_screen(const char* lcd_msg) {
print_job_counter.loadStats();
printStatistics stats = print_job_counter.getStats();
char printTime[6];
sprintf(printTime, "%02d:%02d", int(stats.printTime / 3600), int(stats.printTime / 60) % 60);
char timeString[8];
sprintf_P(timeString, PSTR("%i:%02i"), int(stats.printTime / 60 / 60), int(stats.printTime / 60) % 60);
START_SCREEN();
START_SCREEN(); // 12345678901234567890
STATIC_ITEM(MSG_INFO_PRINT_COUNT ": ", false, false, itostr3left(stats.totalPrints)); // Print Count : 999
STATIC_ITEM(MSG_INFO_FINISHED_PRINTS ": ", false, false, itostr3left(stats.finishedPrints)); // Finished : 666
STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false, printTime); // Total Time : 12:34
STATIC_ITEM(MSG_INFO_PRINT_TIME ": ", false, false, timeString); // Total Time : 123:45
END_SCREEN();
}
#endif // PRINTCOUNTER

Loading…
Cancel
Save