Fix Max Temperature not enforced (#21592)

This commit is contained in:
ellensp 2021-04-13 14:02:21 +12:00 committed by Scott Lahteine
parent 3517fbdcbd
commit 5fb3ee6101
2 changed files with 22 additions and 20 deletions

View file

@ -2196,19 +2196,19 @@ void Temperature::init() {
#if HAS_HOTEND
#define _TEMP_MIN_E(NR) do{ \
const celsius_t tmin = _MAX(HEATER_##NR##_MINTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 0, pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MINTEMP_IND].celsius))); \
const celsius_t tmin = _MAX(HEATER_##NR##_MINTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 0, (int)pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MINTEMP_IND].celsius))); \
temp_range[NR].mintemp = tmin; \
while (analog_to_celsius_hotend(temp_range[NR].raw_min, NR) < tmin) \
temp_range[NR].raw_min += TEMPDIR(NR) * (OVERSAMPLENR); \
}while(0)
#define _TEMP_MAX_E(NR) do{ \
const celsius_t tmax = _MIN(HEATER_##NR##_MAXTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 2000, pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MAXTEMP_IND].celsius) - 1)); \
const celsius_t tmax = _MIN(HEATER_##NR##_MAXTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 2000, (int)pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MAXTEMP_IND].celsius) - 1)); \
temp_range[NR].maxtemp = tmax; \
while (analog_to_celsius_hotend(temp_range[NR].raw_max, NR) > tmax) \
temp_range[NR].raw_max -= TEMPDIR(NR) * (OVERSAMPLENR); \
}while(0)
#define _MINMAX_TEST(N,M) (HOTENDS > N && TEMP_SENSOR_ ##N## THERMISTOR_ID && TEMP_SENSOR_ ##N## THERMISTOR_ID != 998 && TEMP_SENSOR_ ##N## THERMISTOR_ID != 999 && defined(HEATER_##N##_##M##TEMP))
#define _MINMAX_TEST(N,M) (HOTENDS > N && TEMP_SENSOR_ ##N## _THERMISTOR_ID && TEMP_SENSOR_ ##N## _THERMISTOR_ID != 998 && TEMP_SENSOR_ ##N## _THERMISTOR_ID != 999 && defined(HEATER_##N##_##M##TEMP))
#if _MINMAX_TEST(0, MIN)
_TEMP_MIN_E(0);

View file

@ -335,7 +335,8 @@ static_assert(
// For thermistors the highest temperature results in the lowest ADC value
// For thermocouples the highest temperature results in the highest ADC value
#define _TT_REV(N) REVERSE_TEMP_SENSOR_RANGE_##N
#define __TT_REV(N) REVERSE_TEMP_SENSOR_RANGE_##N
#define _TT_REV(N) __TT_REV(N)
#define TT_REV(N) _TT_REV(TEMP_SENSOR_##N##_THERMISTOR_ID)
#define _TT_REVRAW(N) !TEMP_SENSOR_##N##_IS_THERMISTOR
#define TT_REVRAW(N) (TT_REV(N) || _TT_REVRAW(N))
@ -343,72 +344,72 @@ static_assert(
#ifdef TEMPTABLE_0
#if TT_REV(0)
#define TEMP_SENSOR_0_MINTEMP_IND 0
#define TEMPTABLE_0_MAXTEMP_IND HEATER_0_LEN - 1
#define TEMP_SENSOR_0_MAXTEMP_IND TEMPTABLE_0_LEN - 1
#else
#define TEMPTABLE_0_MINTEMP_IND HEATER_0_LEN - 1
#define TEMP_SENSOR_0_MINTEMP_IND TEMPTABLE_0_LEN - 1
#define TEMP_SENSOR_0_MAXTEMP_IND 0
#endif
#endif
#ifdef TEMPTABLE_1
#if TT_REV(1)
#define TEMP_SENSOR_1_MINTEMP_IND 0
#define TEMPTABLE_1_MAXTEMP_IND HEATER_1_LEN - 1
#define TEMP_SENSOR_1_MAXTEMP_IND TEMPTABLE_1_LEN - 1
#else
#define TEMPTABLE_1_MINTEMP_IND HEATER_1_LEN - 1
#define TEMP_SENSOR_1_MINTEMP_IND TEMPTABLE_1_LEN - 1
#define TEMP_SENSOR_1_MAXTEMP_IND 0
#endif
#endif
#ifdef TEMPTABLE_2
#if TT_REV(2)
#define TEMP_SENSOR_2_MINTEMP_IND 0
#define TEMPTABLE_2_MAXTEMP_IND HEATER_2_LEN - 1
#define TEMP_SENSOR_2_MAXTEMP_IND TEMPTABLE_2_LEN - 1
#else
#define TEMPTABLE_2_MINTEMP_IND HEATER_2_LEN - 1
#define TEMP_SENSOR_2_MINTEMP_IND TEMPTABLE_2_LEN - 1
#define TEMP_SENSOR_2_MAXTEMP_IND 0
#endif
#endif
#ifdef TEMPTABLE_3
#if TT_REV(3)
#define TEMP_SENSOR_3_MINTEMP_IND 0
#define TEMPTABLE_3_MAXTEMP_IND HEATER_3_LEN - 1
#define TEMP_SENSOR_3_MAXTEMP_IND TEMPTABLE_3_LEN - 1
#else
#define TEMPTABLE_3_MINTEMP_IND HEATER_3_LEN - 1
#define TEMP_SENSOR_3_MINTEMP_IND TEMPTABLE_3_LEN - 1
#define TEMP_SENSOR_3_MAXTEMP_IND 0
#endif
#endif
#ifdef TEMPTABLE_4
#if TT_REV(4)
#define TEMP_SENSOR_4_MINTEMP_IND 0
#define TEMPTABLE_4_MAXTEMP_IND HEATER_4_LEN - 1
#define TEMP_SENSOR_4_MAXTEMP_IND TEMPTABLE_4_LEN - 1
#else
#define TEMPTABLE_4_MINTEMP_IND HEATER_4_LEN - 1
#define TEMP_SENSOR_4_MINTEMP_IND TEMPTABLE_4_LEN - 1
#define TEMP_SENSOR_4_MAXTEMP_IND 0
#endif
#endif
#ifdef TEMPTABLE_5
#if TT_REV(5)
#define TEMP_SENSOR_5_MINTEMP_IND 0
#define TEMPTABLE_5_MAXTEMP_IND HEATER_5_LEN - 1
#define TEMP_SENSOR_5_MAXTEMP_IND TEMPTABLE_5_LEN - 1
#else
#define TEMPTABLE_5_MINTEMP_IND HEATER_5_LEN - 1
#define TEMP_SENSOR_5_MINTEMP_IND TEMPTABLE_5_LEN - 1
#define TEMP_SENSOR_5_MAXTEMP_IND 0
#endif
#endif
#ifdef TEMPTABLE_6
#if TT_REV(6)
#define TEMP_SENSOR_6_MINTEMP_IND 0
#define TEMPTABLE_6_MAXTEMP_IND HEATER_6_LEN - 1
#define TEMP_SENSOR_6_MAXTEMP_IND TEMPTABLE_6_LEN - 1
#else
#define TEMPTABLE_6_MINTEMP_IND HEATER_6_LEN - 1
#define TEMP_SENSOR_6_MINTEMP_IND TEMPTABLE_6_LEN - 1
#define TEMP_SENSOR_6_MAXTEMP_IND 0
#endif
#endif
#ifdef TEMPTABLE_7
#if TT_REV(7)
#define TEMP_SENSOR_7_MINTEMP_IND 0
#define TEMPTABLE_7_MAXTEMP_IND HEATER_7_LEN - 1
#define TEMP_SENSOR_7_MAXTEMP_IND TEMPTABLE_7_LEN - 1
#else
#define TEMPTABLE_7_MINTEMP_IND HEATER_7_LEN - 1
#define TEMP_SENSOR_7_MINTEMP_IND TEMPTABLE_7_LEN - 1
#define TEMP_SENSOR_7_MAXTEMP_IND 0
#endif
#endif
@ -522,6 +523,7 @@ static_assert(
#endif
#endif
#undef __TT_REV
#undef _TT_REV
#undef TT_REV
#undef _TT_REVRAW