From c730076e57e865bb00b47c4fc2ddebdeee48d36a Mon Sep 17 00:00:00 2001 From: vovodroid Date: Tue, 19 Mar 2024 14:54:38 +0200 Subject: [PATCH] Simplify M190 annealing code --- Marlin/src/gcode/temp/M140_M190.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Marlin/src/gcode/temp/M140_M190.cpp b/Marlin/src/gcode/temp/M140_M190.cpp index 1a179873cc..22032cd0dc 100644 --- a/Marlin/src/gcode/temp/M140_M190.cpp +++ b/Marlin/src/gcode/temp/M140_M190.cpp @@ -93,7 +93,7 @@ void GcodeSuite::M140_M190(const bool isM190) { #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; + const millis_t anneal_ms = anneal ? parser.value_millis_from_seconds() : 0UL; #else constexpr bool anneal = false; #endif @@ -110,15 +110,11 @@ void GcodeSuite::M140_M190(const bool isM190) { #if ENABLED(BED_ANNEALING_GCODE) if (anneal) { LCD_MESSAGE(MSG_BED_ANNEALING); + const millis_t wait_ms = anneal_ms / (thermalManager.degBed() - temp) ; // 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 - } + for (celsius_t cool_temp = thermalManager.degBed() - 1; cool_temp >= temp; --cool_temp) { + thermalManager.setTargetBed(cool_temp); // Cool by one degree + dwell(wait_ms); //Wait for going to the next degree } return; }