浏览代码

Simplify TWIBus debug

Scott Lahteine 5 年前
父节点
当前提交
a84990961a
共有 2 个文件被更改,包括 22 次插入41 次删除
  1. 17
    39
      Marlin/src/feature/twibus.cpp
  2. 5
    2
      Marlin/src/feature/twibus.h

+ 17
- 39
Marlin/src/feature/twibus.cpp 查看文件

49
 
49
 
50
   addr = adr;
50
   addr = adr;
51
 
51
 
52
-  #if ENABLED(DEBUG_TWIBUS)
53
-    debug(PSTR("address"), adr);
54
-  #endif
52
+  debug(PSTR("address"), adr);
55
 }
53
 }
56
 
54
 
57
 void TWIBus::addbyte(const char c) {
55
 void TWIBus::addbyte(const char c) {
58
   if (buffer_s >= COUNT(buffer)) return;
56
   if (buffer_s >= COUNT(buffer)) return;
59
   buffer[buffer_s++] = c;
57
   buffer[buffer_s++] = c;
60
-  #if ENABLED(DEBUG_TWIBUS)
61
-    debug(PSTR("addbyte"), c);
62
-  #endif
58
+  debug(PSTR("addbyte"), c);
63
 }
59
 }
64
 
60
 
65
 void TWIBus::addbytes(char src[], uint8_t bytes) {
61
 void TWIBus::addbytes(char src[], uint8_t bytes) {
66
-  #if ENABLED(DEBUG_TWIBUS)
67
-    debug(PSTR("addbytes"), bytes);
68
-  #endif
62
+  debug(PSTR("addbytes"), bytes);
69
   while (bytes--) addbyte(*src++);
63
   while (bytes--) addbyte(*src++);
70
 }
64
 }
71
 
65
 
72
 void TWIBus::addstring(char str[]) {
66
 void TWIBus::addstring(char str[]) {
73
-  #if ENABLED(DEBUG_TWIBUS)
74
-    debug(PSTR("addstring"), str);
75
-  #endif
67
+  debug(PSTR("addstring"), str);
76
   while (char c = *str++) addbyte(c);
68
   while (char c = *str++) addbyte(c);
77
 }
69
 }
78
 
70
 
79
 void TWIBus::send() {
71
 void TWIBus::send() {
80
-  #if ENABLED(DEBUG_TWIBUS)
81
-    debug(PSTR("send"), addr);
82
-  #endif
72
+  debug(PSTR("send"), addr);
83
 
73
 
84
   Wire.beginTransmission(I2C_ADDRESS(addr));
74
   Wire.beginTransmission(I2C_ADDRESS(addr));
85
   Wire.write(buffer, buffer_s);
75
   Wire.write(buffer, buffer_s);
89
 }
79
 }
90
 
80
 
91
 // static
81
 // static
92
-void TWIBus::echoprefix(uint8_t bytes, const char prefix[], uint8_t adr) {
82
+void TWIBus::echoprefix(uint8_t bytes, const char pref[], uint8_t adr) {
93
   SERIAL_ECHO_START();
83
   SERIAL_ECHO_START();
94
-  serialprintPGM(prefix);
84
+  serialprintPGM(pref);
95
   SERIAL_ECHOPAIR(": from:", adr, " bytes:", bytes, " data:");
85
   SERIAL_ECHOPAIR(": from:", adr, " bytes:", bytes, " data:");
96
 }
86
 }
97
 
87
 
98
 // static
88
 // static
99
-void TWIBus::echodata(uint8_t bytes, const char prefix[], uint8_t adr) {
100
-  echoprefix(bytes, prefix, adr);
89
+void TWIBus::echodata(uint8_t bytes, const char pref[], uint8_t adr) {
90
+  echoprefix(bytes, pref, adr);
101
   while (bytes-- && Wire.available()) SERIAL_CHAR(Wire.read());
91
   while (bytes-- && Wire.available()) SERIAL_CHAR(Wire.read());
102
   SERIAL_EOL();
92
   SERIAL_EOL();
103
 }
93
 }
104
 
94
 
105
-void TWIBus::echobuffer(const char prefix[], uint8_t adr) {
106
-  echoprefix(buffer_s, prefix, adr);
95
+void TWIBus::echobuffer(const char pref[], uint8_t adr) {
96
+  echoprefix(buffer_s, pref, adr);
107
   LOOP_L_N(i, buffer_s) SERIAL_CHAR(buffer[i]);
97
   LOOP_L_N(i, buffer_s) SERIAL_CHAR(buffer[i]);
108
   SERIAL_EOL();
98
   SERIAL_EOL();
109
 }
99
 }
