瀏覽代碼

Merge pull request #3578 from thinkyhead/rc_fix_twibus_less_debug_code

Reduce PROGMEM usage by TWIBus, stopwatch
Scott Lahteine 9 年之前
父節點
當前提交
7ddaa79ffe
共有 5 個檔案被更改,包括 96 行新增29 行删除
  1. 6
    6
      Marlin/Marlin.h
  2. 29
    6
      Marlin/stopwatch.cpp
  3. 18
    3
      Marlin/stopwatch.h
  4. 28
    14
      Marlin/twibus.cpp
  5. 15
    0
      Marlin/twibus.h

+ 6
- 6
Marlin/Marlin.h 查看文件

@@ -233,12 +233,12 @@ void kill(const char*);
233 233
  */
234 234
 enum DebugFlags {
235 235
   DEBUG_NONE          = 0,
236
-  DEBUG_ECHO          = _BV(0),
237
-  DEBUG_INFO          = _BV(1),
238
-  DEBUG_ERRORS        = _BV(2),
239
-  DEBUG_DRYRUN        = _BV(3),
240
-  DEBUG_COMMUNICATION = _BV(4),
241
-  DEBUG_LEVELING      = _BV(5)
236
+  DEBUG_ECHO          = _BV(0), ///< Echo commands in order as they are processed
237
+  DEBUG_INFO          = _BV(1), ///< Print messages for code that has debug output
238
+  DEBUG_ERRORS        = _BV(2), ///< Not implemented
239
+  DEBUG_DRYRUN        = _BV(3), ///< Ignore temperature setting and E movement commands
240
+  DEBUG_COMMUNICATION = _BV(4), ///< Not implemented
241
+  DEBUG_LEVELING      = _BV(5)  ///< Print detailed output for homing and leveling
242 242
 };
243 243
 extern uint8_t marlin_debug_flags;
244 244
 #define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F))

+ 29
- 6
Marlin/stopwatch.cpp 查看文件

@@ -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 查看文件

@@ -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

+ 28
- 14
Marlin/twibus.cpp 查看文件

@@ -28,7 +28,7 @@
28 28
 
29 29
 #include <Wire.h>
30 30
 
31
-TWIBus::twibus() {
31
+TWIBus::TWIBus() {
32 32
   Wire.begin(); // We use no address so we will join the BUS as the master
33 33
   this->reset();
34 34
 }
@@ -42,25 +42,26 @@ void TWIBus::reset() {
42 42
 void TWIBus::address(uint8_t addr) {
43 43
   this->addr = addr;
44 44
 
45
-  if (DEBUGGING(INFO)) {
46
-    SERIAL_ECHOPAIR("TWIBus::sendto: ", this->addr);
47
-    SERIAL_EOL;
48
-  }
45
+  #if ENABLED(DEBUG_TWIBUS)
46
+    debug(PSTR("sendto"), this->addr);
47
+  #endif
49 48
 }
50 49
 
51 50
 void TWIBus::addbyte(char c) {
52 51
   if (buffer_s >= sizeof(this->buffer)) return;
53 52
   this->buffer[this->buffer_s++] = c;
54 53
 
55
-  if (DEBUGGING(INFO)) {
56
-    SERIAL_ECHOPAIR("TWIBus::addbyte: ", this->buffer[this->buffer_s -1]);
57
-    SERIAL_EOL;
58
-  }
54
+  #if ENABLED(DEBUG_TWIBUS)
55
+    debug(PSTR("addbyte"), this->buffer[this->buffer_s - 1]);
56
+  #endif
59 57
 }
60 58
 
61 59
 void TWIBus::send() {
62 60
   if (!this->addr) return;
63
-  if (DEBUGGING(INFO)) SERIAL_ECHOLNPGM("TWIBus::send()");
61
+
62
+  #if ENABLED(DEBUG_TWIBUS)
63
+    debug(PSTR("send()"));
64
+  #endif
64 65
 
65 66
   Wire.beginTransmission(this->addr);
66 67
   Wire.write(this->buffer, this->buffer_s);
@@ -72,10 +73,10 @@ void TWIBus::send() {
72 73
 
73 74
 void TWIBus::reqbytes(uint8_t bytes) {
74 75
   if (!this->addr) return;
75
-  if (DEBUGGING(INFO)) {
76
-    SERIAL_ECHOPAIR("TWIBus::reqbytes(): ", bytes);
77
-    SERIAL_EOL;
78
-  }
76
+
77
+  #if ENABLED(DEBUG_TWIBUS)
78
+    debug(PSTR("reqbytes"), bytes);
79
+  #endif
79 80
 
80 81
   millis_t t = millis() + this->timeout;
81 82
   Wire.requestFrom(this->addr, bytes);
@@ -101,4 +102,17 @@ void TWIBus::reqbytes(uint8_t bytes) {
101 102
   this->reset();
102 103
 }
103 104
 
105
+#if ENABLED(DEBUG_TWIBUS)
106
+
107
+  void TWIBus::debug(const char func[], int32_t val/*=-1*/) {
108
+    if (DEBUGGING(INFO)) {
109
+      SERIAL_ECHOPGM("TWIBus::");
110
+      serialprintPGM(func);
111
+      if (val >= 0) SERIAL_ECHOPAIR(": ", val);
112
+      SERIAL_EOL;
113
+    }
114
+  }
115
+
116
+#endif
117
+
104 118
 #endif //EXPERIMENTAL_I2CBUS

+ 15
- 0
Marlin/twibus.h 查看文件

@@ -23,6 +23,11 @@
23 23
 #ifndef TWIBUS_H
24 24
 #define TWIBUS_H
25 25
 
26
+#include "macros.h"
27
+
28
+// Print debug messages with M111 S2 (Uses 236 bytes of PROGMEM)
29
+//#define DEBUG_TWIBUS
30
+
26 31
 /**
27 32
  * TWIBUS class
28 33
  *
@@ -117,6 +122,16 @@ class TWIBus {
117 122
      * @param bytes the number of bytes to request
118 123
      */
119 124
     void reqbytes(uint8_t bytes);
125
+
126
+    #if ENABLED(DEBUG_TWIBUS)
127
+
128
+      /**
129
+       * @brief Prints a debug message
130
+       * @details Prints a simple debug message "TWIBus::function: value"
131
+       */
132
+      static void debug(const char func[], int32_t val = -1);
133
+
134
+    #endif
120 135
 };
121 136
 
122 137
 #endif //TWIBUS_H

Loading…
取消
儲存