summaryrefslogtreecommitdiff
path: root/src/common/time.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-14 10:24:36 +0100
committerHampusM <hampus@hampusmat.com>2022-03-14 10:24:36 +0100
commita119e6ca70ffab14f0a70908fa3eeb83b41bb5ab (patch)
tree51b72774694f5e1aac0bb17fc1a5e528dbad9b44 /src/common/time.cpp
parent6b5754655f78a7f93b756ff902ce9fd80d9dc4ec (diff)
refactor: rename std to common
Diffstat (limited to 'src/common/time.cpp')
-rw-r--r--src/common/time.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/common/time.cpp b/src/common/time.cpp
new file mode 100644
index 0000000..ee297d7
--- /dev/null
+++ b/src/common/time.cpp
@@ -0,0 +1,42 @@
+#include "time.hpp"
+
+#include <Arduino.h>
+
+namespace common
+{
+
+ Time::Time(uint64_t time_micros) : _time_micros(time_micros)
+ {
+ }
+
+ void Time::update()
+ {
+ _time_micros = micros();
+ }
+
+ Time Time::diff(Time prev_time) const
+ {
+ return Time(_time_micros - prev_time.microsecs());
+ }
+
+ double Time::secs() const
+ {
+ return static_cast<double>(_time_micros) * MICROS_TO_SECS;
+ }
+
+ double Time::millisecs() const
+ {
+ return static_cast<double>(_time_micros) * MICROS_TO_MILLIS;
+ }
+
+ uint64_t Time::microsecs() const
+ {
+ return _time_micros;
+ }
+
+ Time time_now()
+ {
+ return Time(micros());
+ }
+
+} // namespace common