diff options
author | HampusM <hampus@hampusmat.com> | 2022-02-15 12:33:52 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-02-15 12:33:52 +0100 |
commit | bcdce9633dc351d3bc7f347a165348b8fab87cd9 (patch) | |
tree | 88c2f5d8f0c5fac2bca28e4b543e5209f3bc98fb /src/std/time.cpp | |
parent | 917adc6a2b6b166e37fc3d4f94b41488f0c245a5 (diff) |
refactor: reorganize files & improve classes
Diffstat (limited to 'src/std/time.cpp')
-rw-r--r-- | src/std/time.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/std/time.cpp b/src/std/time.cpp new file mode 100644 index 0000000..cca8955 --- /dev/null +++ b/src/std/time.cpp @@ -0,0 +1,37 @@ +#include "time.hpp" + +#include <Arduino.h> + +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()); +} |