WPILibC++  unspecified
Timer.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 FIRST. 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 <support/deprecated.h>
11 #include <support/mutex.h>
12 
13 #include "Base.h"
14 
15 namespace frc {
16 
17 typedef void (*TimerInterruptHandler)(void* param);
18 
19 void Wait(double seconds);
20 WPI_DEPRECATED("Use Timer::GetFPGATimestamp() instead.")
21 double GetClock();
22 double GetTime();
23 
33 class Timer {
34  public:
35  Timer();
36  virtual ~Timer() = default;
37 
38  Timer(const Timer&) = delete;
39  Timer& operator=(const Timer&) = delete;
40 
41  double Get() const;
42  void Reset();
43  void Start();
44  void Stop();
45  bool HasPeriodPassed(double period);
46 
47  static double GetFPGATimestamp();
48  static double GetMatchTime();
49 
50  // The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0
51  static const double kRolloverTime;
52 
53  private:
54  double m_startTime = 0.0;
55  double m_accumulatedTime = 0.0;
56  bool m_running = false;
57  mutable wpi::mutex m_mutex;
58 };
59 
60 } // namespace frc
Definition: RobotController.cpp:14
Timer objects measure accumulated time in seconds.
Definition: Timer.h:33