Skip to content

Commit

Permalink
Add clogging prevention if previous filament had higher temp on unloa…
Browse files Browse the repository at this point in the history
…d than filament on load
  • Loading branch information
bkerler committed Apr 22, 2024
1 parent 0de68b8 commit bdc65cb
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/marlin_stubs/pause/M701_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,19 @@ struct CurrentStore
StoreItem<filament::Type, defaults::filament_type, journal::hash("Filament Type 5")> filament_type_5;
#endif

StoreItem<filament::Type, defaults::filament_type, journal::hash("Filament Previous Type 0")> filament_prev_type_0;
#if EXTRUDERS > 1 // for now only doing one ifdef for simplicity
StoreItem<filament::Type, defaults::filament_type, journal::hash("Filament Previous Type 1")> filament_prev_type_1;
StoreItem<filament::Type, defaults::filament_type, journal::hash("Filament Previous Type 2")> filament_prev_type_2;
StoreItem<filament::Type, defaults::filament_type, journal::hash("Filament Previous Type 3")> filament_prev_type_3;
StoreItem<filament::Type, defaults::filament_type, journal::hash("Filament Previous Type 4")> filament_prev_type_4;
StoreItem<filament::Type, defaults::filament_type, journal::hash("Filament Previous Type 5")> 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<bool, defaults::bool_false, journal::hash("Heatup Bed")> heatup_bed;

Expand Down

0 comments on commit bdc65cb

Please sign in to comment.