1
0
forked from fsfw/fsfw

stopwatch update

This commit is contained in:
2020-09-18 12:27:40 +02:00
parent 42bfedd36c
commit 0f0ddfc375
4 changed files with 25 additions and 33 deletions

View File

@ -1,4 +1,4 @@
#include "Stopwatch.h"
#include "../timemanager/Stopwatch.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include <iomanip>
@ -6,19 +6,22 @@ Stopwatch::Stopwatch(bool displayOnDestruction,
StopwatchDisplayMode displayMode): displayOnDestruction(
displayOnDestruction), displayMode(displayMode) {
// Measures start time on initialization.
Clock::getClock_timeval(&startTime);
Clock::getUptime(&startTime);
}
void Stopwatch::start() {
Clock::getClock_timeval(&startTime);
Clock::getUptime(&startTime);
}
dur_millis_t Stopwatch::stop() {
dur_millis_t Stopwatch::stop(bool display) {
stopInternal();
if(display) {
this->display();
}
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
}
dur_seconds_t Stopwatch::stopSeconds() {
double Stopwatch::stopSeconds() {
stopInternal();
return timevalOperations::toDouble(elapsedTime);
}
@ -52,6 +55,6 @@ StopwatchDisplayMode Stopwatch::getDisplayMode() const {
void Stopwatch::stopInternal() {
timeval endTime;
Clock::getClock_timeval(&endTime);
Clock::getUptime(&endTime);
elapsedTime = endTime - startTime;
}