WPILibC++  2019.1.1-beta-2-16-ga60f312
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 <wpi/deprecated.h>
11 #include <wpi/mutex.h>
12 
13 #include "frc/Base.h"
14 
15 namespace frc {
16 
17 using TimerInterruptHandler = void (*)(void* param);
18 
29 void Wait(double seconds);
30 
38 WPI_DEPRECATED("Use Timer::GetFPGATimestamp() instead.")
39 double GetClock();
40 
46 double GetTime();
47 
57 class Timer {
58  public:
65  Timer();
66 
67  virtual ~Timer() = default;
68 
69  Timer(Timer&&) = default;
70  Timer& operator=(Timer&&) = default;
71 
79  double Get() const;
80 
87  void Reset();
88 
95  void Start();
96 
104  void Stop();
105 
114  bool HasPeriodPassed(double period);
115 
124  static double GetFPGATimestamp();
125 
141  static double GetMatchTime();
142 
143  // The time, in seconds, at which the 32-bit FPGA timestamp rolls over to 0
144  static const double kRolloverTime;
145 
146  private:
147  double m_startTime = 0.0;
148  double m_accumulatedTime = 0.0;
149  bool m_running = false;
150  mutable wpi::mutex m_mutex;
151 };
152 
153 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
double GetTime()
Gives real-time clock system time with nanosecond resolution.
Timer objects measure accumulated time in seconds.
Definition: Timer.h:57
void Wait(double seconds)
Pause the task for a specified time.
double GetClock()
Return the FPGA system clock time in seconds.