From dadd7516b5b7e56a379f838e76fd4a1c9fa547c6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 31 Dec 2021 07:42:07 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20Fix=20thermal=20conditi?= =?UTF-8?q?onals,=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/inc/Conditionals_post.h | 8 +++---- Marlin/src/module/temperature.cpp | 34 ++++++++++++++---------------- Marlin/src/module/temperature.h | 10 ++++----- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index a5c9d20eda..e1e82c40f2 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -2549,13 +2549,13 @@ #endif // Thermal protection -#if BOTH(HAS_HEATED_BED, THERMAL_PROTECTION_BED) - #define HAS_THERMALLY_PROTECTED_BED 1 +#if !HAS_HEATED_BED + #undef THERMAL_PROTECTION_BED #endif #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0 #define WATCH_HOTENDS 1 #endif -#if HAS_THERMALLY_PROTECTED_BED && WATCH_BED_TEMP_PERIOD > 0 +#if ENABLED(THERMAL_PROTECTION_BED) && WATCH_BED_TEMP_PERIOD > 0 #define WATCH_BED 1 #endif #if BOTH(HAS_HEATED_CHAMBER, THERMAL_PROTECTION_CHAMBER) && WATCH_CHAMBER_TEMP_PERIOD > 0 @@ -2567,7 +2567,7 @@ #if (ENABLED(THERMAL_PROTECTION_HOTENDS) || !EXTRUDERS) \ && (ENABLED(THERMAL_PROTECTION_BED) || !HAS_HEATED_BED) \ && (ENABLED(THERMAL_PROTECTION_CHAMBER) || !HAS_HEATED_CHAMBER) \ - && (ENABLED(THERMAL_PROTECTION_COOLER) || !HAS_COOLER) + && (ENABLED(THERMAL_PROTECTION_COOLER) || !HAS_COOLER) #define THERMALLY_SAFE 1 #endif diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index dccdc55034..c5c4b3524b 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -1444,7 +1444,7 @@ void Temperature::manage_heater() { TERN_(HEATER_IDLE_HANDLER, heater_idle[IDLE_INDEX_BED].update(ms)); - #if HAS_THERMALLY_PROTECTED_BED + #if ENABLED(THERMAL_PROTECTION_BED) tr_state_machine[RUNAWAY_IND_BED].run(temp_bed.celsius, temp_bed.target, H_BED, THERMAL_PROTECTION_BED_PERIOD, THERMAL_PROTECTION_BED_HYSTERESIS); #endif @@ -2570,20 +2570,14 @@ void Temperature::init() { ); */ - #if HEATER_IDLE_HANDLER - // If the heater idle timeout expires, restart - if (heater_idle[idle_index].timed_out) { - state = TRInactive; - running_temp = 0; - } - else - #endif - { - // If the target temperature changes, restart - if (running_temp != target) { - running_temp = target; - state = target > 0 ? TRFirstHeating : TRInactive; - } + // If the heater idle timeout expires, restart + if (TERN0(HEATER_IDLE_HANDLER, heater_idle[idle_index].timed_out)) { + state = TRInactive; + running_temp = 0; + } + else if (running_temp != target) { // If the target temperature changes, restart + running_temp = target; + state = target > 0 ? TRFirstHeating : TRInactive; } switch (state) { @@ -2596,7 +2590,7 @@ void Temperature::init() { state = TRStable; // While the temperature is stable watch for a bad temperature - case TRStable: + case TRStable: { #if ENABLED(ADAPTIVE_FAN_SLOWING) if (adaptive_fan_slowing && heater_id >= 0) { @@ -2614,13 +2608,17 @@ void Temperature::init() { } #endif + const millis_t now = millis(); + if (current >= running_temp - hysteresis_degc) { - timer = millis() + SEC_TO_MS(period_seconds); + timer = now + SEC_TO_MS(period_seconds); break; } - else if (PENDING(millis(), timer)) break; + else if (PENDING(now, timer)) break; state = TRRunaway; + } // fall through + case TRRunaway: TERN_(HAS_DWIN_E3V2_BASIC, DWIN_Popup_Temperature(0)); _temp_error(heater_id, FPSTR(str_t_thermal_runaway), GET_TEXT_F(MSG_THERMAL_RUNAWAY)); diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index 1ca0f3e88c..5661668204 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -1009,7 +1009,7 @@ class Temperature { static void min_temp_error(const heater_id_t e); static void max_temp_error(const heater_id_t e); - #define HAS_THERMAL_PROTECTION ANY(THERMAL_PROTECTION_HOTENDS, THERMAL_PROTECTION_CHAMBER, HAS_THERMALLY_PROTECTED_BED, THERMAL_PROTECTION_COOLER) + #define HAS_THERMAL_PROTECTION ANY(THERMAL_PROTECTION_HOTENDS, THERMAL_PROTECTION_CHAMBER, THERMAL_PROTECTION_BED, THERMAL_PROTECTION_COOLER) #if HAS_THERMAL_PROTECTION @@ -1021,7 +1021,7 @@ class Temperature { REPEAT(HOTENDS, _RUNAWAY_IND_E) #undef _RUNAWAY_IND_E #endif - OPTARG(HAS_THERMALLY_PROTECTED_BED, RUNAWAY_IND_BED) + OPTARG(THERMAL_PROTECTION_BED, RUNAWAY_IND_BED) OPTARG(THERMAL_PROTECTION_CHAMBER, RUNAWAY_IND_CHAMBER) OPTARG(THERMAL_PROTECTION_COOLER, RUNAWAY_IND_COOLER) , NR_HEATER_RUNAWAY @@ -1029,9 +1029,9 @@ class Temperature { // Convert the given heater_id_t to runaway state array index static RunawayIndex runaway_index_for_id(const int8_t heater_id) { - TERN_(HAS_THERMALLY_PROTECTED_CHAMBER, if (heater_id == H_CHAMBER) return RUNAWAY_IND_CHAMBER); - TERN_(HAS_THERMALLY_PROTECTED_CHAMBER, if (heater_id == H_COOLER) return RUNAWAY_IND_COOLER); - TERN_(HAS_THERMALLY_PROTECTED_BED, if (heater_id == H_BED) return RUNAWAY_IND_BED); + TERN_(THERMAL_PROTECTION_CHAMBER, if (heater_id == H_CHAMBER) return RUNAWAY_IND_CHAMBER); + TERN_(THERMAL_PROTECTION_COOLER, if (heater_id == H_COOLER) return RUNAWAY_IND_COOLER); + TERN_(THERMAL_PROTECTION_BED, if (heater_id == H_BED) return RUNAWAY_IND_BED); return (RunawayIndex)_MAX(heater_id, 0); }