Skip to content

Commit

Permalink
🔧 Sanity-check hotend max / preheat temps (MarlinFirmware#25407)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
ellensp and thinkyhead committed Apr 7, 2023
1 parent 4a1cbff commit 7afd823
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 27 deletions.
9 changes: 5 additions & 4 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,11 @@
( DEFER2(__RREPEAT2)()(ADD1(_RPT_I),SUB1(_RPT_N),_RPT_OP,V) ) \
( /* Do nothing */ )
#define __RREPEAT2() _RREPEAT2
#define RREPEAT_S(S,N,OP) EVAL1024(_RREPEAT(S,SUB##S(N),OP))
#define RREPEAT(N,OP) RREPEAT_S(0,N,OP)
#define RREPEAT2_S(S,N,OP,V...) EVAL1024(_RREPEAT2(S,SUB##S(N),OP,V))
#define RREPEAT2(N,OP,V...) RREPEAT2_S(0,N,OP,V)
#define RREPEAT_S(S,N,OP) EVAL1024(_RREPEAT(S,SUB##S(N),OP))
#define RREPEAT(N,OP) RREPEAT_S(0,N,OP)
#define RREPEAT_1(N,OP) RREPEAT_S(1,INCREMENT(N),OP)
#define RREPEAT2_S(S,N,OP,V...) EVAL1024(_RREPEAT2(S,SUB##S(N),OP,V))
#define RREPEAT2(N,OP,V...) RREPEAT2_S(0,N,OP,V)

// Call OP(A) with each item as an argument
#define _MAP(_MAP_OP,A,V...) \
Expand Down
82 changes: 67 additions & 15 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,12 @@
#define TEMP_SENSOR_0_IS_AD8495 1
#elif TEMP_SENSOR_0 == -1
#define TEMP_SENSOR_0_IS_AD595 1
#elif TEMP_SENSOR_0 == 1000
#define TEMP_SENSOR_0_IS_CUSTOM 1
#elif TEMP_SENSOR_0 == 998 || TEMP_SENSOR_0 == 999
#define TEMP_SENSOR_0_IS_DUMMY 1
#elif TEMP_SENSOR_0 > 0
#define TEMP_SENSOR_0_IS_THERMISTOR 1
#if TEMP_SENSOR_0 == 1000
#define TEMP_SENSOR_0_IS_CUSTOM 1
#elif TEMP_SENSOR_0 == 998 || TEMP_SENSOR_0 == 999
#define TEMP_SENSOR_0_IS_DUMMY 1
#endif
#else
#undef HEATER_0_MINTEMP
#undef HEATER_0_MAXTEMP
Expand Down Expand Up @@ -269,13 +268,12 @@
#define TEMP_SENSOR_1_IS_AD8495 1
#elif TEMP_SENSOR_1 == -1
#define TEMP_SENSOR_1_IS_AD595 1
#elif TEMP_SENSOR_1 == 1000
#define TEMP_SENSOR_1_IS_CUSTOM 1
#elif TEMP_SENSOR_1 == 998 || TEMP_SENSOR_1 == 999
#define TEMP_SENSOR_1_IS_DUMMY 1
#elif TEMP_SENSOR_1 > 0
#define TEMP_SENSOR_1_IS_THERMISTOR 1
#if TEMP_SENSOR_1 == 1000
#define TEMP_SENSOR_1_IS_CUSTOM 1
#elif TEMP_SENSOR_1 == 998 || TEMP_SENSOR_1 == 999
#define TEMP_SENSOR_1_IS_DUMMY 1
#endif
#else
#undef HEATER_1_MINTEMP
#undef HEATER_1_MAXTEMP
Expand Down Expand Up @@ -315,18 +313,72 @@
#define TEMP_SENSOR_2_IS_AD8495 1
#elif TEMP_SENSOR_2 == -1
#define TEMP_SENSOR_2_IS_AD595 1
#elif TEMP_SENSOR_2 == 1000
#define TEMP_SENSOR_2_IS_CUSTOM 1
#elif TEMP_SENSOR_2 == 998 || TEMP_SENSOR_2 == 999
#define TEMP_SENSOR_2_IS_DUMMY 1
#elif TEMP_SENSOR_2 > 0
#define TEMP_SENSOR_2_IS_THERMISTOR 1
#if TEMP_SENSOR_2 == 1000
#define TEMP_SENSOR_2_IS_CUSTOM 1
#elif TEMP_SENSOR_2 == 998 || TEMP_SENSOR_2 == 999
#define TEMP_SENSOR_2_IS_DUMMY 1
#endif
#else
#undef HEATER_2_MINTEMP
#undef HEATER_2_MAXTEMP
#endif

#if TEMP_SENSOR_3 == 1000
#define TEMP_SENSOR_3_IS_CUSTOM 1
#elif TEMP_SENSOR_3 == 998 || TEMP_SENSOR_3 == 999
#define TEMP_SENSOR_3_IS_DUMMY 1
#elif TEMP_SENSOR_3 > 0
#define TEMP_SENSOR_3_IS_THERMISTOR 1
#elif !TEMP_SENSOR_3
#undef HEATER_3_MINTEMP
#undef HEATER_3_MAXTEMP
#endif

#if TEMP_SENSOR_4 == 1000
#define TEMP_SENSOR_4_IS_CUSTOM 1
#elif TEMP_SENSOR_4 == 998 || TEMP_SENSOR_4 == 999
#define TEMP_SENSOR_4_IS_DUMMY 1
#elif TEMP_SENSOR_4 > 0
#define TEMP_SENSOR_4_IS_THERMISTOR 1
#elif !TEMP_SENSOR_4
#undef HEATER_4_MINTEMP
#undef HEATER_4_MAXTEMP
#endif

#if TEMP_SENSOR_5 == 1000
#define TEMP_SENSOR_5_IS_CUSTOM 1
#elif TEMP_SENSOR_5 == 998 || TEMP_SENSOR_5 == 999
#define TEMP_SENSOR_5_IS_DUMMY 1
#elif TEMP_SENSOR_5 > 0
#define TEMP_SENSOR_5_IS_THERMISTOR 1
#elif !TEMP_SENSOR_5
#undef HEATER_5_MINTEMP
#undef HEATER_5_MAXTEMP
#endif

#if TEMP_SENSOR_6 == 1000
#define TEMP_SENSOR_6_IS_CUSTOM 1
#elif TEMP_SENSOR_6 == 998 || TEMP_SENSOR_6 == 999
#define TEMP_SENSOR_6_IS_DUMMY 1
#elif TEMP_SENSOR_6 > 0
#define TEMP_SENSOR_6_IS_THERMISTOR 1
#elif !TEMP_SENSOR_6
#undef HEATER_6_MINTEMP
#undef HEATER_6_MAXTEMP
#endif

#if TEMP_SENSOR_7 == 1000
#define TEMP_SENSOR_7_IS_CUSTOM 1
#elif TEMP_SENSOR_7 == 998 || TEMP_SENSOR_7 == 999
#define TEMP_SENSOR_7_IS_DUMMY 1
#elif TEMP_SENSOR_7 > 0
#define TEMP_SENSOR_7_IS_THERMISTOR 1
#elif !TEMP_SENSOR_7
#undef HEATER_7_MINTEMP
#undef HEATER_7_MAXTEMP
#endif

#if TEMP_SENSOR_IS_MAX_TC(REDUNDANT)
#if TEMP_SENSOR_REDUNDANT == -5
#if !REDUNDANT_TEMP_MATCH(SOURCE, E0) && !REDUNDANT_TEMP_MATCH(SOURCE, E1) && !REDUNDANT_TEMP_MATCH(SOURCE, E2)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
const preheat_t &pre = material_preset[m];
TERN_(HAS_HOTEND, if (TEST(pmask, PT_HOTEND)) thermalManager.setTargetHotend(pre.hotend_temp, e));
TERN_(HAS_HEATED_BED, if (TEST(pmask, PT_BED)) thermalManager.setTargetBed(pre.bed_temp));
//TERN_(HAS_HEATED_CHAMBER, if (TEST(pmask, PT_CHAMBER)) thermalManager.setTargetBed(pre.chamber_temp));
//TERN_(HAS_HEATED_CHAMBER, if (TEST(pmask, PT_CHAMBER)) thermalManager.setTargetChamber(pre.chamber_temp));
TERN_(HAS_FAN, if (TEST(pmask, PT_FAN)) thermalManager.set_fan_speed(0, pre.fan_speed));
}
#endif
Expand Down
16 changes: 15 additions & 1 deletion Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,22 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);

