My Elma Project
An event loop manager for embedded systems
 All Classes Functions
stopwatch.h
1 #ifndef _ELMA_STOP_WATCH_H
2 #define _ELMA_STOP_WATCH_H
3 
4 #include "elma/elma.h" // Note installation directory for elma
5 
6 #include "on.h"
7 #include "off.h"
8 #include "user_interface.h"
9 
10 namespace stopwatch {
11 
12  using namespace std::chrono;
13  using namespace elma;
14 
16  class StopWatch : public StateMachine {
17 
18  public:
20  StopWatch();
21 
23  void begin();
24 
26  void reset();
27 
29  void stop();
30 
32  void lap();
33 
35  high_resolution_clock::duration value();
36 
38  const vector<high_resolution_clock::duration>& laps() { return _laps; }
39 
40  private:
41 
42  // When overriding the StateMachine class, put state declarations here.
43  OnState on;
44  OffState off;
45 
46  // Other private variables
47  bool _running;
48  high_resolution_clock::time_point _start_time;
49  high_resolution_clock::duration _elapsed;
50  vector<high_resolution_clock::duration> _laps;
51 
52  };
53 
54 }
55 
56 #endif
const vector< high_resolution_clock::duration > & laps()
Get a list of lap times.
Definition: stopwatch.h:38
Definition: off.h:6
The on state of the stopwatch.
Definition: on.h:15
A State class to represen the state in which the stopwatch is off.
Definition: off.h:15
A stop watch class, that inherits from StateMachine.
Definition: stopwatch.h:16