Browse Source

🎨 MMU2 cleanup

Scott Lahteine 2 years ago
parent
commit
54a5bf5edf
1 changed files with 19 additions and 27 deletions
  1. 19
    27
      Marlin/src/feature/mmu/mmu2.cpp

+ 19
- 27
Marlin/src/feature/mmu/mmu2.cpp View File

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

Loading…
Cancel
Save