Browse Source

Shrink debug code in TWIBus and disable by default

Scott Lahteine 8 years ago
parent
commit
1addb50b62
2 changed files with 42 additions and 13 deletions
  1. 27
    13
      Marlin/twibus.cpp
  2. 15
    0
      Marlin/twibus.h

+ 27
- 13
Marlin/twibus.cpp View File

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

@@ -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…
Cancel
Save