From 0ae746b20f4ea410809d69dc4c375c956b41a553 Mon Sep 17 00:00:00 2001 From: ellensp Date: Mon, 12 Apr 2021 02:24:17 +1200 Subject: [PATCH 1/4] fixes #21582 --- Marlin/src/module/temperature.cpp | 2 +- Marlin/src/module/thermistor/thermistors.h | 32 +++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 5a8704d3bac3..3e99e692be03 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2206,7 +2206,7 @@ void Temperature::init() { 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 0871844e3921..d14745743c94 100644 --- a/Marlin/src/module/thermistor/thermistors.h +++ b/Marlin/src/module/thermistor/thermistors.h @@ -343,72 +343,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 From 24362b0796535247365b497e79d947c661a65824 Mon Sep 17 00:00:00 2001 From: ellensp Date: Mon, 12 Apr 2021 02:25:20 +1200 Subject: [PATCH 2/4] stop warnings --- Marlin/src/module/temperature.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 3e99e692be03..f8a3e0bdb6bf 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2194,13 +2194,13 @@ 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); \ From a0ef85ebfd2c185d2152d32645366f1d4887ecb3 Mon Sep 17 00:00:00 2001 From: ellensp Date: Mon, 12 Apr 2021 12:07:56 +1200 Subject: [PATCH 3/4] TT_REV didnt resolve correctly resulting in PTC thermistor not working. --- Marlin/src/module/thermistor/thermistors.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Marlin/src/module/thermistor/thermistors.h b/Marlin/src/module/thermistor/thermistors.h index d14745743c94..3b4e0b2c7b33 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)) From 5e16df22e0189cf097b05fe9233aec00cc611c1e Mon Sep 17 00:00:00 2001 From: ellensp Date: Mon, 12 Apr 2021 15:41:25 +1200 Subject: [PATCH 4/4] remove __TT_REV define after use. --- Marlin/src/module/thermistor/thermistors.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Marlin/src/module/thermistor/thermistors.h b/Marlin/src/module/thermistor/thermistors.h index 3b4e0b2c7b33..58ccc619bcb7 100644 --- a/Marlin/src/module/thermistor/thermistors.h +++ b/Marlin/src/module/thermistor/thermistors.h @@ -523,6 +523,7 @@ static_assert( #endif #endif +#undef __TT_REV #undef _TT_REV #undef TT_REV #undef _TT_REVRAW