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
 
167
 
168
     case -1:
168
     case -1:
169
       if (rx_start()) {
169
       if (rx_start()) {
170
+        prev_P0_request = millis();   // Initialize finda sensor timeout
171
+
170
         DEBUG_ECHOLNPGM("MMU => 'start'");
172
         DEBUG_ECHOLNPGM("MMU => 'start'");
171
         DEBUG_ECHOLNPGM("MMU <= 'S1'");
173
         DEBUG_ECHOLNPGM("MMU <= 'S1'");
172
 
174
 
311
         // if (finda_runout_valid) DEBUG_ECHOLNPAIR_F("MMU <= 'P0'\nMMU => ", finda, 6);
313
         // if (finda_runout_valid) DEBUG_ECHOLNPAIR_F("MMU <= 'P0'\nMMU => ", finda, 6);
312
 
314
 
313
         if (!finda && finda_runout_valid) filament_runout();
315
         if (!finda && finda_runout_valid) filament_runout();
314
-        if (cmd == 0) ready = true;
316
+        if (cmd == MMU_CMD_NONE) ready = true;
315
         state = 1;
317
         state = 1;
316
       }
318
       }
317
       else if (ELAPSED(millis(), prev_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
319
       else if (ELAPSED(millis(), prev_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
333
       #endif
335
       #endif
334
 
336
 
335
       if (rx_ok()) {
337
       if (rx_ok()) {
336
-        // Response to C0 mmu command in MMU2S model
337
-        bool can_reset = true;
338
         #if HAS_PRUSA_MMU2S
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
             // MMU ok received but filament sensor not triggered, retrying...
342
             // MMU ok received but filament sensor not triggered, retrying...
342
             DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)");
343
             DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)");
343
             DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)");
344
             DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)");
344
             MMU2_COMMAND("C0");
345
             MMU2_COMMAND("C0");
345
           }
346
           }
347
+        #else
348
+          constexpr bool keep_trying = false;
346
         #endif
349
         #endif
347
-        if (can_reset) {
350
+
351
+        if (!keep_trying) {
348
           DEBUG_ECHOLNPGM("MMU => 'ok'");
352
           DEBUG_ECHOLNPGM("MMU => 'ok'");
349
           ready = true;
353
           ready = true;
350
           state = 1;
354
           state = 1;
370
  */
374
  */
371
 bool MMU2::rx_start() {
375
 bool MMU2::rx_start() {
372
   // check for start message
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
 
385
 
386
   while (MMU2_SERIAL.available()) {
386
   while (MMU2_SERIAL.available()) {
387
     rx_buffer[i++] = MMU2_SERIAL.read();
387
     rx_buffer[i++] = MMU2_SERIAL.read();
388
-    rx_buffer[i] = '\0';
389
 
388
 
390
     if (i == sizeof(rx_buffer) - 1) {
389
     if (i == sizeof(rx_buffer) - 1) {
391
       DEBUG_ECHOLNPGM("rx buffer overrun");
390
       DEBUG_ECHOLNPGM("rx buffer overrun");
392
       break;
391
       break;
393
     }
392
     }
394
   }
393
   }
394
+  rx_buffer[i] = '\0';
395
 
395
 
396
   uint8_t len = strlen_P(str);
396
   uint8_t len = strlen_P(str);
397
 
397
 
416
   clear_rx_buffer();
416
   clear_rx_buffer();
417
   uint8_t len = strlen_P(str);
417
   uint8_t len = strlen_P(str);
418
   LOOP_L_N(i, len) MMU2_SERIAL.write(pgm_read_byte(str++));
418
   LOOP_L_N(i, len) MMU2_SERIAL.write(pgm_read_byte(str++));
419
-  rx_buffer[0] = '\0';
420
   prev_request = millis();
419
   prev_request = millis();
421
 }
420
 }
422
 
421
 
427
   clear_rx_buffer();
426
   clear_rx_buffer();
428
   uint8_t len = sprintf_P(tx_buffer, format, argument);
427
   uint8_t len = sprintf_P(tx_buffer, format, argument);
429
   LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
428
   LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
430
-  rx_buffer[0] = '\0';
431
   prev_request = millis();
429
   prev_request = millis();
432
 }
430
 }
