WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Timer.h
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 
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 hal::priority_mutex m_mutex;
55 };
56 
57 } // namespace frc
void Start()
Start the timer running.
Definition: Timer.cpp:118
Timer()
Create a new timer object.
Definition: Timer.cpp:66
void Reset()
Reset the timer by setting the time to 0.
Definition: Timer.cpp:106
Timer objects measure accumulated time in seconds.
Definition: Timer.h:29
double Get() const
Get the current time from the timer.
Definition: Timer.cpp:79
static double GetFPGATimestamp()
Return the FPGA system clock time in seconds.
Definition: Timer.cpp:170
void Stop()
Stop the timer.
Definition: Timer.cpp:133
Definition: priority_mutex.h:57
bool HasPeriodPassed(double period)
Check if the period specified has passed and if it has, advance the start time by that period...
Definition: Timer.cpp:151
static double GetMatchTime()
Return the approximate match time The FMS does not currently send the official match time to the robo...
Definition: Timer.cpp:189