summaryrefslogtreecommitdiff
path: root/src/utils/time.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-14 18:18:38 +0100
committerHampusM <hampus@hampusmat.com>2022-02-14 18:18:38 +0100
commit01ce0af940bd69c94a2fac8b65219262845cca98 (patch)
tree97c443782ce1cfba90b205183c8aab1e3edb0bb3 /src/utils/time.cpp
parentcb7a167c7dee2fa1a19bd09ede3bae8b140e79da (diff)
refactor: clean sewage
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()