getClock_timval used now
This commit is contained in:
parent
35b9346c2b
commit
1cf5991101
@ -3,14 +3,14 @@
|
||||
#include <iomanip>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ enum class StopwatchDisplayMode {
|
||||
* @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();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user