esp8266ndn
NDN Arduino library for ESP8266 and more
Loading...
Searching...
No Matches
ino.hpp
Go to the documentation of this file.
1#ifndef NDNPH_PORT_CLOCK_INO_HPP
2#define NDNPH_PORT_CLOCK_INO_HPP
3
4#include "../../core/common.hpp"
5#include "../arduino-include.hpp"
6
7namespace ndnph {
8namespace port_clock_ino {
9
10using TimeMillis = decltype(::millis());
11
13class Clock {
14public:
15 Clock() = delete;
16
17 struct Time {
19 };
20
21 static Time now() {
22 Time r;
23 r.ms = ::millis();
24 return r;
25 }
26
27 static Time add(Time t, int ms) {
28 Time r;
29 r.ms = t.ms + ms;
30 return r;
31 }
32
33 static int sub(Time a, Time b) {
34 if (isBefore(a, b)) {
35 auto diff = b.ms - a.ms;
36 return -static_cast<int>(diff);
37 }
38 auto diff = a.ms - b.ms;
39 return static_cast<int>(diff);
40 }
41
42 static bool isBefore(Time a, Time b) {
43 static_assert(std::is_unsigned<TimeMillis>::value, "");
44 auto diff = a.ms - b.ms;
45 return diff > std::numeric_limits<TimeMillis>::max() / 2;
46 }
47
48 static void sleep(int ms) {
49 if (ms >= 0) {
50 ::delay(ms);
51 }
52 }
53};
54
55} // namespace port_clock_ino
56
57#ifdef NDNPH_PORT_CLOCK_INO
58namespace port {
60} // namespace port
61#endif
62
63} // namespace ndnph
64
65#endif // NDNPH_PORT_CLOCK_INO_HPP
Clock implemented with Arduino API.
Definition ino.hpp:13
static void sleep(int ms)
Definition ino.hpp:48
static bool isBefore(Time a, Time b)
Definition ino.hpp:42
static int sub(Time a, Time b)
Definition ino.hpp:33
static Time now()
Definition ino.hpp:21
static Time add(Time t, int ms)
Definition ino.hpp:27
decltype(::millis()) TimeMillis
Definition ino.hpp:10
Definition fs.hpp:33
TimeMillis ms
Definition ino.hpp:18