🚑️ Fix thermal conditionals, structure

This commit is contained in:
Scott Lahteine 2021-12-31 07:42:07 -06:00
parent f99732ba75
commit dadd7516b5
3 changed files with 25 additions and 27 deletions

View File

@ -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

View File

@ -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));

View File

@ -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);
}