Browse Source

Shrink debug code in Stopwatch and disable by default

Scott Lahteine 8 years ago
parent
commit
21a6b66807
2 changed files with 47 additions and 9 deletions
  1. 29
    6
      Marlin/stopwatch.cpp
  2. 18
    3
      Marlin/stopwatch.h

+ 29
- 6
Marlin/stopwatch.cpp View File

24
 #include "stopwatch.h"
24
 #include "stopwatch.h"
25
 
25
 
26
 Stopwatch::Stopwatch() {
26
 Stopwatch::Stopwatch() {
27
-   this->reset();
28
- }
27
+  this->reset();
28
+}
29
 
29
 
30
 void Stopwatch::stop() {
30
 void Stopwatch::stop() {
31
-  if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("Stopwatch::stop()");
31
+  #if ENABLED(DEBUG_STOPWATCH)
32
+    debug(PSTR("stop"));
33
+  #endif
34
+
32
   if (!this->isRunning()) return;
35
   if (!this->isRunning()) return;
33
 
36
 
34
   this->status = STPWTCH_STOPPED;
37
   this->status = STPWTCH_STOPPED;
36
 }
39
 }
37
 
40
 
38
 void Stopwatch::pause() {
41
 void Stopwatch::pause() {
39
-  if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("Stopwatch::pause()");
42
+  #if ENABLED(DEBUG_STOPWATCH)
43
+    debug(PSTR("pause"));
44
+  #endif
45
+
40
   if (!this->isRunning()) return;
46
   if (!this->isRunning()) return;
41
 
47
 
42
   this->status = STPWTCH_PAUSED;
48
   this->status = STPWTCH_PAUSED;
44
 }
50
 }
45
 
51
 
46
 void Stopwatch::start() {
52
 void Stopwatch::start() {
47
-  if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("Stopwatch::start()");
53
+  #if ENABLED(DEBUG_STOPWATCH)
54
+    debug(PSTR("start"));
55
+  #endif
56
+
48
   if (this->isRunning()) return;
57
   if (this->isRunning()) return;
49
 
58
 
50
   if (this->isPaused()) this->accumulator = this->duration();
59
   if (this->isPaused()) this->accumulator = this->duration();
55
 }
64
 }
56
 
65
 
57
 void Stopwatch::reset() {
66
 void Stopwatch::reset() {
58
-  if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("Stopwatch::reset()");
67
+  #if ENABLED(DEBUG_STOPWATCH)
68
+    debug(PSTR("reset"));
69
+  #endif
59
 
70
 
60
   this->status = STPWTCH_STOPPED;
71
   this->status = STPWTCH_STOPPED;
61
   this->startTimestamp = 0;
72
   this->startTimestamp = 0;
75
   return (((this->isRunning()) ? millis() : this->stopTimestamp)
86
   return (((this->isRunning()) ? millis() : this->stopTimestamp)
76
           - this->startTimestamp) / 1000 + this->accumulator;
87
           - this->startTimestamp) / 1000 + this->accumulator;
77
 }
88
 }
89
+
90
+#if ENABLED(DEBUG_STOPWATCH)
91
+
92
+  void Stopwatch::debug(const char func[]) {
93
+    if (DEBUGGING(INFO)) {
94
+      SERIAL_ECHOPGM("Stopwatch::");
95
+      serialprintPGM(func);
96
+      SERIAL_ECHOLNPGM("()");
97
+    }
98
+  }
99
+
100
+#endif

+ 18
- 3
Marlin/stopwatch.h View File

23
 #ifndef STOPWATCH_H
23
 #ifndef STOPWATCH_H
24
 #define STOPWATCH_H
24
 #define STOPWATCH_H
25
 
25
 
26
+#include "macros.h"
27
+
28
+// Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
29
+//#define DEBUG_STOPWATCH
30
+
26
 enum StopwatchStatus {
31
 enum StopwatchStatus {
27
-  STPWTCH_STOPPED = 0x0,
28
-  STPWTCH_RUNNING = 0x1,
29
-  STPWTCH_PAUSED  = 0x2
32
+  STPWTCH_STOPPED,
33
+  STPWTCH_RUNNING,
34
+  STPWTCH_PAUSED
30
 };
35
 };
31
 
36
 
32
 /**
37
 /**
94
      * @return uint16_t
99
      * @return uint16_t
95
      */
100
      */
96
     uint16_t duration();
101
     uint16_t duration();
102
+
103
+    #if ENABLED(DEBUG_STOPWATCH)
104
+
105
+      /**
106
+       * @brief Prints a debug message
107
+       * @details Prints a simple debug message "Stopwatch::function"
108
+       */
109
+      static void debug(const char func[]);
110
+
111
+    #endif
97
 };
112
 };
98
 
113
 
99
 #endif //STOPWATCH_H
114
 #endif //STOPWATCH_H

Loading…
Cancel
Save