From 81cb0251f7404c586e2ff10a875febf53f43681d Mon Sep 17 00:00:00 2001 From: GMagician Date: Sat, 16 Jan 2021 15:58:18 +0100 Subject: [PATCH 1/4] MMU2 fixes - Removed functions called once - Removed fixed 5 and replace with EXTRUDERS (needed by SMuFF) - Added a turn off extruder - Removed duplicated "clear rx buffer" code --- Marlin/src/feature/mmu/mmu2.cpp | 33 +++++++++++-------------------- Marlin/src/feature/mmu/mmu2.h | 1 - Marlin/src/lcd/menu/menu_mmu2.cpp | 21 +++++++++----------- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/Marlin/src/feature/mmu/mmu2.cpp b/Marlin/src/feature/mmu/mmu2.cpp index a4b7f257a9b8..31cb17409d10 100644 --- a/Marlin/src/feature/mmu/mmu2.cpp +++ b/Marlin/src/feature/mmu/mmu2.cpp @@ -167,6 +167,8 @@ void MMU2::mmu_loop() { case -1: if (rx_start()) { + prev_P0_request = millis(); // Initialize finda sensor timeout + DEBUG_ECHOLNPGM("MMU => 'start'"); DEBUG_ECHOLNPGM("MMU <= 'S1'"); @@ -311,7 +313,7 @@ void MMU2::mmu_loop() { // if (finda_runout_valid) DEBUG_ECHOLNPAIR_F("MMU <= 'P0'\nMMU => ", finda, 6); if (!finda && finda_runout_valid) filament_runout(); - if (cmd == 0) ready = true; + if (cmd == MMU_CMD_NONE) ready = true; state = 1; } else if (ELAPSED(millis(), prev_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s) @@ -337,7 +339,6 @@ void MMU2::mmu_loop() { bool can_reset = true; #if HAS_PRUSA_MMU2S if (!mmu2s_triggered && last_cmd == MMU_CMD_C0) { - can_reset = false; // MMU ok received but filament sensor not triggered, retrying... DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)"); DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)"); @@ -370,11 +371,7 @@ void MMU2::mmu_loop() { */ bool MMU2::rx_start() { // check for start message - if (rx_str_P(PSTR("start\n"))) { - prev_P0_request = millis(); - return true; - } - return false; + return rx_str_P(PSTR("start\n")); } /** @@ -385,13 +382,13 @@ bool MMU2::rx_str_P(const char* str) { while (MMU2_SERIAL.available()) { rx_buffer[i++] = MMU2_SERIAL.read(); - rx_buffer[i] = '\0'; if (i == sizeof(rx_buffer) - 1) { DEBUG_ECHOLNPGM("rx buffer overrun"); break; } } + rx_buffer[i] = '\0'; uint8_t len = strlen_P(str); @@ -416,7 +413,6 @@ void MMU2::tx_str_P(const char* str) { clear_rx_buffer(); uint8_t len = strlen_P(str); LOOP_L_N(i, len) MMU2_SERIAL.write(pgm_read_byte(str++)); - rx_buffer[0] = '\0'; prev_request = millis(); } @@ -427,7 +423,6 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) { clear_rx_buffer(); uint8_t len = sprintf_P(tx_buffer, format, argument); LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]); - rx_buffer[0] = '\0'; prev_request = millis(); } @@ -438,7 +433,6 @@ void MMU2::tx_printf_P(const char* format, int argument1, int argument2) { clear_rx_buffer(); uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2); LOOP_L_N(i, len) MMU2_SERIAL.write(tx_buffer[i]); - rx_buffer[0] = '\0'; prev_request = millis(); } @@ -570,7 +564,7 @@ static void mmu2_not_responding() { case 'c': { 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)); + load_to_nozzle(); } break; } @@ -791,7 +785,7 @@ bool MMU2::get_response() { } /** - * Wait for response and deal with timeout if nexcessary + * Wait for response and deal with timeout if necessary */ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) { @@ -917,6 +911,7 @@ void MMU2::filament_runout() { // Load filament into MMU2 void MMU2::load_filament(const uint8_t index) { if (!enabled) return; + command(MMU_CMD_L0 + index); manage_response(false, false); BUZZ(200, 404); @@ -935,6 +930,7 @@ bool MMU2::load_filament_to_nozzle(const uint8_t index) { return false; } + DISABLE_AXIS_E0(); command(MMU_CMD_T0 + index); manage_response(true, true); @@ -957,7 +953,6 @@ bool MMU2::load_filament_to_nozzle(const uint8_t index) { * filament to nozzle. */ void MMU2::load_to_nozzle() { - if (!enabled) return; execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence)); } @@ -1020,7 +1015,8 @@ bool MMU2::unload() { return false; } - filament_ramming(); + // Unload sequence to optimize shape of the tip of the unloaded filament + execute_extruder_sequence((const E_Step *)ramming_sequence, sizeof(ramming_sequence) / sizeof(E_Step)); command(MMU_CMD_U0); manage_response(false, true); @@ -1035,13 +1031,6 @@ bool MMU2::unload() { return true; } -/** - * Unload sequence to optimize shape of the tip of the unloaded filament - */ -void MMU2::filament_ramming() { - execute_extruder_sequence((const E_Step *)ramming_sequence, sizeof(ramming_sequence) / sizeof(E_Step)); -} - void MMU2::execute_extruder_sequence(const E_Step * sequence, int steps) { planner.synchronize(); diff --git a/Marlin/src/feature/mmu/mmu2.h b/Marlin/src/feature/mmu/mmu2.h index 09ff3b668366..4326989a74b0 100644 --- a/Marlin/src/feature/mmu/mmu2.h +++ b/Marlin/src/feature/mmu/mmu2.h @@ -71,7 +71,6 @@ class MMU2 { static void manage_response(const bool move_axes, const bool turn_off_nozzle); static void load_to_nozzle(); - static void filament_ramming(); static void execute_extruder_sequence(const E_Step * sequence, int steps); static void filament_runout(); diff --git a/Marlin/src/lcd/menu/menu_mmu2.cpp b/Marlin/src/lcd/menu/menu_mmu2.cpp index 8a34e7d296fb..37c4997cf0c6 100644 --- a/Marlin/src/lcd/menu/menu_mmu2.cpp +++ b/Marlin/src/lcd/menu/menu_mmu2.cpp @@ -32,15 +32,12 @@ // Load Filament // -void _mmu2_load_filamentToNozzle(uint8_t index) { - ui.reset_status(); - ui.return_to_status(); - ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1)); - if (mmu2.load_filament_to_nozzle(index)) ui.reset_status(); -} - inline void action_mmu2_load_filament_to_nozzle(const uint8_t tool) { - _mmu2_load_filamentToNozzle(tool); + ui.reset_status(); + //ui.return_to_status(); I suspect it's useless here + ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(tool + 1)); + if (mmu2.load_filament_to_nozzle(tool)) + ui.reset_status(); ui.return_to_status(); } @@ -59,14 +56,14 @@ void menu_mmu2_load_filament() { START_MENU(); BACK_ITEM(MSG_MMU2_MENU); ACTION_ITEM(MSG_MMU2_ALL, action_mmu2_load_all); - LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_load_filament(MenuItemBase::itemIndex); }); + LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_load_filament(MenuItemBase::itemIndex); }); END_MENU(); } void menu_mmu2_load_to_nozzle() { START_MENU(); BACK_ITEM(MSG_MMU2_MENU); - LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_load_filament_to_nozzle(MenuItemBase::itemIndex); }); + LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_load_filament_to_nozzle(MenuItemBase::itemIndex); }); END_MENU(); } @@ -92,7 +89,7 @@ void action_mmu2_unload_filament() { void menu_mmu2_eject_filament() { START_MENU(); BACK_ITEM(MSG_MMU2_MENU); - LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_eject_filament(MenuItemBase::itemIndex); }); + LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ _mmu2_eject_filament(MenuItemBase::itemIndex); }); END_MENU(); } @@ -133,7 +130,7 @@ void menu_mmu2_choose_filament() { #if LCD_HEIGHT > 2 STATIC_ITEM(MSG_MMU2_CHOOSE_FILAMENT_HEADER, SS_DEFAULT|SS_INVERT); #endif - LOOP_L_N(i, 5) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_chosen(MenuItemBase::itemIndex); }); + LOOP_L_N(i, EXTRUDERS) ACTION_ITEM_N(i, MSG_MMU2_FILAMENT_N, []{ action_mmu2_chosen(MenuItemBase::itemIndex); }); END_MENU(); } From b8e261f8bed779417962e1a2a4ba52873abb330b Mon Sep 17 00:00:00 2001 From: GMagician Date: Sun, 17 Jan 2021 18:15:57 +0100 Subject: [PATCH 2/4] Fix missing part --- Marlin/src/feature/mmu/mmu2.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/src/feature/mmu/mmu2.cpp b/Marlin/src/feature/mmu/mmu2.cpp index 31cb17409d10..4c918dcce4eb 100644 --- a/Marlin/src/feature/mmu/mmu2.cpp +++ b/Marlin/src/feature/mmu/mmu2.cpp @@ -336,7 +336,6 @@ void MMU2::mmu_loop() { if (rx_ok()) { // Response to C0 mmu command in MMU2S model - bool can_reset = true; #if HAS_PRUSA_MMU2S if (!mmu2s_triggered && last_cmd == MMU_CMD_C0) { // MMU ok received but filament sensor not triggered, retrying... @@ -344,13 +343,14 @@ void MMU2::mmu_loop() { DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)"); MMU2_COMMAND("C0"); } + else #endif - if (can_reset) { + { DEBUG_ECHOLNPGM("MMU => 'ok'"); ready = true; state = 1; last_cmd = MMU_CMD_NONE; - } + } } else if (ELAPSED(millis(), prev_request + MMU_CMD_TIMEOUT)) { // resend request after timeout From 8bfd1b44ff0f82da3f90e00d73caf6d37e8549f6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 08:54:24 -0600 Subject: [PATCH 3/4] Update mmu2.cpp --- Marlin/src/feature/mmu/mmu2.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Marlin/src/feature/mmu/mmu2.cpp b/Marlin/src/feature/mmu/mmu2.cpp index 4c918dcce4eb..e3036947d576 100644 --- a/Marlin/src/feature/mmu/mmu2.cpp +++ b/Marlin/src/feature/mmu/mmu2.cpp @@ -335,22 +335,25 @@ void MMU2::mmu_loop() { #endif if (rx_ok()) { - // Response to C0 mmu command in MMU2S model #if HAS_PRUSA_MMU2S - if (!mmu2s_triggered && last_cmd == MMU_CMD_C0) { + // Respond to C0 MMU command in MMU2S model + const bool keep_trying = !mmu2s_triggered && last_cmd == MMU_CMD_C0; + if (keep_trying) { // MMU ok received but filament sensor not triggered, retrying... DEBUG_ECHOLNPGM("MMU => 'ok' (filament not present in gears)"); DEBUG_ECHOLNPGM("MMU <= 'C0' (keep trying)"); MMU2_COMMAND("C0"); } - else + #else + constexpr bool keep_trying = false; #endif - { + + if (!keep_trying) { DEBUG_ECHOLNPGM("MMU => 'ok'"); ready = true; state = 1; last_cmd = MMU_CMD_NONE; - } + } } else if (ELAPSED(millis(), prev_request + MMU_CMD_TIMEOUT)) { // resend request after timeout From 6b8307f71deebaf7c03b8c98e906f823c53d04ae Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 08:58:00 -0600 Subject: [PATCH 4/4] Update menu_mmu2.cpp --- Marlin/src/lcd/menu/menu_mmu2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/lcd/menu/menu_mmu2.cpp b/Marlin/src/lcd/menu/menu_mmu2.cpp index 37c4997cf0c6..7e71f00d2557 100644 --- a/Marlin/src/lcd/menu/menu_mmu2.cpp +++ b/Marlin/src/lcd/menu/menu_mmu2.cpp @@ -34,7 +34,7 @@ inline void action_mmu2_load_filament_to_nozzle(const uint8_t tool) { ui.reset_status(); - //ui.return_to_status(); I suspect it's useless here + ui.return_to_status(); ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(tool + 1)); if (mmu2.load_filament_to_nozzle(tool)) ui.reset_status();