Scott Lahteine před 2 roky
rodič
revize
54a5bf5edf
1 změnil soubory, kde provedl 19 přidání a 27 odebrání
  1. 19
    27
      Marlin/src/feature/mmu/mmu2.cpp

+ 19
- 27
Marlin/src/feature/mmu/mmu2.cpp Zobrazit soubor

@@ -54,7 +54,8 @@ MMU2 mmu2;
54 54
 #define MMU_CMD_TIMEOUT 45000UL // 45s timeout for mmu commands (except P0)
55 55
 #define MMU_P0_TIMEOUT 3000UL   // Timeout for P0 command: 3seconds
56 56
 
57
-#define MMU2_COMMAND(S) tx_str(F(S "\n"))
57
+#define MMU2_SEND(S) tx_str(F(S "\n"))
58
+#define MMU2_RECV(S) rx_str(F(S "\n"))
58 59
 
59 60
 #if ENABLED(MMU_EXTRUDER_SENSOR)
60 61
   uint8_t mmu_idl_sens = 0;
@@ -131,7 +132,7 @@ void MMU2::reset() {
131 132
     safe_delay(20);
132 133
     WRITE(MMU2_RST_PIN, HIGH);
133 134
   #else
134
-    MMU2_COMMAND("X0"); // Send soft reset
135
+    MMU2_SEND("X0");  // Send soft reset
135 136
   #endif
136 137
 }
137 138
 
