jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/
|
| 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 |
|
| 13 | typedef void (*TimerInterruptHandler)(void *param);
|
| 14 |
|
| 15 | void Wait(double seconds);
|
| 16 | double GetClock();
|
| 17 | double 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 | */
|
| 27 | class Timer
|
| 28 | {
|
| 29 | public:
|
| 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 |
|
| 41 | private:
|
| 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
|