|
@@ -1047,33 +1047,26 @@ void Temperature::init() {
|
1047
|
1047
|
int heater_index = heater_id >= 0 ? heater_id : EXTRUDERS;
|
1048
|
1048
|
|
1049
|
1049
|
// If the target temperature changes, restart
|
1050
|
|
- if (tr_target_temperature[heater_index] != target_temperature)
|
1051
|
|
- *state = TRReset;
|
|
1050
|
+ if (tr_target_temperature[heater_index] != target_temperature) {
|
|
1051
|
+ tr_target_temperature[heater_index] = target_temperature;
|
|
1052
|
+ *state = target_temperature > 0 ? TRFirstHeating : TRInactive;
|
|
1053
|
+ }
|
1052
|
1054
|
|
1053
|
1055
|
switch (*state) {
|
1054
|
|
- case TRReset:
|
1055
|
|
- *timer = 0;
|
1056
|
|
- *state = TRInactive;
|
1057
|
1056
|
// Inactive state waits for a target temperature to be set
|
1058
|
|
- case TRInactive:
|
1059
|
|
- if (target_temperature > 0) {
|
1060
|
|
- tr_target_temperature[heater_index] = target_temperature;
|
1061
|
|
- *state = TRFirstHeating;
|
1062
|
|
- }
|
1063
|
|
- break;
|
|
1057
|
+ case TRInactive: break;
|
1064
|
1058
|
// When first heating, wait for the temperature to be reached then go to Stable state
|
1065
|
1059
|
case TRFirstHeating:
|
1066
|
|
- if (temperature >= tr_target_temperature[heater_index]) *state = TRStable;
|
1067
|
|
- break;
|
|
1060
|
+ if (temperature < tr_target_temperature[heater_index]) break;
|
|
1061
|
+ *state = TRStable;
|
1068
|
1062
|
// While the temperature is stable watch for a bad temperature
|
1069
|
1063
|
case TRStable:
|
1070
|
|
- // If the temperature is over the target (-hysteresis) restart the timer
|
1071
|
|
- if (temperature >= tr_target_temperature[heater_index] - hysteresis_degc)
|
1072
|
|
- *timer = millis();
|
1073
|
|
- // If the timer goes too long without a reset, trigger shutdown
|
1074
|
|
- else if (ELAPSED(millis(), *timer + period_seconds * 1000UL))
|
|
1064
|
+ if (temperature < tr_target_temperature[heater_index] - hysteresis_degc && ELAPSED(millis(), *timer))
|
1075
|
1065
|
*state = TRRunaway;
|
1076
|
|
- break;
|
|
1066
|
+ else {
|
|
1067
|
+ *timer = millis() + period_seconds * 1000UL;
|
|
1068
|
+ break;
|
|
1069
|
+ }
|
1077
|
1070
|
case TRRunaway:
|
1078
|
1071
|
_temp_error(heater_id, PSTR(MSG_T_THERMAL_RUNAWAY), PSTR(MSG_THERMAL_RUNAWAY));
|
1079
|
1072
|
}
|