From 7c19a40af1061136aba611caddf24d4dc4b40bdf Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 18 Nov 2020 01:48:09 -0600 Subject: [PATCH] Cleanup after merge --- Marlin/Configuration_adv.h | 56 +++++------ Marlin/src/feature/mmu/mmu2.cpp | 164 ++++++++++++++++---------------- Marlin/src/feature/mmu/mmu2.h | 6 +- 3 files changed, 109 insertions(+), 117 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 9382b4f5cad0..4132f79e0b25 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3565,6 +3565,34 @@ // G-code to execute when MMU2 F.I.N.D.A. probe detects filament runout #define MMU2_FILAMENT_RUNOUT_SCRIPT "M600" + // Add an LCD menu for MMU2 + //#define MMU2_MENUS + + #if EITHER(MMU2_MENUS, HAS_PRUSA_MMU2S) + // Settings for filament load / unload. + // This is for Průša MK3-style extruders. Customize for your hardware. + #define MMU2_FILAMENTCHANGE_EJECT_FEED 80.0 + #define MMU2_LOAD_TO_NOZZLE_SEQUENCE \ + { 7.2, 1145 }, \ + { 14.4, 871 }, \ + { 36.0, 1393 }, \ + { 14.4, 871 }, \ + { 50.0, 198 } + + #define MMU2_RAMMING_SEQUENCE \ + { 1.0, 1000 }, \ + { 1.0, 1500 }, \ + { 2.0, 2000 }, \ + { 1.5, 3000 }, \ + { 2.5, 4000 }, \ + { -15.0, 5000 }, \ + { -14.0, 1200 }, \ + { -6.0, 600 }, \ + { 10.0, 700 }, \ + { -10.0, 400 }, \ + { -50.0, 2000 } + #endif + /** * Using a sensor like the MMU2S * This mode requires a MK3S extruder with a sensor at the extruder idler, like the MMU2S. @@ -3606,34 +3634,6 @@ #endif - // Add an LCD menu for MMU2 - //#define MMU2_MENUS - - #if EITHER(MMU2_MENUS, HAS_PRUSA_MMU2S) - // Settings for filament load / unload. - // This is for Průša MK3-style extruders. Customize for your hardware. - #define MMU2_FILAMENTCHANGE_EJECT_FEED 80.0 - #define MMU2_LOAD_TO_NOZZLE_SEQUENCE \ - { 7.2, 1145 }, \ - { 14.4, 871 }, \ - { 36.0, 1393 }, \ - { 14.4, 871 }, \ - { 50.0, 198 } - - #define MMU2_RAMMING_SEQUENCE \ - { 1.0, 1000 }, \ - { 1.0, 1500 }, \ - { 2.0, 2000 }, \ - { 1.5, 3000 }, \ - { 2.5, 4000 }, \ - { -15.0, 5000 }, \ - { -14.0, 1200 }, \ - { -6.0, 600 }, \ - { 10.0, 700 }, \ - { -10.0, 400 }, \ - { -50.0, 2000 } - #endif - //#define MMU2_DEBUG // Write debug info to serial output #endif // HAS_PRUSA_MMU2 diff --git a/Marlin/src/feature/mmu/mmu2.cpp b/Marlin/src/feature/mmu/mmu2.cpp index 53a749f068de..f7bde8847823 100644 --- a/Marlin/src/feature/mmu/mmu2.cpp +++ b/Marlin/src/feature/mmu/mmu2.cpp @@ -22,7 +22,7 @@ #include "../../inc/MarlinConfig.h" -#if ENABLED(PRUSA_MMU2) +#if HAS_PRUSA_MMU2 #include "mmu2.h" #include "../../lcd/menu/menu_mmu2.h" @@ -94,7 +94,7 @@ MMU2 mmu2; #define mmuSerial MMU2_SERIAL bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved; -#if ENABLED(PRUSA_MMU2_S_MODE) +#if HAS_PRUSA_MMU2S bool MMU2::mmu2s_triggered; #endif uint8_t MMU2::cmd, MMU2::cmd_arg, MMU2::last_cmd, MMU2::extruder; @@ -110,19 +110,18 @@ struct E_Step { feedRate_t feedRate; //!< feed rate in mm/s }; -// ramming_sequence and load_to_nozzle_sequence are required for PRUSA_MMU2_S_MODE too +// ramming_sequence and load_to_nozzle_sequence are required for MMU2 S Mode too static constexpr E_Step - #if EITHER(MMU2_MENUS, PRUSA_MMU2_S_MODE) + #if EITHER(MMU2_MENUS, HAS_PRUSA_MMU2S) ramming_sequence[] PROGMEM = { MMU2_RAMMING_SEQUENCE } , load_to_nozzle_sequence[] PROGMEM = { MMU2_LOAD_TO_NOZZLE_SEQUENCE } #endif - #if ENABLED(PRUSA_MMU2_S_MODE) + #if HAS_PRUSA_MMU2S , can_load_sequence[] PROGMEM = { MMU2_CAN_LOAD_SEQUENCE } , can_load_increment_sequence[] PROGMEM = { MMU2_CAN_LOAD_INCREMENT_SEQUENCE } #endif ; - MMU2::MMU2() { rx_buffer[0] = '\0'; } @@ -162,7 +161,7 @@ uint8_t MMU2::get_current_tool() { return extruder == MMU2_NO_TOOL ? -1 : extruder; } -#if EITHER(PRUSA_MMU2_S_MODE, MMU_EXTRUDER_SENSOR) +#if EITHER(HAS_PRUSA_MMU2S, MMU_EXTRUDER_SENSOR) #define FILAMENT_PRESENT() (READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE) #endif @@ -242,7 +241,7 @@ void MMU2::mmu_loop() { enabled = true; state = 1; - TERN_(PRUSA_MMU2_S_MODE, mmu2s_triggered = false); + TERN_(HAS_PRUSA_MMU2S, mmu2s_triggered = false); } break; @@ -307,7 +306,7 @@ void MMU2::mmu_loop() { state = 2; // wait for response } - TERN_(PRUSA_MMU2_S_MODE, check_filament()); + TERN_(HAS_PRUSA_MMU2S, check_filament()); break; case 2: // response to command P0 @@ -324,7 +323,7 @@ void MMU2::mmu_loop() { else if (ELAPSED(millis(), prev_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s) state = 1; - TERN_(PRUSA_MMU2_S_MODE, check_filament()); + TERN_(HAS_PRUSA_MMU2S, check_filament()); break; case 3: // response to mmu commands @@ -340,9 +339,9 @@ void MMU2::mmu_loop() { #endif if (rx_ok()) { - // Response to C0 mmu command in PRUSA_MMU2_S_MODE + // Response to C0 mmu command in MMU2 S Mode bool can_reset = true; - #if ENABLED(PRUSA_MMU2_S_MODE) + #if HAS_PRUSA_MMU2S if (!mmu2s_triggered && last_cmd == MMU_CMD_C0) { can_reset = false; // MMU ok received but filament sensor not triggered, retrying... @@ -367,7 +366,7 @@ void MMU2::mmu_loop() { } state = 1; } - TERN_(PRUSA_MMU2_S_MODE, check_filament()); + TERN_(HAS_PRUSA_MMU2S, check_filament()); break; } } @@ -487,7 +486,7 @@ static void mmu2_not_responding() { BUZZ(100, 659); } -#if ENABLED(PRUSA_MMU2_S_MODE) +#if HAS_PRUSA_MMU2S bool MMU2::load_to_gears() { command(MMU_CMD_C0); @@ -550,14 +549,14 @@ static void mmu2_not_responding() { switch (*special) { case '?': { - uint8_t index = mmu2_choose_filament(); + const uint8_t index = mmu2_choose_filament(); while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); load_filament_to_nozzle(index); } break; case 'x': { planner.synchronize(); - uint8_t index = mmu2_choose_filament(); + const uint8_t index = mmu2_choose_filament(); DISABLE_AXIS_E0(); command(MMU_CMD_T0 + index); manage_response(true, true); @@ -635,7 +634,7 @@ static void mmu2_not_responding() { switch (*special) { case '?': { DEBUG_ECHOLNPGM("case ?\n"); - uint8_t index = mmu2_choose_filament(); + const uint8_t index = mmu2_choose_filament(); while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); load_filament_to_nozzle(index); } break; @@ -643,7 +642,7 @@ static void mmu2_not_responding() { case 'x': { DEBUG_ECHOLNPGM("case x\n"); planner.synchronize(); - uint8_t index = mmu2_choose_filament(); + const uint8_t index = mmu2_choose_filament(); DISABLE_AXIS_E0(); command(MMU_CMD_T0 + index); manage_response(true, true); @@ -682,83 +681,83 @@ static void mmu2_not_responding() { mmu_idl_sens = 0; } -#elif DISABLED(MMU_EXTRUDER_SENSOR) && DISABLED(PRUSA_MMU2_S_MODE) +#else // !HAS_PRUSA_MMU2S && !MMU_EXTRUDER_SENSOR -/** - * Handle tool change - */ -void MMU2::tool_change(const uint8_t index) { - if (!enabled) return; + /** + * Handle tool change + */ + void MMU2::tool_change(const uint8_t index) { + if (!enabled) return; - set_runout_valid(false); + set_runout_valid(false); - if (index != extruder) { - DISABLE_AXIS_E0(); - ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1)); - command(MMU_CMD_T0 + index); - manage_response(true, true); - command(MMU_CMD_C0); - extruder = index; //filament change is finished - active_extruder = 0; - ENABLE_AXIS_E0(); - SERIAL_ECHO_START(); - SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder)); - ui.reset_status(); - } + if (index != extruder) { + DISABLE_AXIS_E0(); + ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1)); + command(MMU_CMD_T0 + index); + manage_response(true, true); + command(MMU_CMD_C0); + extruder = index; //filament change is finished + active_extruder = 0; + ENABLE_AXIS_E0(); + SERIAL_ECHO_START(); + SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder)); + ui.reset_status(); + } - set_runout_valid(true); -} + set_runout_valid(true); + } -/** - * Handle special T?/Tx/Tc commands - * - * T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically - * Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load. - * Tc Load to nozzle after filament was prepared by Tx and extruder nozzle is already heated. - */ -void MMU2::tool_change(const char* special) { - if (!enabled) return; + /** + * Handle special T?/Tx/Tc commands + * + * T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically + * Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load. + * Tc Load to nozzle after filament was prepared by Tx and extruder nozzle is already heated. + */ + void MMU2::tool_change(const char* special) { + #if ENABLED(MMU2_MENUS) - #if ENABLED(MMU2_MENUS) + if (!enabled) return; - set_runout_valid(false); + set_runout_valid(false); - switch (*special) { - case '?': { - DEBUG_ECHOLNPGM("case ?\n"); - uint8_t index = mmu2_choose_filament(); - while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); - load_filament_to_nozzle(index); - } break; + switch (*special) { + case '?': { + DEBUG_ECHOLNPGM("case ?\n"); + const uint8_t index = mmu2_choose_filament(); + while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); + load_filament_to_nozzle(index); + } break; - case 'x': { - DEBUG_ECHOLNPGM("case x\n"); - planner.synchronize(); - uint8_t index = mmu2_choose_filament(); - DISABLE_AXIS_E0(); - command(MMU_CMD_T0 + index); - manage_response(true, true); - command(MMU_CMD_C0); - mmu_loop(); + case 'x': { + DEBUG_ECHOLNPGM("case x\n"); + planner.synchronize(); + const uint8_t index = mmu2_choose_filament(); + DISABLE_AXIS_E0(); + command(MMU_CMD_T0 + index); + manage_response(true, true); + command(MMU_CMD_C0); + mmu_loop(); - ENABLE_AXIS_E0(); - extruder = index; - active_extruder = 0; - } break; + ENABLE_AXIS_E0(); + extruder = index; + active_extruder = 0; + } break; - case 'c': { - DEBUG_ECHOLNPGM("case c\n"); - while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); - execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence)); - } break; - } + case 'c': { + DEBUG_ECHOLNPGM("case c\n"); + while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100); + execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence)); + } break; + } - set_runout_valid(true); + set_runout_valid(true); - #endif + #endif } -#endif // MMU_EXTRUDER_SENSOR +#endif // !HAS_PRUSA_MMU2S && !MMU_EXTRUDER_SENSOR /** * Set next command @@ -890,7 +889,7 @@ void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) { DISABLE_AXIS_E0(); } -#if ENABLED(PRUSA_MMU2_S_MODE) +#if HAS_PRUSA_MMU2S void MMU2::check_filament() { const bool present = FILAMENT_PRESENT(); @@ -933,7 +932,6 @@ void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) { } #endif - /** * Switch material and load to nozzle */ @@ -973,7 +971,6 @@ void MMU2::load_to_nozzle() { execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence)); } - /** * Unload from hotend and retract to MMU */ @@ -1065,7 +1062,6 @@ void MMU2::filament_ramming() { return true; } - #endif // HAS_LCD_MENU && MMU2_MENUS #endif // PRUSA_MMU2 diff --git a/Marlin/src/feature/mmu/mmu2.h b/Marlin/src/feature/mmu/mmu2.h index 0d1dbb8e6fbf..02c86540c358 100644 --- a/Marlin/src/feature/mmu/mmu2.h +++ b/Marlin/src/feature/mmu/mmu2.h @@ -57,10 +57,6 @@ class MMU2 { static bool eject_filament(const uint8_t index, const bool recover); #endif - static bool unload(); - static void load_filament(uint8_t); - static bool load_filament_to_nozzle(const uint8_t index); - private: static bool rx_str_P(const char* str); static void tx_str_P(const char* str); @@ -78,9 +74,9 @@ class MMU2 { static void load_to_nozzle(); static void filament_ramming(); + static void execute_extruder_sequence(const E_Step * sequence, int steps); static void filament_runout(); - static void execute_extruder_sequence(const E_Step * sequence, int steps); #if HAS_PRUSA_MMU2S static bool mmu2s_triggered;