ed
include
ed
event_clock.h
Go to the documentation of this file.
1
#ifndef ED_EVENT_CLOCK_H_
2
#define ED_EVENT_CLOCK_H_
3
4
#include <sys/time.h>
5
6
namespace
ed
7
{
8
9
class
EventClock
10
{
11
public
:
12
13
EventClock
() :
cycle_duration_
(0),
t_last_trigger_
(0) {}
14
15
EventClock
(
double
freq) :
cycle_duration_
(1.0 / freq),
t_last_trigger_
(0) {}
16
17
bool
triggers
()
18
{
19
struct
timeval now;
20
gettimeofday(&now, NULL);
21
22
double
t_secs = now.tv_sec + now.tv_usec / 1e6;
23
if
((t_secs -
t_last_trigger_
) >
cycle_duration_
)
24
{
25
t_last_trigger_
= t_secs;
26
return
true
;
27
}
28
return
false
;
29
}
30
31
private
:
32
double
cycle_duration_
;
33
double
t_last_trigger_
;
34
};
35
36
}
37
38
#endif
ed::EventClock::t_last_trigger_
double t_last_trigger_
Definition:
event_clock.h:33
ed::EventClock::EventClock
EventClock()
Definition:
event_clock.h:13
ed::EventClock::triggers
bool triggers()
Definition:
event_clock.h:17
ed::EventClock
Definition:
event_clock.h:9
ed::EventClock::EventClock
EventClock(double freq)
Definition:
event_clock.h:15
ed::EventClock::cycle_duration_
double cycle_duration_
Definition:
event_clock.h:32
ed
Definition:
convex_hull.h:8
Generated on Sun Feb 23 2025 04:34:40 for ed by
1.8.17