Skip to content

Commit

Permalink
Fix Max Temperature not enforced (MarlinFirmware#21592)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5fb3ee6)
  • Loading branch information
ellensp authored and Sebazzz committed Apr 25, 2021
1 parent b3a0017 commit da69571
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2194,19 +2194,19 @@ void Temperature::init() {
#if HAS_HOTEND

#define _TEMP_MIN_E(NR) do{ \
const int16_t tmin = _MAX(HEATER_##NR##_MINTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 0, (int16_t)pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MINTEMP_IND].celsius))); \
const int16_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 int16_t tmax = _MIN(HEATER_##NR##_MAXTEMP, TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 2000, (int16_t)pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MAXTEMP_IND].celsius) - 1)); \
const int16_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);
Expand Down
36 changes: 19 additions & 17 deletions Marlin/src/module/thermistor/thermistors.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,80 +335,81 @@ 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))

#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
Expand Down Expand Up @@ -522,6 +523,7 @@ static_assert(
#endif
#endif

#undef __TT_REV
#undef _TT_REV
#undef TT_REV
#undef _TT_REVRAW
Expand Down

0 comments on commit da69571

Please sign in to comment.