diff options
author | HampusM <hampus@hampusmat.com> | 2021-12-24 20:07:16 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-12-26 20:36:34 +0100 |
commit | e5b34cbb3d6764cc9a7d3e6d4c27da468f16246f (patch) | |
tree | dd6da3fb64a9a8f355ad819061efcdaa8aa305a3 /src/time_utils.cpp | |
parent | 8969ebfa45b593e0c59f6998fdf8bde42324089f (diff) |
refactor: improve whole project
Diffstat (limited to 'src/time_utils.cpp')
-rw-r--r-- | src/time_utils.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/time_utils.cpp b/src/time_utils.cpp new file mode 100644 index 0000000..84c7d96 --- /dev/null +++ b/src/time_utils.cpp @@ -0,0 +1,37 @@ +#include "time_utils.hpp" +#include "Arduino.h" + +Time::Time(unsigned long time_micros) +{ + _time_micros = time_micros; +} + +void Time::update() +{ + _time_micros = micros(); +} + +Time Time::diff(Time prev_time) +{ + return Time(_time_micros - prev_time.microsecs()); +} + +unsigned long Time::microsecs() +{ + return _time_micros; +} + +unsigned long Time::millisecs() +{ + return _time_micros * 0.001; +} + +float Time::secs() +{ + return _time_micros * 0.000001; +} + +Time time_now() +{ + return Time(micros()); +} |