blob: ee297d72a4b99a8386364db9782381e85655fdd9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
|