From bdc65cbb9a5b5706c95a5e33438f138693d778de Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Fri, 12 Jan 2024 21:17:47 +0100 Subject: [PATCH] Add clogging prevention if previous filament had higher temp on unload than filament on load --- src/marlin_stubs/pause/M701_2.cpp | 6 +- .../config_store/store_definition.cpp | 56 +++++++++++++++++++ .../config_store/store_definition.hpp | 11 ++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/marlin_stubs/pause/M701_2.cpp b/src/marlin_stubs/pause/M701_2.cpp index 19bbefc30d..1a475f9c22 100644 --- a/src/marlin_stubs/pause/M701_2.cpp +++ b/src/marlin_stubs/pause/M701_2.cpp @@ -38,7 +38,10 @@ using namespace filament_gcodes; bool filament_gcodes::load_unload([[maybe_unused]] LoadUnloadMode type, filament_gcodes::Func f_load_unload, pause::Settings &rSettings) { float disp_temp = marlin_vars()->active_hotend().display_nozzle; float targ_temp = Temperature::degTargetHotend(rSettings.GetExtruder()); - + float previous_filament_temp = filament::get_description(config_store().get_previous_filament_type(rSettings.GetExtruder())).nozzle; + if (previous_filament_temp > disp_temp) { + targ_temp = previous_filament_temp; + } if (disp_temp > targ_temp) { thermalManager.setTargetHotend(disp_temp, rSettings.GetExtruder()); } @@ -188,6 +191,7 @@ void filament_gcodes::M70X_process_user_response(PreheatStatus::Result res, uint switch (res) { case PreheatStatus::Result::DoneHasFilament: { auto filament = config_store().get_filament_type(target_extruder); + config_store().set_previous_filament_type(target_extruder, filament); auto preheat_temp = filament::get_description(filament).nozzle_preheat; thermalManager.setTargetHotend(preheat_temp, 0); break; diff --git a/src/persistent_stores/store_instances/config_store/store_definition.cpp b/src/persistent_stores/store_instances/config_store/store_definition.cpp index dbd8431124..a8f315b681 100644 --- a/src/persistent_stores/store_instances/config_store/store_definition.cpp +++ b/src/persistent_stores/store_instances/config_store/store_definition.cpp @@ -528,6 +528,62 @@ void CurrentStore::set_filament_type([[maybe_unused]] uint8_t index, filament::T #endif } +filament::Type CurrentStore::get_previous_filament_type([[maybe_unused]] uint8_t index) { +#if EXTRUDERS <= 1 + assert(index == 0); + return filament_prev_type_0.get(); +#else + switch (index) { + case 0: + return filament_prev_type_0.get(); + case 1: + return filament_prev_type_1.get(); + case 2: + return filament_prev_type_2.get(); + case 3: + return filament_prev_type_3.get(); + case 4: + return filament_prev_type_4.get(); + case 5: + return filament_prev_type_5.get(); + default: + assert(false && "invalid index"); + return {}; + } +#endif +} + +void CurrentStore::set_previous_filament_type([[maybe_unused]] uint8_t index, filament::Type value) { +#if EXTRUDERS <= 1 + assert(index == 0); + filament_type_0.set(value); +#else + switch (index) { + case 0: + filament_prev_type_0.set(value); + break; + case 1: + filament_prev_type_1.set(value); + break; + case 2: + filament_prev_type_2.set(value); + break; + case 3: + filament_prev_type_3.set(value); + break; + case 4: + filament_prev_type_4.set(value); + break; + case 5: + filament_prev_type_5.set(value); + break; + default: + assert(false && "invalid index"); + return; + } +#endif +} + float CurrentStore::get_nozzle_diameter([[maybe_unused]] uint8_t index) { #if HOTENDS <= 1 assert(index == 0); diff --git a/src/persistent_stores/store_instances/config_store/store_definition.hpp b/src/persistent_stores/store_instances/config_store/store_definition.hpp index dd6afb44aa..db49ce8885 100644 --- a/src/persistent_stores/store_instances/config_store/store_definition.hpp +++ b/src/persistent_stores/store_instances/config_store/store_definition.hpp @@ -289,8 +289,19 @@ struct CurrentStore StoreItem filament_type_5; #endif + StoreItem filament_prev_type_0; +#if EXTRUDERS > 1 // for now only doing one ifdef for simplicity + StoreItem filament_prev_type_1; + StoreItem filament_prev_type_2; + StoreItem filament_prev_type_3; + StoreItem filament_prev_type_4; + StoreItem filament_prev_type_5; +#endif + filament::Type get_filament_type(uint8_t index); void set_filament_type(uint8_t index, filament::Type value); + filament::Type get_previous_filament_type(uint8_t index); + void set_previous_filament_type(uint8_t index, filament::Type value); StoreItem heatup_bed;