Add Stopwatch::resume method

This commit is contained in:
Scott Lahteine
2018-04-21 19:06:05 -05:00
parent a90cbc6339
commit 2f4b4d6076
2 changed files with 26 additions and 19 deletions

View File

@@ -71,6 +71,15 @@ bool Stopwatch::start() {
else return false;
}
void Stopwatch::resume(const millis_t duration) {
#if ENABLED(DEBUG_STOPWATCH)
Stopwatch::debug(PSTR("resume"));
#endif
reset();
if ((accumulator = duration)) state = RUNNING;
}
void Stopwatch::reset() {
#if ENABLED(DEBUG_STOPWATCH)
Stopwatch::debug(PSTR("reset"));
@@ -82,16 +91,8 @@ void Stopwatch::reset() {
accumulator = 0;
}
bool Stopwatch::isRunning() {
return (state == RUNNING) ? true : false;
}
bool Stopwatch::isPaused() {
return (state == PAUSED) ? true : false;
}
millis_t Stopwatch::duration() {
return (((isRunning()) ? millis() : stopTimestamp)
return ((isRunning() ? millis() : stopTimestamp)
- startTimestamp) / 1000UL + accumulator;
}