Updates Stopwatch class to use internal state enum
This commit is contained in:
parent
46117593b9
commit
238fefcb00
2 changed files with 13 additions and 13 deletions
|
@ -33,7 +33,7 @@ bool Stopwatch::stop() {
|
|||
#endif
|
||||
|
||||
if (this->isRunning() || this->isPaused()) {
|
||||
this->state = STOPWATCH_STOPPED;
|
||||
this->state = STOPPED;
|
||||
this->stopTimestamp = millis();
|
||||
return true;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ bool Stopwatch::pause() {
|
|||
#endif
|
||||
|
||||
if (this->isRunning()) {
|
||||
this->state = STOPWATCH_PAUSED;
|
||||
this->state = PAUSED;
|
||||
this->stopTimestamp = millis();
|
||||
return true;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ bool Stopwatch::start() {
|
|||
if (this->isPaused()) this->accumulator = this->duration();
|
||||
else this->reset();
|
||||
|
||||
this->state = STOPWATCH_RUNNING;
|
||||
this->state = RUNNING;
|
||||
this->startTimestamp = millis();
|
||||
return true;
|
||||
}
|
||||
|
@ -74,18 +74,18 @@ void Stopwatch::reset() {
|
|||
Stopwatch::debug(PSTR("reset"));
|
||||
#endif
|
||||
|
||||
this->state = STOPWATCH_STOPPED;
|
||||
this->state = STOPPED;
|
||||
this->startTimestamp = 0;
|
||||
this->stopTimestamp = 0;
|
||||
this->accumulator = 0;
|
||||
}
|
||||
|
||||
bool Stopwatch::isRunning() {
|
||||
return (this->state == STOPWATCH_RUNNING) ? true : false;
|
||||
return (this->state == RUNNING) ? true : false;
|
||||
}
|
||||
|
||||
bool Stopwatch::isPaused() {
|
||||
return (this->state == STOPWATCH_PAUSED) ? true : false;
|
||||
return (this->state == PAUSED) ? true : false;
|
||||
}
|
||||
|
||||
millis_t Stopwatch::duration() {
|
||||
|
|
|
@ -28,12 +28,6 @@
|
|||
// Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
|
||||
//#define DEBUG_STOPWATCH
|
||||
|
||||
enum StopwatchState {
|
||||
STOPWATCH_STOPPED,
|
||||
STOPWATCH_RUNNING,
|
||||
STOPWATCH_PAUSED
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Stopwatch class
|
||||
* @details This class acts as a timer proving stopwatch functionality including
|
||||
|
@ -41,7 +35,13 @@ enum StopwatchState {
|
|||
*/
|
||||
class Stopwatch {
|
||||
private:
|
||||
StopwatchState state;
|
||||
enum State {
|
||||
STOPPED,
|
||||
RUNNING,
|
||||
PAUSED
|
||||
};
|
||||
|
||||
Stopwatch::State state;
|
||||
millis_t accumulator;
|
||||
millis_t startTimestamp;
|
||||
millis_t stopTimestamp;
|
||||
|
|
Reference in a new issue