Use static classes for job timers (#9938)

This commit is contained in:
Scott Lahteine
2018-03-04 21:23:43 -06:00
committed by GitHub
parent 930720bbbb
commit 36262a0479
5 changed files with 171 additions and 166 deletions

View File

@@ -20,21 +20,23 @@
*
*/
#include "../Marlin.h"
#include "stopwatch.h"
Stopwatch::Stopwatch() {
this->reset();
}
#include "../inc/MarlinConfig.h"
Stopwatch::State Stopwatch::state;
millis_t Stopwatch::accumulator;
millis_t Stopwatch::startTimestamp;
millis_t Stopwatch::stopTimestamp;
bool Stopwatch::stop() {
#if ENABLED(DEBUG_STOPWATCH)
Stopwatch::debug(PSTR("stop"));
#endif
if (this->isRunning() || this->isPaused()) {
this->state = STOPPED;
this->stopTimestamp = millis();
if (isRunning() || isPaused()) {
state = STOPPED;
stopTimestamp = millis();
return true;
}
else return false;
@@ -45,9 +47,9 @@ bool Stopwatch::pause() {
Stopwatch::debug(PSTR("pause"));
#endif
if (this->isRunning()) {
this->state = PAUSED;
this->stopTimestamp = millis();
if (isRunning()) {
state = PAUSED;
stopTimestamp = millis();
return true;
}
else return false;
@@ -58,12 +60,12 @@ bool Stopwatch::start() {
Stopwatch::debug(PSTR("start"));
#endif
if (!this->isRunning()) {
if (this->isPaused()) this->accumulator = this->duration();
else this->reset();
if (!isRunning()) {
if (isPaused()) accumulator = duration();
else reset();
this->state = RUNNING;
this->startTimestamp = millis();
state = RUNNING;
startTimestamp = millis();
return true;
}
else return false;
@@ -74,23 +76,23 @@ void Stopwatch::reset() {
Stopwatch::debug(PSTR("reset"));
#endif
this->state = STOPPED;
this->startTimestamp = 0;
this->stopTimestamp = 0;
this->accumulator = 0;
state = STOPPED;
startTimestamp = 0;
stopTimestamp = 0;
accumulator = 0;
}
bool Stopwatch::isRunning() {
return (this->state == RUNNING) ? true : false;
return (state == RUNNING) ? true : false;
}
bool Stopwatch::isPaused() {
return (this->state == PAUSED) ? true : false;
return (state == PAUSED) ? true : false;
}
millis_t Stopwatch::duration() {
return (((this->isRunning()) ? millis() : this->stopTimestamp)
- this->startTimestamp) / 1000UL + this->accumulator;
return (((isRunning()) ? millis() : stopTimestamp)
- startTimestamp) / 1000UL + accumulator;
}
#if ENABLED(DEBUG_STOPWATCH)