@@ -157,11 +158,9 @@ void MMU2::mmu_loop() {
157 158
     case -1:
158 159
       if (rx_start()) {
159 160
         prev_P0_request = millis();   // Initialize finda sensor timeout
160
-
161 161
         DEBUG_ECHOLNPGM("MMU => 'start'");
162 162
         DEBUG_ECHOLNPGM("MMU <= 'S1'");
163
-
164
-        MMU2_COMMAND("S1");   // Read Version
163
+        MMU2_SEND("S1");    // Read Version
165 164
         state = -2;
166 165
       }
167 166
       else if (millis() > 30000) { // 30sec after reset disable MMU
@@ -173,10 +172,8 @@ void MMU2::mmu_loop() {
173 172
     case -2:
174 173
       if (rx_ok()) {
175 174
         sscanf(rx_buffer, "%huok\n", &version);
176
-
177 175
         DEBUG_ECHOLNPGM("MMU => ", version, "\nMMU <= 'S2'");
178
-
179
-        MMU2_COMMAND("S2");   // Read Build Number
176
+        MMU2_SEND("S2");    // Read Build Number
180 177
         state = -3;
181 178
       }
182 179
       break;
@@ -191,14 +188,12 @@ void MMU2::mmu_loop() {
191 188
 
192 189
         #if ENABLED(MMU2_MODE_12V)
193 190
           DEBUG_ECHOLNPGM("MMU <= 'M1'");
194
-
195
-          MMU2_COMMAND("M1");   // Stealth Mode
191
+          MMU2_SEND("M1");    // Stealth Mode
196 192
           state = -5;
197 193
 
198 194
         #else
199 195
           DEBUG_ECHOLNPGM("MMU <= 'P0'");
200
-
201
-          MMU2_COMMAND("P0");   // Read FINDA
196
+          MMU2_SEND("P0");    // Read FINDA
202 197
           state = -4;
203 198
         #endif
204 199
       }
@@ -209,10 +204,8 @@ void MMU2::mmu_loop() {
209 204
       // response to M1
210 205
       if (rx_ok()) {
211 206
         DEBUG_ECHOLNPGM("MMU => ok");
212
-
213 207
         DEBUG_ECHOLNPGM("MMU <= 'P0'");
214
-
215
-        MMU2_COMMAND("P0");   // Read FINDA
208
+        MMU2_SEND("P0");    // Read FINDA
216 209
         state = -4;
217 210
       }
218 211
       break;
@@ -250,14 +243,13 @@ void MMU2::mmu_loop() {
250 243
         else if (cmd == MMU_CMD_C0) {
251 244
           // continue loading
252 245
           DEBUG_ECHOLNPGM("MMU <= 'C0'");
253
-          MMU2_COMMAND("C0");
246
+          MMU2_SEND("C0");
254 247
           state = 3; // wait for response
255 248
         }
256 249
         else if (cmd == MMU_CMD_U0) {
257 250
           // unload current
258 251
           DEBUG_ECHOLNPGM("MMU <= 'U0'");
259
-
260
-          MMU2_COMMAND("U0");
252
+          MMU2_SEND("U0");
261 253
           state = 3; // wait for response
262 254
         }
263 255
         else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E0 + EXTRUDERS - 1)) {
@@ -270,7 +262,7 @@ void MMU2::mmu_loop() {
270 262
         else if (cmd == MMU_CMD_R0) {
271 263
           // recover after eject
272 264
           DEBUG_ECHOLNPGM("MMU <= 'R0'");
273
-          MMU2_COMMAND("R0");
265
+          MMU2_SEND("R0");
274 266
           state = 3; // wait for response
275 267
         }
276 268
         else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F0 + EXTRUDERS - 1)) {
@@ -285,7 +277,7 @@ void MMU2::mmu_loop() {
285 277
         cmd = MMU_CMD_NONE;
286 278
       }
287 279
       else if (ELAPSED(millis(), prev_P0_request + 300)) {
288
-        MMU2_COMMAND("P0"); // Read FINDA
280
+        MMU2_SEND("P0");  // Read FINDA
289 281
         state = 2; // wait for response
290 282
       }
291 283
 
@@ -314,7 +306,7 @@ void MMU2::mmu_loop() {
314 306
         if (mmu_idl_sens) {
315 307
           if (FILAMENT_PRESENT() && mmu_loading_flag) {
316 308
             DEBUG_ECHOLNPGM("MMU <= 'A'");
317
-            MMU2_COMMAND("A"); // send 'abort' request
309
+            MMU2_SEND("A");   // send 'abort' request
318 310
             mmu_idl_sens = 0;
319 311
             DEBUG_ECHOLNPGM("MMU IDLER_SENSOR = 0 - ABORT");
320 312
           }
@@ -327,9 +319,9 @@ void MMU2::mmu_loop() {
327 319
           const bool keep_trying = !mmu2s_triggered && last_cmd == MMU_CMD_C0;
328 320
           if (keep_trying) {
329 321
             // MMU ok received but filament sensor not triggered, retrying...
330
-            DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)");
322
+            DEBUG_ECHOLNPGM("MMU => 'ok' (no filament in gears)");
331 323
             DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)");
332
-            MMU2_COMMAND("C0");
324
+            MMU2_SEND("C0");
333 325
           }
334 326
         #else
335 327
           constexpr bool keep_trying = false;
@@ -361,7 +353,7 @@ void MMU2::mmu_loop() {
361 353
  */
362 354
 bool MMU2::rx_start() {
363 355
   // check for start message
364
-  return rx_str(F("start\n"));
356
+  return MMU2_RECV("start");
365 357
 }
366 358
 
367 359
 /**
@@ -440,7 +432,7 @@ void MMU2::clear_rx_buffer() {
440 432
  * Check if we received 'ok' from MMU
441 433
  */
442 434
 bool MMU2::rx_ok() {
443
-  if (rx_str(F("ok\n"))) {
435
+  if (MMU2_RECV("ok")) {
444 436
     prev_P0_request = millis();
445 437
     return true;
446 438
   }
@@ -673,7 +665,7 @@ static void mmu2_not_responding() {
673 665
         // When (T0 rx->ok) load is ready, but in fact it did not load
674 666
         // successfully or an overload created pressure in the extruder.
675 667
         // Send (C0) to load more and move E_AXIS a little to release pressure.
676
-        if ((fil_present = FILAMENT_PRESENT())) MMU2_COMMAND("A");
668
+        if ((fil_present = FILAMENT_PRESENT())) MMU2_SEND("A");
677 669
       } while (!fil_present && PENDING(millis(), expire_ms));
678 670
       stepper.disable_extruder();
679 671
       manage_response(true, true);
@@ -882,7 +874,7 @@ void MMU2::filament_runout() {
882 874
     if (cmd == MMU_CMD_NONE && last_cmd == MMU_CMD_C0) {
883 875
       if (present && !mmu2s_triggered) {
884 876
         DEBUG_ECHOLNPGM("MMU <= 'A'");
885
-        tx_str(F("A\n"));
877
+        MMU2_SEND("A");
886 878
       }
887 879
       // Slowly spin the extruder during C0
888 880
       else {

Loading…
Zrušit
Uložit