]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/hokuyo/lib/ticks.c
Add unified ORTE topic type for LIDAR scan data
[eurobot/public.git] / src / hokuyo / lib / ticks.c
1 /*!
2   \file
3   \brief \83^\83C\83\80\83X\83^\83\93\83v\8eæ\93¾\8aÖ\90\94
4
5   \author Satofumi KAMIMURA
6
7   $Id: ticks.c 1305 2009-09-16 05:40:53Z satofumi $
8 */
9
10 #include "ticks.h"
11 #include "detect_os.h"
12 #if defined WINDOWS_OS
13 #include <time.h>
14 #else
15 #include <sys/time.h>
16 #include <stdio.h>
17 #endif
18
19
20 int ticks(void)
21 {
22   int current_ticks = 0;
23
24 #if defined(LINUX_OS)
25   // Linux \82Å SDL \82ª\82È\82¢\8fê\8d\87\82Ì\8eÀ\91\95\81B\8dÅ\8f\89\82Ì\8cÄ\82Ñ\8fo\82µ\82Í 0 \82ð\95Ô\82·
26   static int first_ticks = 0;
27   struct timeval tvp;
28   gettimeofday(&tvp, NULL);
29   int global_ticks = tvp.tv_sec * 1000 + tvp.tv_usec / 1000;
30   if (first_ticks == 0) {
31     first_ticks = global_ticks;
32   }
33   current_ticks = global_ticks - first_ticks;
34
35 #else
36   current_ticks = (int)(clock() / (CLOCKS_PER_SEC / 1000.0));
37 #endif
38   return current_ticks;
39 }