From 884a3249fef951c111c8969eec659cbe36a6292b Mon Sep 17 00:00:00 2001 From: Vovodroid Date: Sun, 12 Nov 2023 04:40:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20BED=5FANNEALING=5FGCODE=20(#26341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- Marlin/Configuration.h | 3 ++ Marlin/src/gcode/temp/M140_M190.cpp | 46 ++++++++++++++++++++++++--- Marlin/src/lcd/language/language_en.h | 1 + 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c5a7398236..3509078407 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -779,6 +779,9 @@ //#define BED_LIMIT_SWITCHING // Keep the bed temperature within BED_HYSTERESIS of the target #endif +// Add 'M190 R T' for more gradual M190 R bed cooling. +//#define BED_ANNEALING_GCODE + //=========================================================================== //==================== PID > Chamber Temperature Control ==================== //=========================================================================== diff --git a/Marlin/src/gcode/temp/M140_M190.cpp b/Marlin/src/gcode/temp/M140_M190.cpp index c5e3c00029..1a179873cc 100644 --- a/Marlin/src/gcode/temp/M140_M190.cpp +++ b/Marlin/src/gcode/temp/M140_M190.cpp @@ -54,6 +54,16 @@ * * With PRINTJOB_TIMER_AUTOSTART turning on heaters will start the print job timer * (used by printingIsActive, etc.) and turning off heaters will stop the timer. + * + * With BED_ANNEALING_GCODE: + * + * M190 Parameters + * T: Cooldown time, for more gradual cooling. Use with R parameter. + * M190 R T - Cool the bed down over a given period of time. + * + * Examples + * M190 R70 T600: Cool down to 70°C over a period of ten minutes. + * */ void GcodeSuite::M140_M190(const bool isM190) { @@ -81,19 +91,47 @@ void GcodeSuite::M140_M190(const bool isM190) { if (!got_temp) return; - thermalManager.setTargetBed(temp); - thermalManager.isHeatingBed() ? LCD_MESSAGE(MSG_BED_HEATING) : LCD_MESSAGE(MSG_BED_COOLING); + #if ENABLED(BED_ANNEALING_GCODE) + const bool anneal = isM190 && !no_wait_for_cooling && parser.seenval('T'); + const millis_t anneal_ms = anneal ? millis() + parser.value_millis_from_seconds() : 0UL; + #else + constexpr bool anneal = false; + #endif + + if (!anneal) { + thermalManager.setTargetBed(temp); + thermalManager.isHeatingBed() ? LCD_MESSAGE(MSG_BED_HEATING) : LCD_MESSAGE(MSG_BED_COOLING); + } // With PRINTJOB_TIMER_AUTOSTART, M190 can start the timer, and M140 can stop it TERN_(PRINTJOB_TIMER_AUTOSTART, thermalManager.auto_job_check_timer(isM190, !isM190)); - if (isM190) + if (isM190) { + #if ENABLED(BED_ANNEALING_GCODE) + if (anneal) { + LCD_MESSAGE(MSG_BED_ANNEALING); + // Loop from current temp down to the target + for (celsius_t cool_temp = thermalManager.degBed(); --cool_temp >= temp; ) { + thermalManager.setTargetBed(cool_temp); // Cool by one degree + thermalManager.wait_for_bed(false); // Could this wait forever? + const millis_t ms = millis(); + if (PENDING(ms, anneal_ms) && cool_temp > temp) { // Still warmer and waiting? + const millis_t remain = anneal_ms - ms; + dwell(remain / (cool_temp - temp)); // Wait for a fraction of remaining time + } + } + return; + } + #endif + thermalManager.wait_for_bed(no_wait_for_cooling); - else + } + else { ui.set_status_reset_fn([]{ const celsius_t c = thermalManager.degTargetBed(); return c < 30 || thermalManager.degBedNear(c); }); + } } #endif // HAS_HEATED_BED diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index 24595e191f..1abad83555 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -626,6 +626,7 @@ namespace LanguageNarrow_en { LSTR MSG_COOLING = _UxGT("Cooling..."); LSTR MSG_BED_HEATING = _UxGT("Bed Heating..."); LSTR MSG_BED_COOLING = _UxGT("Bed Cooling..."); + LSTR MSG_BED_ANNEALING = _UxGT("Annealing..."); LSTR MSG_PROBE_HEATING = _UxGT("Probe Heating..."); LSTR MSG_PROBE_COOLING = _UxGT("Probe Cooling..."); LSTR MSG_CHAMBER_HEATING = _UxGT("Chamber Heating...");