diff options
| author | HampusM <hampus@hampusmat.com> | 2022-02-14 10:11:32 +0100 | 
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2022-02-14 10:11:32 +0100 | 
| commit | 7892ef9d248c189be68ce7faf63230ec0a318b67 (patch) | |
| tree | 7c3d07779d5ce96994f81c0cc22e8b667601ee9d /src/utils/time.cpp | |
| parent | a03dfe959fcafd238119bdf7f27c07b92064496e (diff) | |
refactor: reorganize & add debugging
Diffstat (limited to 'src/utils/time.cpp')
| -rw-r--r-- | src/utils/time.cpp | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/src/utils/time.cpp b/src/utils/time.cpp new file mode 100644 index 0000000..adc33db --- /dev/null +++ b/src/utils/time.cpp @@ -0,0 +1,37 @@ +#include "time.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()); +} | 