433
 
431
 
438
   clear_rx_buffer();
436
   clear_rx_buffer();
439
   uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
437
   uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
440
   LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
438
   LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]);
441
-  rx_buffer[0] = '\0';
442
   prev_request = millis();
439
   prev_request = millis();
443
 }
440
 }
444
 
441
 
570
 
567
 
571
         case 'c': {
568
         case 'c': {
572
           while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
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
         } break;
571
         } break;
575
       }
572
       }
576
 
573
 
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
 void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
793
 void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
797
 
794
 
917
 // Load filament into MMU2
914
 // Load filament into MMU2
918
 void MMU2::load_filament(const uint8_t index) {
915
 void MMU2::load_filament(const uint8_t index) {
919
   if (!enabled) return;
916
   if (!enabled) return;
917
+
920
   command(MMU_CMD_L0 + index);
918
   command(MMU_CMD_L0 + index);
921
   manage_response(false, false);
919
   manage_response(false, false);
922
   BUZZ(200, 404);
920
   BUZZ(200, 404);
935
     return false;
933
     return false;
936
   }
934
   }
937
 
935
 
936
+  DISABLE_AXIS_E0();
938
   command(MMU_CMD_T0 + index);
937
   command(MMU_CMD_T0 + index);
939
   manage_response(true, true);
938
   manage_response(true, true);
940
 
939
 
957
  * filament to nozzle.
956
  * filament to nozzle.
958
  */
957
  */
959
 void MMU2::load_to_nozzle() {
958
 void MMU2::load_to_nozzle() {
960
-  if (!enabled) return;
961
   execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
959
   execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
962
 }
960
 }
963
 
961
 
1020
     return false;
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
   command(MMU_CMD_U0);
1024
   command(MMU_CMD_U0);
1026
   manage_response(false, true);
1025
   manage_response(false, true);
1035
   return true;
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
 void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {
1037
 void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) {
1046
 
1038
 
1047
   planner.synchronize();
1039
   planner.synchronize();

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

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

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

32
 // Load Filament
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
   ui.reset_status();
36
   ui.reset_status();
37
   ui.return_to_status();
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
   ui.return_to_status();
41
   ui.return_to_status();
45
 }
42
 }
46
 
43
 
59
   START_MENU();
56
   START_MENU();
60
   BACK_ITEM(MSG_MMU2_MENU);
57
   BACK_ITEM(MSG_MMU2_MENU);
61
   ACTION_ITEM(MSG_MMU2_ALL, action_mmu2_load_all);
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
   END_MENU();
60
   END_MENU();
64
 }
61
 }
65
 
62
 
66
 void menu_mmu2_load_to_nozzle() {
63
 void menu_mmu2_load_to_nozzle() {
67
   START_MENU();
64
   START_MENU();
68
   BACK_ITEM(MSG_MMU2_MENU);
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
   END_MENU();
67
   END_MENU();
71
 }
68
 }
72
 
69
 
92
 void menu_mmu2_eject_filament() {
89
 void menu_mmu2_eject_filament() {
93
   START_MENU();
90
   START_MENU();
94
   BACK_ITEM(MSG_MMU2_MENU);
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
   END_MENU();
93
   END_MENU();
97
 }
94
 }
98
 
95
 
133
   #if LCD_HEIGHT > 2
130
   #if LCD_HEIGHT > 2
134
     STATIC_ITEM(MSG_MMU2_CHOOSE_FILAMENT_HEADER, SS_DEFAULT|SS_INVERT);
131
     STATIC_ITEM(MSG_MMU2_CHOOSE_FILAMENT_HEADER, SS_DEFAULT|SS_INVERT);
135
   #endif
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
   END_MENU();
134
   END_MENU();
138
 }
135
 }
139
 
136
 

Loading…
Cancel
Save