diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index b335f96562..404c2993aa 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -5703,10 +5703,36 @@ inline void gcode_M226() { #if ENABLED(PREVENT_DANGEROUS_EXTRUDE) /** - * M302: Allow cold extrudes, or set the minimum extrude S. + * M302: Allow cold extrudes, or set the minimum extrude temperature + * + * S sets the minimum extrude temperature + * P enables (1) or disables (0) cold extrusion + * + * Examples: + * + * M302 ; report current cold extrusion state + * M302 P0 ; enable cold extrusion checking + * M302 P1 ; disables cold extrusion checking + * M302 S0 ; always allow extrusion (disables checking) + * M302 S170 ; only allow extrusion above 170 + * M302 S170 P1 ; set min extrude temp to 170 but leave disabled */ inline void gcode_M302() { - thermalManager.extrude_min_temp = code_seen('S') ? code_value_temp_abs() : 0; + bool seen_S = code_seen('S'); + if (seen_S) { + thermalManager.extrude_min_temp = code_value_temp_abs(); + thermalManager.allow_cold_extrude = (thermalManager.extrude_min_temp == 0); + } + + if (code_seen('P')) + thermalManager.allow_cold_extrude = (thermalManager.extrude_min_temp == 0) || code_value_bool(); + else if (!seen_S) { + // Report current state + SERIAL_ECHO_START; + SERIAL_ECHOPAIR("Cold extrudes are ", (thermalManager.allow_cold_extrude ? "en" : "dis")); + SERIAL_ECHOPAIR("abled (min temp ", int(thermalManager.extrude_min_temp + 0.5)); + SERIAL_ECHOLNPGM("C)"); + } } #endif // PREVENT_DANGEROUS_EXTRUDE diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index aa0ff79095..c2bbc81a41 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -107,6 +107,7 @@ unsigned char Temperature::soft_pwm_bed; #endif #if ENABLED(PREVENT_DANGEROUS_EXTRUDE) + bool Temperature::allow_cold_extrude = false; float Temperature::extrude_min_temp = EXTRUDE_MINTEMP; #endif diff --git a/Marlin/temperature.h b/Marlin/temperature.h index fd737bc6a9..5a1a7e7e34 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -121,12 +121,13 @@ class Temperature { #endif #if ENABLED(PREVENT_DANGEROUS_EXTRUDE) + static bool allow_cold_extrude; static float extrude_min_temp; static bool tooColdToExtrude(uint8_t e) { #if HOTENDS == 1 UNUSED(e); #endif - return degHotend(HOTEND_INDEX) < extrude_min_temp; + return allow_cold_extrude ? false : degHotend(HOTEND_INDEX) < extrude_min_temp; } #else static bool tooColdToExtrude(uint8_t e) { UNUSED(e); return false; }