blob: 6f15572777ad457a8de1fd87b772100b257586ec [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#ifndef TIMER_H_
8#define TIMER_H_
9
10#include "semLib.h"
11#include "Base.h"
12
13typedef void (*TimerInterruptHandler)(void *param);
14
15void Wait(double seconds);
16double GetClock();
17double GetTime();
18
19
20/**
21 * Timer objects measure accumulated time in seconds.
22 * The timer object functions like a stopwatch. It can be started, stopped, and cleared. When the
23 * timer is running its value counts up in seconds. When stopped, the timer holds the current
24 * value. The implementation simply records the time when started and subtracts the current time
25 * whenever the value is requested.
26 */
27class Timer
28{
29public:
30 Timer();
31 virtual ~Timer();
32 double Get();
33 void Reset();
34 void Start();
35 void Stop();
36 bool HasPeriodPassed(double period);
37
38 static double GetFPGATimestamp();
39 static double GetPPCTimestamp();
40
41private:
42 double m_startTime;
43 double m_accumulatedTime;
44 bool m_running;
45 SEM_ID m_semaphore;
46 DISALLOW_COPY_AND_ASSIGN(Timer);
47};
48
49#endif