From bcdce9633dc351d3bc7f347a165348b8fab87cd9 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 15 Feb 2022 12:33:52 +0100 Subject: refactor: reorganize files & improve classes --- src/std/time.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/std/time.cpp (limited to 'src/std/time.cpp') 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 + +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(_time_micros) * MICROS_TO_SECS; +} + +double Time::millisecs() const +{ + return static_cast(_time_micros) * MICROS_TO_MILLIS; +} + +uint64_t Time::microsecs() const +{ + return _time_micros; +} + +Time time_now() +{ + return Time(micros()); +} -- cgit v1.2.3-18-g5258