-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUptimeInfo.cpp
51 lines (45 loc) · 829 Bytes
/
UptimeInfo.cpp
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
43
44
45
46
47
48
49
50
51
/*
* UptimeInfo.cpp
*
* Created on: 01.10.2013
* Author: niklausd
*/
#include "UptimeInfo.h"
#ifdef ARDUINO
#include "Arduino.h"
#else
#include <sys/time.h>
#endif
class DefaultUptimeInfoAdapter : public UptimeInfoAdapter
{
public:
inline unsigned long tMillis()
{
#ifdef ARDUINO
return millis();
#else
/**
* @see http://stackoverflow.com/a/1952423
*/
struct timeval tp;
gettimeofday(&tp, 0);
unsigned long ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
return ms;
#endif
}
};
UptimeInfo* UptimeInfo::s_instance = 0;
UptimeInfoAdapter* UptimeInfo::s_adapter = 0;
UptimeInfo::UptimeInfo()
{
s_adapter = new DefaultUptimeInfoAdapter();
}
UptimeInfo::~UptimeInfo()
{
delete s_adapter;
s_adapter = 0;
}
void UptimeInfo::setAdapter(UptimeInfoAdapter* adapter)
{
s_adapter = adapter;
}