瀏覽代碼

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
  */
233
  */
234
 enum DebugFlags {
234
 enum DebugFlags {
235
   DEBUG_NONE          = 0,
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
 extern uint8_t marlin_debug_flags;
243
 extern uint8_t marlin_debug_flags;
244
 #define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F))
244
 #define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F))

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

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

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

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

28
 
28
 
29
 #include <Wire.h>
29
 #include <Wire.h>
30
 
30
 
31
-TWIBus::twibus() {
31
+TWIBus::TWIBus() {
32
   Wire.begin(); // We use no address so we will join the BUS as the master
32
   Wire.begin(); // We use no address so we will join the BUS as the master
33
   this->reset();
33
   this->reset();
34
 }
34
 }
42
 void TWIBus::address(uint8_t addr) {
42
 void TWIBus::address(uint8_t addr) {
43
   this->addr = addr;
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
 void TWIBus::addbyte(char c) {
50
 void TWIBus::addbyte(char c) {
52
   if (buffer_s >= sizeof(this->buffer)) return;
51
   if (buffer_s >= sizeof(this->buffer)) return;
53
   this->buffer[this->buffer_s++] = c;
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
 void TWIBus::send() {
59
 void TWIBus::send() {
62
   if (!this->addr) return;
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
   Wire.beginTransmission(this->addr);
66
   Wire.beginTransmission(this->addr);
66
   Wire.write(this->buffer, this->buffer_s);
67
   Wire.write(this->buffer, this->buffer_s);
72
 
73
 
73
 void TWIBus::reqbytes(uint8_t bytes) {
74
 void TWIBus::reqbytes(uint8_t bytes) {
74
   if (!this->addr) return;
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
   millis_t t = millis() + this->timeout;
81
   millis_t t = millis() + this->timeout;
81
   Wire.requestFrom(this->addr, bytes);
82
   Wire.requestFrom(this->addr, bytes);
101
   this->reset();
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
 #endif //EXPERIMENTAL_I2CBUS
118
 #endif //EXPERIMENTAL_I2CBUS

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

23
 #ifndef TWIBUS_H
23
 #ifndef TWIBUS_H
24
 #define TWIBUS_H
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
  * TWIBUS class
32
  * TWIBUS class
28
  *
33
  *
117
      * @param bytes the number of bytes to request
122
      * @param bytes the number of bytes to request
118
      */
123
      */
119
     void reqbytes(uint8_t bytes);
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
 #endif //TWIBUS_H
137
 #endif //TWIBUS_H

Loading…
取消
儲存