Skip to content

Commit

Permalink
🐛 Fix min/max temp evaluation
Browse files Browse the repository at this point in the history
Fixes #24257
  • Loading branch information
thinkyhead committed Jun 4, 2022
1 parent 0ae9821 commit 9ab654a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,13 +2388,15 @@ 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, (int)pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MINTEMP_IND].celsius))); \
const celsius_t tmin_tmp = TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 0, int16_t(pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MINTEMP_IND].celsius))), \
tmin = _MAX(HEATER_##NR##_MINTEMP, tmin_tmp); \
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, (int)pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MAXTEMP_IND].celsius) - 1)); \
const celsius_t tmax_tmp = TERN(TEMP_SENSOR_##NR##_IS_CUSTOM, 2000, int16_t(pgm_read_word(&TEMPTABLE_##NR [TEMP_SENSOR_##NR##_MAXTEMP_IND].celsius)) - 1), \
tmax = _MIN(HEATER_##NR##_MAXTEMP, tmax_tmp); \
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); \
Expand Down

1 comment on commit 9ab654a

@pillopaolo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the attention and fix.

However I noted that you applied the int16_t fix to my quick&dirty fix, i.e. the one where I split the calculation in 2 lines (I did it without understanding anything, it simply works).
This does not prove that int16_t is the solution (as my fix was already working) + is not so elegant (2 lines instead of 2) in my opinion.

If int16_t really works, why not applying it directly to the original single-line calculation?

Please sign in to comment.