From 1f9fc4ef3fee5acebc288236c8dcf728daa72172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 21 May 2023 15:37:11 +0000 Subject: [PATCH] MMU: add UnloadInner and CutFilamentInner Sync with the 32-bit side. The ReportingRAII does not handle recursion. Fixes an issue with the multiple calls to BeginReport() and EndReport() Change in memory: Flash: +14 bytes SRAM: 0 bytes --- Firmware/mmu2.cpp | 65 ++++++++++++++++++++++++++--------------------- Firmware/mmu2.h | 2 ++ 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index c9152f28b..cee4fb2a4 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -324,7 +324,7 @@ bool MMU2::ToolChangeCommonOnce(uint8_t slot) { // if the extruder has been parked, it will get unparked once the ToolChange command finishes OK // - so no ResumeUnpark() at this spot - unload(); + UnloadInner(); // if we run out of retries, we must do something ... may be raise an error screen and allow the user to do something // but honestly - if the MMU restarts during every toolchange, // something else is seriously broken and stopping a print is probably our best option. @@ -334,9 +334,9 @@ bool MMU2::ToolChangeCommonOnce(uint8_t slot) { if (VerifyFilamentEnteredPTFE()) { return true; // success } else { // Prepare a retry attempt - unload(); + UnloadInner(); if (retries == 2 && cutter_enabled()) { - cut_filament(slot, false); // try cutting filament tip at the last attempt + CutFilamentInner(slot); // try cutting filament tip at the last attempt } } } @@ -444,35 +444,48 @@ bool MMU2::set_filament_type(uint8_t /*slot*/, uint8_t /*type*/) { return true; } +void MMU2::UnloadInner() { + FSensorBlockRunout blockRunout; + filament_ramming(); + + // we assume the printer managed to relieve filament tip from the gears, + // so repeating that part in case of an MMU restart is not necessary + for (;;) { + Disable_E0(); + logic.UnloadFilament(); + if (manage_response(false, true)) + break; + IncrementMMUFails(); + } + MakeSound(Confirm); + + // no active tool + extruder = MMU2_NO_TOOL; + tool_change_extruder = MMU2_NO_TOOL; +} + bool MMU2::unload() { if (!WaitForMMUReady()) return false; WaitForHotendTargetTempBeep(); - { - FSensorBlockRunout blockRunout; - ReportingRAII rep(CommandInProgress::UnloadFilament); - filament_ramming(); + ReportingRAII rep(CommandInProgress::UnloadFilament); + UnloadInner(); - // we assume the printer managed to relieve filament tip from the gears, - // so repeating that part in case of an MMU restart is not necessary - for (;;) { - Disable_E0(); - logic.UnloadFilament(); - if (manage_response(false, true)) - break; - IncrementMMUFails(); - } - MakeSound(Confirm); - - // no active tool - extruder = MMU2_NO_TOOL; - tool_change_extruder = MMU2_NO_TOOL; - } return true; } +void MMU2::CutFilamentInner(uint8_t slot) { + for (;;) { + Disable_E0(); + logic.CutFilament(slot); + if (manage_response(false, true)) + break; + IncrementMMUFails(); + } +} + bool MMU2::cut_filament(uint8_t slot, bool enableFullScreenMsg /*= true*/) { if (!WaitForMMUReady()) return false; @@ -486,13 +499,7 @@ bool MMU2::cut_filament(uint8_t slot, bool enableFullScreenMsg /*= true*/) { } ReportingRAII rep(CommandInProgress::CutFilament); - for (;;) { - Disable_E0(); - logic.CutFilament(slot); - if (manage_response(false, true)) - break; - IncrementMMUFails(); - } + CutFilamentInner(slot); } extruder = MMU2_NO_TOOL; tool_change_extruder = MMU2_NO_TOOL; diff --git a/Firmware/mmu2.h b/Firmware/mmu2.h index e85246524..b34ee2af6 100644 --- a/Firmware/mmu2.h +++ b/Firmware/mmu2.h @@ -286,6 +286,8 @@ private: bool ToolChangeCommonOnce(uint8_t slot); void HelpUnloadToFinda(); + void UnloadInner(); + void CutFilamentInner(uint8_t slot); ProtocolLogic logic; ///< implementation of the protocol logic layer uint8_t extruder; ///< currently active slot in the MMU ... somewhat... not sure where to get it from yet