From da69571353930150568a227539fea3ad80a35fc5 Mon Sep 17 00:00:00 2001 From: ellensp Date: Tue, 13 Apr 2021 14:02:21 +1200 Subject: [PATCH] Fix Max Temperature not enforced (#21592) (cherry picked from commit 5fb3ee610140c9895be5495d84b6d853514e5e2d) --- Marlin/src/module/temperature.cpp | 6 ++-- Marlin/src/module/thermistor/thermistors.h | 36 ++++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index e7fd44411c8e..571560747908 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -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); diff --git a/Marlin/src/module/thermistor/thermistors.h b/Marlin/src/module/thermistor/thermistors.h index f0ec289dfefd..81c5117cce92 100644 --- a/Marlin/src/module/thermistor/thermistors.h +++ b/Marlin/src/module/thermistor/thermistors.h @@ -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