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

+ 7
- 7
Marlin/stopwatch.h View File

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

Loading…
Cancel
Save