#if HAS_HOTEND
hotend_info_t Temperature::temp_hotend[HOTENDS];
#define _HMT(N) HEATER_##N##_MAXTEMP,
const celsius_t Temperature::hotend_maxtemp[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP, HEATER_3_MAXTEMP, HEATER_4_MAXTEMP, HEATER_5_MAXTEMP, HEATER_6_MAXTEMP, HEATER_7_MAXTEMP);

// Sanity-check max readable temperatures
#define CHECK_MAXTEMP_(N,M,S) static_assert( \
S >= 998 || M <= _MAX(TT_NAME(S)[0].celsius, TT_NAME(S)[COUNT(TT_NAME(S)) - 1].celsius) - HOTEND_OVERSHOOT, \
"HEATER_" STRINGIFY(N) "_MAXTEMP (" STRINGIFY(M) ") is too high for thermistor_" STRINGIFY(S) ".h with HOTEND_OVERSHOOT=" STRINGIFY(HOTEND_OVERSHOOT) ".");
#define CHECK_MAXTEMP(N) TERN(TEMP_SENSOR_##N##_IS_THERMISTOR, CHECK_MAXTEMP_, CODE_0)(N, HEATER_##N##_MAXTEMP, TEMP_SENSOR_##N)
REPEAT(HOTENDS, CHECK_MAXTEMP)

