Skip to content

Commit b16e70c

Browse files
ellenspthinkyhead
andcommitted
🔧 Sanity-check hotend max / preheat temps (MarlinFirmware#25407)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent 2e465b5 commit b16e70c

File tree

5 files changed

+94
-27
lines changed

5 files changed

+94
-27
lines changed

Marlin/src/core/macros.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,11 @@
712712
( DEFER2(__RREPEAT2)()(ADD1(_RPT_I),SUB1(_RPT_N),_RPT_OP,V) ) \
713713
( /* Do nothing */ )
714714
#define __RREPEAT2() _RREPEAT2
715-
#define RREPEAT_S(S,N,OP) EVAL1024(_RREPEAT(S,SUB##S(N),OP))
716-
#define RREPEAT(N,OP) RREPEAT_S(0,N,OP)
717-
#define RREPEAT2_S(S,N,OP,V...) EVAL1024(_RREPEAT2(S,SUB##S(N),OP,V))
718-
#define RREPEAT2(N,OP,V...) RREPEAT2_S(0,N,OP,V)
715+
#define RREPEAT_S(S,N,OP) EVAL1024(_RREPEAT(S,SUB##S(N),OP))
716+
#define RREPEAT(N,OP) RREPEAT_S(0,N,OP)
717+
#define RREPEAT_1(N,OP) RREPEAT_S(1,INCREMENT(N),OP)
718+
#define RREPEAT2_S(S,N,OP,V...) EVAL1024(_RREPEAT2(S,SUB##S(N),OP,V))
719+
#define RREPEAT2(N,OP,V...) RREPEAT2_S(0,N,OP,V)
719720

720721
// Emit a list of N OP(I) items with ascending counter.
721722
#define _REPLIST(_RPT_I,_RPT_N,_RPT_OP) \

Marlin/src/inc/Conditionals_adv.h

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,12 @@
223223
#define TEMP_SENSOR_0_IS_AD8495 1
224224
#elif TEMP_SENSOR_0 == -1
225225
#define TEMP_SENSOR_0_IS_AD595 1
226+
#elif TEMP_SENSOR_0 == 1000
227+
#define TEMP_SENSOR_0_IS_CUSTOM 1
228+
#elif TEMP_SENSOR_0 == 998 || TEMP_SENSOR_0 == 999
229+
#define TEMP_SENSOR_0_IS_DUMMY 1
226230
#elif TEMP_SENSOR_0 > 0
227231
#define TEMP_SENSOR_0_IS_THERMISTOR 1
228-
#if TEMP_SENSOR_0 == 1000
229-
#define TEMP_SENSOR_0_IS_CUSTOM 1
230-
#elif TEMP_SENSOR_0 == 998 || TEMP_SENSOR_0 == 999
231-
#define TEMP_SENSOR_0_IS_DUMMY 1
232-
#endif
233232
#else
234233
#undef HEATER_0_MINTEMP
235234
#undef HEATER_0_MAXTEMP
@@ -269,13 +268,12 @@
269268
#define TEMP_SENSOR_1_IS_AD8495 1
270269
#elif TEMP_SENSOR_1 == -1
271270
#define TEMP_SENSOR_1_IS_AD595 1
271+
#elif TEMP_SENSOR_1 == 1000
272+
#define TEMP_SENSOR_1_IS_CUSTOM 1
273+
#elif TEMP_SENSOR_1 == 998 || TEMP_SENSOR_1 == 999
274+
#define TEMP_SENSOR_1_IS_DUMMY 1
272275
#elif TEMP_SENSOR_1 > 0
273276
#define TEMP_SENSOR_1_IS_THERMISTOR 1
274-
#if TEMP_SENSOR_1 == 1000
275-
#define TEMP_SENSOR_1_IS_CUSTOM 1
276-
#elif TEMP_SENSOR_1 == 998 || TEMP_SENSOR_1 == 999
277-
#define TEMP_SENSOR_1_IS_DUMMY 1
278-
#endif
279277
#else
280278
#undef HEATER_1_MINTEMP
281279
#undef HEATER_1_MAXTEMP
@@ -315,18 +313,72 @@
315313
#define TEMP_SENSOR_2_IS_AD8495 1
316314
#elif TEMP_SENSOR_2 == -1
317315
#define TEMP_SENSOR_2_IS_AD595 1
316+
#elif TEMP_SENSOR_2 == 1000
317+
#define TEMP_SENSOR_2_IS_CUSTOM 1
318+
#elif TEMP_SENSOR_2 == 998 || TEMP_SENSOR_2 == 999
319+
#define TEMP_SENSOR_2_IS_DUMMY 1
318320
#elif TEMP_SENSOR_2 > 0
319321
#define TEMP_SENSOR_2_IS_THERMISTOR 1
320-
#if TEMP_SENSOR_2 == 1000
321-
#define TEMP_SENSOR_2_IS_CUSTOM 1
322-
#elif TEMP_SENSOR_2 == 998 || TEMP_SENSOR_2 == 999
323-
#define TEMP_SENSOR_2_IS_DUMMY 1
324-
#endif
325322
#else
326323
#undef HEATER_2_MINTEMP
327324
#undef HEATER_2_MAXTEMP
328325
#endif
329326

327+
#if TEMP_SENSOR_3 == 1000
328+
#define TEMP_SENSOR_3_IS_CUSTOM 1
329+
#elif TEMP_SENSOR_3 == 998 || TEMP_SENSOR_3 == 999
330+
#define TEMP_SENSOR_3_IS_DUMMY 1
331+
#elif TEMP_SENSOR_3 > 0
332+
#define TEMP_SENSOR_3_IS_THERMISTOR 1
333+
#elif !TEMP_SENSOR_3
334+
#undef HEATER_3_MINTEMP
335+
#undef HEATER_3_MAXTEMP
336+
#endif
337+
338+
#if TEMP_SENSOR_4 == 1000
339+
#define TEMP_SENSOR_4_IS_CUSTOM 1
340+
#elif TEMP_SENSOR_4 == 998 || TEMP_SENSOR_4 == 999
341+
#define TEMP_SENSOR_4_IS_DUMMY 1
342+
#elif TEMP_SENSOR_4 > 0
343+
#define TEMP_SENSOR_4_IS_THERMISTOR 1
344+
#elif !TEMP_SENSOR_4
345+
#undef HEATER_4_MINTEMP
346+
#undef HEATER_4_MAXTEMP
347+
#endif
348+
349+
#if TEMP_SENSOR_5 == 1000
350+
#define TEMP_SENSOR_5_IS_CUSTOM 1
351+
#elif TEMP_SENSOR_5 == 998 || TEMP_SENSOR_5 == 999
352+
#define TEMP_SENSOR_5_IS_DUMMY 1
353+
#elif TEMP_SENSOR_5 > 0
354+
#define TEMP_SENSOR_5_IS_THERMISTOR 1
355+
#elif !TEMP_SENSOR_5
356+
#undef HEATER_5_MINTEMP
357+
#undef HEATER_5_MAXTEMP
358+
#endif
359+
360+
#if TEMP_SENSOR_6 == 1000
361+
#define TEMP_SENSOR_6_IS_CUSTOM 1
362+
#elif TEMP_SENSOR_6 == 998 || TEMP_SENSOR_6 == 999
363+
#define TEMP_SENSOR_6_IS_DUMMY 1
364+
#elif TEMP_SENSOR_6 > 0
365+
#define TEMP_SENSOR_6_IS_THERMISTOR 1
366+
#elif !TEMP_SENSOR_6
367+
#undef HEATER_6_MINTEMP
368+
#undef HEATER_6_MAXTEMP
369+
#endif
370+
371+
#if TEMP_SENSOR_7 == 1000
372+
#define TEMP_SENSOR_7_IS_CUSTOM 1
373+
#elif TEMP_SENSOR_7 == 998 || TEMP_SENSOR_7 == 999
374+
#define TEMP_SENSOR_7_IS_DUMMY 1
375+
#elif TEMP_SENSOR_7 > 0
376+
#define TEMP_SENSOR_7_IS_THERMISTOR 1
377+
#elif !TEMP_SENSOR_7
378+
#undef HEATER_7_MINTEMP
379+
#undef HEATER_7_MAXTEMP
380+
#endif
381+
330382
#if TEMP_SENSOR_IS_MAX_TC(REDUNDANT)
331383
#if TEMP_SENSOR_REDUNDANT == -5
332384
#if !REDUNDANT_TEMP_MATCH(SOURCE, E0) && !REDUNDANT_TEMP_MATCH(SOURCE, E1) && !REDUNDANT_TEMP_MATCH(SOURCE, E2)

Marlin/src/lcd/marlinui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
149149
const preheat_t &pre = material_preset[m];
150150
TERN_(HAS_HOTEND, if (TEST(pmask, PT_HOTEND)) thermalManager.setTargetHotend(pre.hotend_temp, e));
151151
TERN_(HAS_HEATED_BED, if (TEST(pmask, PT_BED)) thermalManager.setTargetBed(pre.bed_temp));
152-
//TERN_(HAS_HEATED_CHAMBER, if (TEST(pmask, PT_CHAMBER)) thermalManager.setTargetBed(pre.chamber_temp));
152+
//TERN_(HAS_HEATED_CHAMBER, if (TEST(pmask, PT_CHAMBER)) thermalManager.setTargetChamber(pre.chamber_temp));
153153
TERN_(HAS_FAN, if (TEST(pmask, PT_FAN)) thermalManager.set_fan_speed(0, pre.fan_speed));
154154
}
155155
#endif

