summaryrefslogtreecommitdiff
path: root/src/utils/time.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/time.cpp')
-rw-r--r--src/utils/time.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/utils/time.cpp b/src/utils/time.cpp
index adc33db..c6d981c 100644
--- a/src/utils/time.cpp
+++ b/src/utils/time.cpp
@@ -1,9 +1,9 @@
#include "time.hpp"
-#include "Arduino.h"
-Time::Time(unsigned long time_micros)
+#include <Arduino.h>
+
+Time::Time(uint64_t time_micros) : _time_micros(time_micros)
{
- _time_micros = time_micros;
}
void Time::update()
@@ -16,19 +16,23 @@ Time Time::diff(Time prev_time)
return Time(_time_micros - prev_time.microsecs());
}
-unsigned long Time::microsecs()
+double Time::secs()
{
- return _time_micros;
+ const double micros_to_secs = 0.000001;
+
+ return static_cast<double>(_time_micros) * micros_to_secs;
}
-unsigned long Time::millisecs()
+double Time::millisecs()
{
- return _time_micros * 0.001;
+ const double micros_to_millis = 0.001;
+
+ return static_cast<double>(_time_micros) * micros_to_millis;
}
-float Time::secs()
+uint64_t Time::microsecs()
{
- return _time_micros * 0.000001;
+ return _time_micros;
}
Time time_now()