From 1cf5991101f9dc0e677911e1d7cfeffaa250285b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 17:43:06 +0200 Subject: [PATCH] getClock_timval used now --- timemanager/Stopwatch.cpp | 12 +++++++----- timemanager/Stopwatch.h | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 2c85376d..bc8b4149 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -3,14 +3,14 @@ #include Stopwatch::Stopwatch(bool displayOnDestruction, - StopwatchDisplayMode displayMode): displayMode(displayMode), - displayOnDestruction(displayOnDestruction) { + StopwatchDisplayMode displayMode): displayOnDestruction( + displayOnDestruction), displayMode(displayMode) { // Measures start time on initialization. - startTime = Clock::getUptime(); + Clock::getClock_timeval(&startTime); } void Stopwatch::start() { - startTime = Clock::getUptime(); + Clock::getClock_timeval(&startTime); } millis_t Stopwatch::stop() { @@ -51,5 +51,7 @@ StopwatchDisplayMode Stopwatch::getDisplayMode() const { } void Stopwatch::stopInternal() { - elapsedTime = Clock::getUptime() - startTime; + timeval endTime; + Clock::getClock_timeval(&endTime); + elapsedTime = endTime - startTime; } diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h index 19e1f92b..71580778 100644 --- a/timemanager/Stopwatch.h +++ b/timemanager/Stopwatch.h @@ -8,11 +8,13 @@ enum class StopwatchDisplayMode { }; /** - * @brief Simple Stopwatch implementation to measure elapsed time + * @brief Simple Stopwatch implementation to measure elapsed time * @details * This class can be used to measure elapsed times. It also displays elapsed * times automatically on destruction if not explicitely deactivated in the - * constructor. The default time format is the elapsed time in miliseconds. + * constructor. The default time format is the elapsed time in miliseconds + * in seconds as a double. + * @author R. Mueller */ class Stopwatch { public: @@ -21,8 +23,8 @@ public: * no parameters are required! * @param displayOnDestruction If set to true, displays measured time on * object destruction - * @param displayMode Display format is either MS rounded or seconds as - * double format + * @param displayMode Display format is either MS rounded or MS as double + * format * @param outputPrecision If using double format, specify precision here. */ Stopwatch(bool displayOnDestruction = true, StopwatchDisplayMode displayMode @@ -39,6 +41,10 @@ public: * @return elapsed time in milliseconds (rounded) */ millis_t stop(); + /** + * Calculates the elapsed time since start and returns it + * @return elapsed time in seconds (double precision) + */ seconds_t stopSeconds(); /** @@ -49,12 +55,13 @@ public: StopwatchDisplayMode getDisplayMode() const; void setDisplayMode(StopwatchDisplayMode displayMode); + bool displayOnDestruction = true; private: timeval startTime {0, 0}; timeval elapsedTime {0, 0}; StopwatchDisplayMode displayMode = StopwatchDisplayMode::MILLIS; - bool displayOnDestruction = true; + void stopInternal(); };