111
 bool TWIBus::request(const uint8_t bytes) {
101
 bool TWIBus::request(const uint8_t bytes) {
112
   if (!addr) return false;
102
   if (!addr) return false;
113
 
103
 
114
-  #if ENABLED(DEBUG_TWIBUS)
115
-    debug(PSTR("request"), bytes);
116
-  #endif
104
+  debug(PSTR("request"), bytes);
117
 
105
 
118
   // requestFrom() is a blocking function
106
   // requestFrom() is a blocking function
119
   if (Wire.requestFrom(addr, bytes) == 0) {
107
   if (Wire.requestFrom(addr, bytes) == 0) {
120
-    #if ENABLED(DEBUG_TWIBUS)
121
-      debug("request fail", addr);
122
-    #endif
108
+    debug("request fail", addr);
123
     return false;
109
     return false;
124
   }
110
   }
125
 
111
 
127
 }
113
 }
128
 
114
 
129
 void TWIBus::relay(const uint8_t bytes) {
115
 void TWIBus::relay(const uint8_t bytes) {
130
-  #if ENABLED(DEBUG_TWIBUS)
131
-    debug(PSTR("relay"), bytes);
132
-  #endif
116
+  debug(PSTR("relay"), bytes);
133
 
117
 
134
   if (request(bytes))
118
   if (request(bytes))
135
     echodata(bytes, PSTR("i2c-reply"), addr);
119
     echodata(bytes, PSTR("i2c-reply"), addr);
141
   while (count < bytes && Wire.available())
125
   while (count < bytes && Wire.available())
142
     dst[count++] = Wire.read();
126
     dst[count++] = Wire.read();
143
 
127
 
144
-  #if ENABLED(DEBUG_TWIBUS)
145
-    debug(PSTR("capture"), count);
146
-  #endif
128
+  debug(PSTR("capture"), count);
147
 
129
 
148
   return count;
130
   return count;
149
 }
131
 }
156
 #if I2C_SLAVE_ADDRESS > 0
138
 #if I2C_SLAVE_ADDRESS > 0
157
 
139
 
158
   void TWIBus::receive(uint8_t bytes) {
140
   void TWIBus::receive(uint8_t bytes) {
159
-    #if ENABLED(DEBUG_TWIBUS)
160
-      debug(PSTR("receive"), bytes);
161
-    #endif
141
+    debug(PSTR("receive"), bytes);
162
     echodata(bytes, PSTR("i2c-receive"), 0);
142
     echodata(bytes, PSTR("i2c-receive"), 0);
163
   }
143
   }
164
 
144
 
165
   void TWIBus::reply(char str[]/*=nullptr*/) {
145
   void TWIBus::reply(char str[]/*=nullptr*/) {
166
-    #if ENABLED(DEBUG_TWIBUS)
167
-      debug(PSTR("reply"), str);
168
-    #endif
146
+    debug(PSTR("reply"), str);
169
 
147
 
170
     if (str) {
148
     if (str) {
171
       reset();
149
       reset();

+ 5
- 2
Marlin/src/feature/twibus.h 查看文件

223
     #endif
223
     #endif
224
 
224
 
225
     #if ENABLED(DEBUG_TWIBUS)
225
     #if ENABLED(DEBUG_TWIBUS)
226
-
227
       /**
226
       /**
228
        * @brief Prints a debug message
227
        * @brief Prints a debug message
229
        * @details Prints a simple debug message "TWIBus::function: value"
228
        * @details Prints a simple debug message "TWIBus::function: value"
233
       static void debug(const char func[], char c);
232
       static void debug(const char func[], char c);
234
       static void debug(const char func[], char adr[]);
233
       static void debug(const char func[], char adr[]);
235
       static inline void debug(const char func[], uint8_t v) { debug(func, (uint32_t)v); }
234
       static inline void debug(const char func[], uint8_t v) { debug(func, (uint32_t)v); }
236
-
235
+    #else
236
+      static inline void debug(const char[], uint32_t) {}
237
+      static inline void debug(const char[], char) {}
238
+      static inline void debug(const char[], char[]) {}
239
+      static inline void debug(const char[], uint8_t) {}
237
     #endif
240
     #endif
238
 };
241
 };

正在加载...
取消
保存