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 
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:
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