Marlin/src/module/temperature.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,22 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED);
317317

318318
#if HAS_HOTEND
319319
hotend_info_t Temperature::temp_hotend[HOTENDS];
320-
#define _HMT(N) HEATER_##N##_MAXTEMP,
321320
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);
321+
322+
// Sanity-check max readable temperatures
323+
#define CHECK_MAXTEMP_(N,M,S) static_assert( \
324+
S >= 998 || M <= _MAX(TT_NAME(S)[0].celsius, TT_NAME(S)[COUNT(TT_NAME(S)) - 1].celsius) - HOTEND_OVERSHOOT, \
325+
"HEATER_" STRINGIFY(N) "_MAXTEMP (" STRINGIFY(M) ") is too high for thermistor_" STRINGIFY(S) ".h with HOTEND_OVERSHOOT=" STRINGIFY(HOTEND_OVERSHOOT) ".");
326+
#define CHECK_MAXTEMP(N) TERN(TEMP_SENSOR_##N##_IS_THERMISTOR, CHECK_MAXTEMP_, CODE_0)(N, HEATER_##N##_MAXTEMP, TEMP_SENSOR_##N)
327+
REPEAT(HOTENDS, CHECK_MAXTEMP)
328+
329+
#if HAS_PREHEAT
330+
#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) ".");
331+
#define CHECK_PREHEAT_(N,P) CHECK_PREHEAT__(N, P, PREHEAT_##P##_TEMP_HOTEND, HEATER_##N##_MAXTEMP);
332+
#define CHECK_PREHEAT(P) REPEAT2(HOTENDS, CHECK_PREHEAT_, P);
333+
RREPEAT_1(PREHEAT_COUNT, CHECK_PREHEAT)
334+
#endif
335+
322336
#endif
323337

324338
#if HAS_TEMP_REDUNDANT

Marlin/src/module/thermistor/thermistor_2000.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
// 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
2525
constexpr temp_entry_t temptable_2000[] PROGMEM = {
26-
{ OV(313), 125 },
27-
{ OV(347), 120 },
28-
{ OV(383), 115 },
29-
{ OV(422), 110 },
30-
{ OV(463), 105 },
31-
{ OV(506), 100 },
26+
{ OV(313), 125 },
27+
{ OV(347), 120 },
28+
{ OV(383), 115 },
29+
{ OV(422), 110 },
30+
{ OV(463), 105 },
31+
{ OV(506), 100 },
3232
{ OV(549), 95 },
3333
{ OV(594), 90 },
3434
{ OV(638), 85 },

0 commit comments

Comments
 (0)