Browse Source

Clean up MMU2 code (#20794)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Giuliano Zaro 4 years ago
parent
commit
876c2586b9
No account linked to committer's email address
3 changed files with 26 additions and 38 deletions
  1. 18
    26
      Marlin/src/feature/mmu/mmu2.cpp
  2. 0
    1
      Marlin/src/feature/mmu/mmu2.h
  3. 8
    11
      Marlin/src/lcd/menu/menu_mmu2.cpp

+ 18
- 26
Marlin/src/feature/mmu/mmu2.cpp View File

@@ -167,6 +167,8 @@ void MMU2::mmu_loop() {
167 167
 
168 168
     case -1:
169 169
       if (rx_start()) {
170
+        prev_P0_request = millis();   // Initialize finda sensor timeout
171
+
170 172
         DEBUG_ECHOLNPGM("MMU => 'start'");
171 173
         DEBUG_ECHOLNPGM("MMU <= 'S1'");
172 174
 
@@ -311,7 +313,7 @@ void MMU2::mmu_loop() {
311 313
         // if (finda_runout_valid) DEBUG_ECHOLNPAIR_F("MMU <= 'P0'\nMMU => ", finda, 6);
312 314
 
313 315
         if (!finda && finda_runout_valid) filament_runout();
314
-        if (cmd == 0) ready = true;
316
+        if (cmd == MMU_CMD_NONE) ready = true;
315 317
         state = 1;
316 318
       }
317 319
       else if (ELAPSED(millis(), prev_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
@@ -333,18 +335,20 @@ void MMU2::mmu_loop() {
333 335
       #endif
334 336
 
335 337
       if (rx_ok()) {
336
-        // Response to C0 mmu command in MMU2S model
337
-        bool can_reset = true;
338 338
         #if HAS_PRUSA_MMU2S
339
-          if (!mmu2s_triggered && last_cmd == MMU_CMD_C0) {
340
-            can_reset = false;
339
+          // Respond to C0 MMU command in MMU2S model
340
+          const bool keep_trying = !mmu2s_triggered && last_cmd == MMU_CMD_C0;
341
+          if (keep_trying) {
341 342
             // MMU ok received but filament sensor not triggered, retrying...
342 343
             DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)");
343 344
             DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)");
344 345
             MMU2_COMMAND("C0");
345 346
           }
347
+        #else
348
+          constexpr bool keep_trying = false;
346 349
         #endif
347
-        if (can_reset) {
350
+
351
+        if (!keep_trying) {
348 352
           DEBUG_ECHOLNPGM("MMU => 'ok'");
349 353
           ready = true;
350 354
           state = 1;
@@ -370,11 +374,7 @@ void MMU2::mmu_loop() {
370 374
  */
371 375
 bool MMU2::rx_start() {
372 376
   // check for start message
373
-  if (rx_str_P(PSTR("start\n"))) {
374
-    prev_P0_request = millis();
375
-    return true;
376
-  }
377
-  return false;
377
+  return rx_str_P(PSTR("start\n"));
378 378
 }
379 379
 
380 380
 /**
@@ -385,13 +385,13 @@ bool MMU2::rx_str_P(const char* str) {
385 385
 
386 386
   while (MMU2_SERIAL.available()) {
387 387
     rx_buffer[i++] = MMU2_SERIAL.read();
388
-    rx_buffer[i] = '\0';
389 388
 
390 389
     if (i == sizeof(rx_buffer) - 1) {
391 390
       DEBUG_ECHOLNPGM("rx buffer overrun");
392 391
       break;
393 392
     }
394 393
   }
394
+  rx_buffer[i] = '\0';
395 395
 
396 396
   uint8_t len = strlen_P(str);
397 397
 
@@ -416,7 +416,6 @@ void MMU2::tx_str_P(const char* str) {
416 416
   clear_rx_buffer();
417 417
   uint8_t len = strlen_P(str);
418 418
   LOOP_L_N(i, len) MMU2_SERIAL.write(pgm_read_byte(str++));
419
-  rx_buffer[0] = '\0';
420 419
   prev_request = millis();
421 420
 }
422 421
 
@@ -427,7 +426,6 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) {
427 426
   clear_rx_buffer();
428 427
   uint8_t len = sprintf_P(tx_buffer, format, argument);
429 428
   LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
430
-  rx_buffer[0] = '\0';
431 429
   prev_request = millis();
432 430
 }
433 431
 
@@ -438,7 +436,6 @@ void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
438 436
   clear_rx_buffer();
439 437
   uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
440 438
   LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
441
-  rx_buffer[0] = '\0';
442 439
   prev_request = millis();
443 440
 }
444 441
 
@@ -570,7 +567,7 @@ static void mmu2_not_responding() {
570 567
 
571 568
         case 'c': {
572 569
           while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
573
-          execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
570
+          load_to_nozzle();
574 571
         } break;
575 572
       }
576 573
 
@@ -791,7 +788,7 @@ bool MMU2::get_response() {
791 788
 }
792 789
 
793 790
 /**
794
- * Wait for response and deal with timeout if nexcessary
791
+ * Wait for response and deal with timeout if necessary
795 792
  */
796 793
 void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
797 794
 
@@ -917,6 +914,7 @@ void MMU2::filament_runout() {
917 914
 // Load filament into MMU2
918 915
 void MMU2::load_filament(const uint8_t index) {
919 916
   if (!enabled) return;
917
+
920 918
   command(MMU_CMD_L0 + index);
921 919
   manage_response(false, false);
922 920
   BUZZ(200, 404);
@@ -935,6 +933,7 @@ bool MMU2::load_filament_to_nozzle(const uint8_t index) {
935 933
     return false;
936 934
   }
937 935
 
936
+  DISABLE_AXIS_E0();
938 937
   command(MMU_CMD_T0 + index);
939 938
   manage_response(true, true);
940 939
 
@@ -957,7 +956,6 @@ bool MMU2::load_filament_to_nozzle(const uint8_t index) {
957 956
  * filament to nozzle.
958 957
  */
959 958
 void MMU2::load_to_nozzle() {
960
-  if (!enabled) return;
961 959
   execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
962 960
 }
963 961
 
@@ -1020,7 +1018,8 @@ bool MMU2::unload() {
1020 1018
     return false;
1021 1019
   }
1022 1020
 
1023
-  filament_ramming();
1021
+  // Unload sequence to optimize shape of the tip of the unloaded filament
1022
+  execute_extruder_sequence((const E_Step *)ramming_sequence, sizeof(ramming_sequence) / sizeof(E_Step));
1024 1023
 
1025 1024
   command(MMU_CMD_U0);
1026 1025
   manage_response(false, true);
@@ -1035,13 +1034,6 @@ bool MMU2::unload() {
1035 1034
   return true;
1036 1035
 }
1037 1036
 
1038
-/**
1039
- * Unload sequence to optimize shape of the tip of the unloaded filament
1040
- */
1041
-void MMU2::filament_ramming() {
1042
-  execute_extruder_sequence((const E_Step *)ramming_sequence, sizeof(ramming_sequence) / sizeof(E_Step));
1043
-}
1044
-
1045 1037
 void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {
1046 1038
 
1047 1039
   planner.synchronize();

+ 0
- 1
Marlin/src/feature/mmu/mmu2.h View File

@@ -71,7 +71,6 @@ private:
71 71
   static void manage_response(const bool move_axes, const bool turn_off_nozzle);
72 72
 
73 73
   static void load_to_nozzle();
74
-  static void filament_ramming();
75 74
   static void execute_extruder_sequence(const E_Step * sequence, int steps);
76 75
 
77 76
   static void filament_runout();

+ 8
- 11
Marlin/src/lcd/menu/menu_mmu2.cpp View File

@@ -32,15 +32,12 @@
32 32
 // Load Filament
33 33
 //
34 34
 
35
-void _mmu2_load_filamentToNozzle(uint8_t index) {
35
+inline void action_mmu2_load_filament_to_nozzle(const uint8_t tool) {
36 36
   ui.reset_status();
37 37
   ui.return_to_status();
38
-  ui.status_printf_P(0,  GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
39
-  if (mmu2.load_filament_to_nozzle(index)) ui.reset_status();
40
-}
41
-
42
-inline void action_mmu2_load_filament_to_nozzle(const uint8_t tool) {
43
-  _mmu2_load_filamentToNozzle(tool);
38
+  ui.status_printf_P(0,  GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(tool + 1));
39
+  if (mmu2.load_filament_to_nozzle(tool))
40
+    ui.reset_status();
44 41
   ui.return_to_status();
45 42
 }
46 43
 
@@ -59,14 +56,14 @@ void menu_mmu2_load_filament() {
59 56
   START_MENU();
60 57
   BACK_ITEM(MSG_MMU2_MENU);
61 58
   ACTION_ITEM(MSG_MMU2_ALL, action_mmu2_load_all);
62
-  LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_load_filament(MenuItemBase::itemIndex); });
59
+  LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_load_filament(MenuItemBase::itemIndex); });
63 60
   END_MENU();
64 61
 }
65 62
 
66 63
 void menu_mmu2_load_to_nozzle() {
67 64
   START_MENU();
68 65
   BACK_ITEM(MSG_MMU2_MENU);
69
-  LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_load_filament_to_nozzle(MenuItemBase::itemIndex); });
66
+  LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_load_filament_to_nozzle(MenuItemBase::itemIndex); });
70 67
   END_MENU();
71 68
 }
72 69
 
@@ -92,7 +89,7 @@ void action_mmu2_unload_filament() {
92 89
 void menu_mmu2_eject_filament() {
93 90
   START_MENU();
94 91
   BACK_ITEM(MSG_MMU2_MENU);
95
-  LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_eject_filament(MenuItemBase::itemIndex); });
92
+  LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_eject_filament(MenuItemBase::itemIndex); });
96 93
   END_MENU();
97 94
 }
98 95
 
@@ -133,7 +130,7 @@ void menu_mmu2_choose_filament() {
133 130
   #if LCD_HEIGHT > 2
134 131
     STATIC_ITEM(MSG_MMU2_CHOOSE_FILAMENT_HEADER, SS_DEFAULT|SS_INVERT);
135 132
   #endif
136
-  LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_chosen(MenuItemBase::itemIndex); });
133
+  LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_chosen(MenuItemBase::itemIndex); });
137 134
   END_MENU();
138 135
 }
139 136
 

Loading…
Cancel
Save