#if HAS_PREHEAT
#define CHECK_PREHEAT__(N,P,T,M) static_assert(T <= M - HOTEND_OVERSHOOT, "PREHEAT_" STRINGIFY(P) "_TEMP_HOTEND (" STRINGIFY(T) ") must be less than HEATER_" STRINGIFY(N) "_MAXTEMP (" STRINGIFY(M) ") - " STRINGIFY(HOTEND_OVERSHOOT) ".");
#define CHECK_PREHEAT_(N,P) CHECK_PREHEAT__(N, P, PREHEAT_##P##_TEMP_HOTEND, HEATER_##N##_MAXTEMP);
#define CHECK_PREHEAT(P) REPEAT2(HOTENDS, CHECK_PREHEAT_, P);
RREPEAT_1(PREHEAT_COUNT, CHECK_PREHEAT)
#endif

#endif

#if HAS_TEMP_REDUNDANT
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/module/thermistor/thermistor_2000.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

// R25 = 100 KOhm, beta25 = 4550 K, 4.7 kOhm pull-up, TDK NTCG104LH104KT1 https://product.tdk.com/en/search/sensor/ntc/chip-ntc-thermistor/info?part_no=NTCG104LH104KT1
constexpr temp_entry_t temptable_2000[] PROGMEM = {
{ OV(313), 125 },
{ OV(347), 120 },
{ OV(383), 115 },
{ OV(422), 110 },
{ OV(463), 105 },
{ OV(506), 100 },
{ OV(313), 125 },
{ OV(347), 120 },
{ OV(383), 115 },
{ OV(422), 110 },
{ OV(463), 105 },
{ OV(506), 100 },
{ OV(549), 95 },
{ OV(594), 90 },
{ OV(638), 85 },
Expand Down

0 comments on commit 7afd823

Please sign in to comment.