Browse Source

Updates Stopwatch class to use internal state enum

João Brázio 8 years ago
parent
commit
238fefcb00
2 changed files with 13 additions and 13 deletions
  1. 6
    6
      Marlin/stopwatch.cpp
  2. 7
    7
      Marlin/stopwatch.h

+ 6
- 6
Marlin/stopwatch.cpp View File

@@ -33,7 +33,7 @@ bool Stopwatch::stop() {
33 33
   #endif
34 34
 
35 35
   if (this->isRunning() || this->isPaused()) {
36
-    this->state = STOPWATCH_STOPPED;
36
+    this->state = STOPPED;
37 37
     this->stopTimestamp = millis();
38 38
     return true;
39 39
   }
@@ -46,7 +46,7 @@ bool Stopwatch::pause() {
46 46
   #endif
47 47
 
48 48
   if (this->isRunning()) {
49
-    this->state = STOPWATCH_PAUSED;
49
+    this->state = PAUSED;
50 50
     this->stopTimestamp = millis();
51 51
     return true;
52 52
   }
@@ -62,7 +62,7 @@ bool Stopwatch::start() {
62 62
     if (this->isPaused()) this->accumulator = this->duration();
63 63
     else this->reset();
64 64
 
65
-    this->state = STOPWATCH_RUNNING;
65
+    this->state = RUNNING;
66 66
     this->startTimestamp = millis();
67 67
     return true;
68 68
   }
@@ -74,18 +74,18 @@ void Stopwatch::reset() {
74 74
     Stopwatch::debug(PSTR("reset"));
75 75
   #endif
76 76
 
77
-  this->state = STOPWATCH_STOPPED;
77
+  this->state = STOPPED;
78 78
   this->startTimestamp = 0;
79 79
   this->stopTimestamp = 0;
80 80
   this->accumulator = 0;
81 81
 }
82 82
 
83 83
 bool Stopwatch::isRunning() {
84
-  return (this->state == STOPWATCH_RUNNING) ? true : false;
84
+  return (this->state == RUNNING) ? true : false;
85 85
 }
86 86
 
87 87
 bool Stopwatch::isPaused() {
88
-  return (this->state == STOPWATCH_PAUSED) ? true : false;
88
+  return (this->state == PAUSED) ? true : false;
89 89
 }
90 90
 
91 91
 millis_t Stopwatch::duration() {

+ 7
- 7
Marlin/stopwatch.h View File

@@ -28,12 +28,6 @@
28 28
 // Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
29 29
 //#define DEBUG_STOPWATCH
30 30
 
31
-enum StopwatchState {
32
-  STOPWATCH_STOPPED,
33
-  STOPWATCH_RUNNING,
34
-  STOPWATCH_PAUSED
35
-};
36
-
37 31
 /**
38 32
  * @brief Stopwatch class
39 33
  * @details This class acts as a timer proving stopwatch functionality including
@@ -41,7 +35,13 @@ enum StopwatchState {
41 35
  */
42 36
 class Stopwatch {
43 37
   private:
44
-    StopwatchState state;
38
+    enum State {
39
+      STOPPED,
40
+      RUNNING,
41
+      PAUSED
42
+    };
43
+
44
+    Stopwatch::State state;
45 45
     millis_t accumulator;
46 46
     millis_t startTimestamp;
47 47
     millis_t stopTimestamp;

Loading…
Cancel
Save