Kaynağa Gözat

Shrink debug code in Stopwatch and disable by default

Scott Lahteine 8 yıl önce
ebeveyn
işleme
21a6b66807
2 değiştirilmiş dosya ile 47 ekleme ve 9 silme
  1. 29
    6
      Marlin/stopwatch.cpp
  2. 18
    3
      Marlin/stopwatch.h

+ 29
- 6
Marlin/stopwatch.cpp Dosyayı Görüntüle

@@ -24,11 +24,14 @@
24 24
 #include "stopwatch.h"
25 25
 
26 26
 Stopwatch::Stopwatch() {
27
-   this->reset();
28
- }
27
+  this->reset();
28
+}
29 29
 
30 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 35
   if (!this->isRunning()) return;
33 36
 
34 37
   this->status = STPWTCH_STOPPED;
@@ -36,7 +39,10 @@ void Stopwatch::stop() {
36 39
 }
37 40
 
38 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 46
   if (!this->isRunning()) return;
41 47
 
42 48
   this->status = STPWTCH_PAUSED;
@@ -44,7 +50,10 @@ void Stopwatch::pause() {
44 50
 }
45 51
 
46 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 57
   if (this->isRunning()) return;
49 58
 
50 59
   if (this->isPaused()) this->accumulator = this->duration();
@@ -55,7 +64,9 @@ void Stopwatch::start() {
55 64
 }
56 65
 
57 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 71
   this->status = STPWTCH_STOPPED;
61 72
   this->startTimestamp = 0;
@@ -75,3 +86,15 @@ uint16_t Stopwatch::duration() {
75 86
   return (((this->isRunning()) ? millis() : this->stopTimestamp)
76 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 Dosyayı Görüntüle

@@ -23,10 +23,15 @@
23 23
 #ifndef STOPWATCH_H
24 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 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,6 +99,16 @@ class Stopwatch {
94 99
      * @return uint16_t
95 100
      */
96 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 114
 #endif //STOPWATCH_H

Loading…
İptal
Kaydet