Add Stopwatch::resume method
This commit is contained in:
parent
a90cbc6339
commit
2f4b4d6076
2 changed files with 26 additions and 19 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,10 +54,10 @@ class Stopwatch {
|
|||
FORCE_INLINE static void init() { reset(); }
|
||||
|
||||
/**
|
||||
* @brief Stops the stopwatch
|
||||
* @details Stops the running timer, it will silently ignore the request if
|
||||
* @brief Stop the stopwatch
|
||||
* @details Stop the running timer, it will silently ignore the request if
|
||||
* no timer is currently running.
|
||||
* @return true is method was successful
|
||||
* @return true on success
|
||||
*/
|
||||
static bool stop();
|
||||
|
||||
|
@ -65,7 +65,7 @@ class Stopwatch {
|
|||
* @brief Pause the stopwatch
|
||||
* @details Pause the running timer, it will silently ignore the request if
|
||||
* no timer is currently running.
|
||||
* @return true is method was successful
|
||||
* @return true on success
|
||||
*/
|
||||
static bool pause();
|
||||
|
||||
|
@ -73,10 +73,16 @@ class Stopwatch {
|
|||
* @brief Start the stopwatch
|
||||
* @details Start the timer, it will silently ignore the request if the
|
||||
* timer is already running.
|
||||
* @return true is method was successful
|
||||
* @return true on success
|
||||
*/
|
||||
static bool start();
|
||||
|
||||
/**
|
||||
* @brief Resume the stopwatch
|
||||
* @details Resume a timer from a given duration
|
||||
*/
|
||||
static void resume(const millis_t duration);
|
||||
|
||||
/**
|
||||
* @brief Reset the stopwatch
|
||||
* @details Reset all settings to their default values.
|
||||
|
@ -88,14 +94,14 @@ class Stopwatch {
|
|||
* @details Return true if the timer is currently running, false otherwise.
|
||||
* @return true if stopwatch is running
|
||||
*/
|
||||
static bool isRunning();
|
||||
FORCE_INLINE static bool isRunning() { return state == RUNNING; }
|
||||
|
||||
/**
|
||||
* @brief Check if the timer is paused
|
||||
* @details Return true if the timer is currently paused, false otherwise.
|
||||
* @return true if stopwatch is paused
|
||||
*/
|
||||
static bool isPaused();
|
||||
FORCE_INLINE static bool isPaused() { return state == PAUSED; }
|
||||
|
||||
/**
|
||||
* @brief Get the running time
|
||||
|
|
Reference in a new issue