From d5cdb412baaaf427eb343009273436abf39c7265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Fri, 17 Jun 2022 18:54:04 +0000 Subject: [PATCH] Introduce a way to read the previous tool used --- Firmware/Marlin_main.cpp | 2 +- Firmware/mmu2.cpp | 4 ++++ Firmware/mmu2.h | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 1bf919a2b..f9725a9c7 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3511,7 +3511,7 @@ static void mmu_M600_wait_and_beep() { /// @brief load filament for mmu v2 /// @par nozzle_temp nozzle temperature to load filament void mmu_M600_load_filament(bool automatic, float nozzle_temp) { - uint8_t tmp_extruder = MMU2::mmu2.get_current_tool(); + uint8_t tmp_extruder = MMU2::mmu2.get_previous_tool(); // TODO SpoolJoin /*if (automatic) { diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 116a02cba..73709e534 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -85,6 +85,7 @@ MMU2::MMU2() : is_mmu_error_monitor_active(false) , logic(&mmu2Serial) , extruder(MMU2_NO_TOOL) + , previous_extruder(MMU2_NO_TOOL) , resume_position() , resume_hotend_temp(0) , logicStepLastStatus(StepStatus::Finished) @@ -228,6 +229,7 @@ bool MMU2::tool_change(uint8_t index) { // SERIAL_ECHOLN(current_position[E_AXIS]); extruder = index; //filament change is finished + previous_extruder = extruder; SetActiveExtruder(0); // @@TODO really report onto the serial? May be for the Octoprint? Not important now @@ -260,6 +262,7 @@ bool MMU2::tool_change(char code, uint8_t slot) { logic.ToolChange(slot); manage_response(false, false); extruder = slot; + previous_extruder = extruder; SetActiveExtruder(0); set_extrude_min_temp(EXTRUDE_MINTEMP); } break; @@ -383,6 +386,7 @@ bool MMU2::load_filament_to_nozzle(uint8_t index) { execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, sizeof(load_to_nozzle_sequence) / sizeof (load_to_nozzle_sequence[0])); extruder = index; + previous_extruder = extruder; SetActiveExtruder(0); Sound_MakeSound(e_SOUND_TYPE_StandardConfirm); diff --git a/Firmware/mmu2.h b/Firmware/mmu2.h index 1870c9933..4f9306e8f 100644 --- a/Firmware/mmu2.h +++ b/Firmware/mmu2.h @@ -107,6 +107,9 @@ public: /// @returns the active filament slot index (0-4) or 0xff in case of no active tool uint8_t get_current_tool() const; + + /// @returns the previous active filament slot index (0-4) or 0xff in case of no active tool at boot-up + inline uint8_t get_previous_tool() const { return previous_extruder; }; bool set_filament_type(uint8_t index, uint8_t type); @@ -201,6 +204,7 @@ private: ProtocolLogic logic; ///< implementation of the protocol logic layer int extruder; ///< currently active slot in the MMU ... somewhat... not sure where to get it from yet + uint8_t previous_extruder; ///< last active slot in the MMU, useful for M600 xyz_pos_t resume_position; int16_t resume_hotend_temp;