Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008-2017. 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 the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include "Base.h" |
| 11 | #include "HAL/cpp/priority_mutex.h" |
| 12 | |
| 13 | namespace frc { |
| 14 | |
| 15 | typedef void (*TimerInterruptHandler)(void* param); |
| 16 | |
| 17 | void Wait(double seconds); |
| 18 | double GetClock(); |
| 19 | double GetTime(); |
| 20 | |
| 21 | /** |
| 22 | * Timer objects measure accumulated time in seconds. |
| 23 | * The timer object functions like a stopwatch. It can be started, stopped, and |
| 24 | * cleared. When the timer is running its value counts up in seconds. When |
| 25 | * stopped, the timer holds the current value. The implementation simply records |
| 26 | * the time when started and subtracts the current time whenever the value is |
| 27 | * requested. |
| 28 | */ |
| 29 | class Timer { |
| 30 | public: |
| 31 | Timer(); |
| 32 | virtual ~Timer() = default; |
| 33 | |
| 34 | Timer(const Timer&) = delete; |
| 35 | Timer& operator=(const Timer&) = delete; |
| 36 | |
| 37 | double Get() const; |
| 38 | void Reset(); |
| 39 | void Start(); |
| 40 | void Stop(); |
| 41 | bool HasPeriodPassed(double period); |
| 42 | |
| 43 | static double GetFPGATimestamp(); |
| 44 | static double GetPPCTimestamp(); |
| 45 | static double GetMatchTime(); |
| 46 | |
| 47 | // The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0 |
| 48 | static const double kRolloverTime; |
| 49 | |
| 50 | private: |
| 51 | double m_startTime = 0.0; |
| 52 | double m_accumulatedTime = 0.0; |
| 53 | bool m_running = false; |
| 54 | mutable priority_mutex m_mutex; |
| 55 | }; |
| 56 | |
| 57 | } // namespace frc |