WPILibC++  2018.4.1-20180729223220-1149-g7bd3f9f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Watchdog.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 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 <functional>
11 
12 #include <wpi/StringMap.h>
13 #include <wpi/StringRef.h>
14 
15 #include "frc/Notifier.h"
16 
17 namespace frc {
18 
28 class Watchdog {
29  public:
36  explicit Watchdog(double timeout, std::function<void()> callback = [] {});
37 
38  Watchdog(const Watchdog&) = delete;
39  Watchdog& operator=(const Watchdog&) = delete;
40 
44  double GetTime() const;
45 
49  bool IsExpired() const;
50 
56  void AddEpoch(wpi::StringRef epochName);
57 
61  void PrintEpochs();
62 
68  void Reset();
69 
73  void Enable();
74 
78  void Disable();
79 
80  private:
81  double m_timeout;
82  std::function<void()> m_callback;
83  Notifier m_notifier;
84 
85  double m_startTime = 0.0;
86  wpi::StringMap<double> m_epochs;
87  bool m_isExpired = false;
88 
89  void TimeoutFunc();
90 };
91 
92 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: Notifier.h:26
void Enable()
Enables the watchdog timer.
bool IsExpired() const
Returns true if the watchdog timer has expired.
Watchdog(double timeout, std::function< void()> callback=[]{})
Watchdog constructor.
void Reset()
Resets the watchdog timer.
double GetTime() const
Get the time in seconds since the watchdog was last fed.
void PrintEpochs()
Prints list of epochs added so far and their times.
void Disable()
Disable the watchdog.
A class that's a wrapper around a watchdog timer.
Definition: Watchdog.h:28
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void AddEpoch(wpi::StringRef epochName)
Adds time since last epoch to the list printed by PrintEpochs().