Skip to content

Commit

Permalink
Simplified temp sensor conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Nov 9, 2020
1 parent 4ace02f commit 59eca25
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 178 deletions.
100 changes: 48 additions & 52 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
#endif

#if TEMP_SENSOR_0 == -5 || TEMP_SENSOR_0 == -3 || TEMP_SENSOR_0 == -2
#define HEATER_0_USES_MAX6675
#define HEATER_0_USES_MAX6675 1
#if TEMP_SENSOR_0 == -3
#define HEATER_0_MAX6675_TMIN -270
#define HEATER_0_MAX6675_TMAX 1800
Expand All @@ -445,27 +445,27 @@
#define HEATER_0_MAX6675_TMAX 1024
#endif
#if TEMP_SENSOR_0 == -5
#define MAX6675_IS_MAX31865
#define MAX6675_IS_MAX31865 1
#elif TEMP_SENSOR_0 == -3
#define MAX6675_IS_MAX31855
#define MAX6675_IS_MAX31855 1
#endif
#elif TEMP_SENSOR_0 == -4
#define HEATER_0_USES_AD8495
#define HEATER_0_USES_AD8495 1
#elif TEMP_SENSOR_0 == -1
#define HEATER_0_USES_AD595
#define HEATER_0_USES_AD595 1
#elif TEMP_SENSOR_0 > 0
#define THERMISTOR_HEATER_0 TEMP_SENSOR_0
#define HEATER_0_USES_THERMISTOR
#define HEATER_0_USES_THERMISTOR 1
#if TEMP_SENSOR_0 == 1000
#define HEATER_0_USER_THERMISTOR
#define HEATER_0_USER_THERMISTOR 1
#endif
#else
#undef HEATER_0_MINTEMP
#undef HEATER_0_MAXTEMP
#endif

#if TEMP_SENSOR_1 == -5 || TEMP_SENSOR_1 == -3 || TEMP_SENSOR_1 == -2
#define HEATER_1_USES_MAX6675
#define HEATER_1_USES_MAX6675 1
#if TEMP_SENSOR_1 == -3
#define HEATER_1_MAX6675_TMIN -270
#define HEATER_1_MAX6675_TMAX 1800
Expand All @@ -483,192 +483,188 @@
#endif
#endif
#elif TEMP_SENSOR_1 == -4
#define HEATER_1_USES_AD8495
#define HEATER_1_USES_AD8495 1
#elif TEMP_SENSOR_1 == -1
#define HEATER_1_USES_AD595
#define HEATER_1_USES_AD595 1
#elif TEMP_SENSOR_1 > 0
#define THERMISTOR_HEATER_1 TEMP_SENSOR_1
#define HEATER_1_USES_THERMISTOR
#define HEATER_1_USES_THERMISTOR 1
#if TEMP_SENSOR_1 == 1000
#define HEATER_1_USER_THERMISTOR
#define HEATER_1_USER_THERMISTOR 1
#endif
#else
#undef HEATER_1_MINTEMP
#undef HEATER_1_MAXTEMP
#endif

#if TEMP_SENSOR_2 == -4
#define HEATER_2_USES_AD8495
#define HEATER_2_USES_AD8495 1
#elif TEMP_SENSOR_2 == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_2."
#elif TEMP_SENSOR_2 == -2
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_2."
#elif TEMP_SENSOR_2 == -1
#define HEATER_2_USES_AD595
#define HEATER_2_USES_AD595 1
#elif TEMP_SENSOR_2 > 0
#define THERMISTOR_HEATER_2 TEMP_SENSOR_2
#define HEATER_2_USES_THERMISTOR
#define HEATER_2_USES_THERMISTOR 1
#if TEMP_SENSOR_2 == 1000
#define HEATER_2_USER_THERMISTOR
#define HEATER_2_USER_THERMISTOR 1
#endif
#else
#undef HEATER_2_MINTEMP
#undef HEATER_2_MAXTEMP
#endif

#if TEMP_SENSOR_3 == -4
#define HEATER_3_USES_AD8495
#define HEATER_3_USES_AD8495 1
#elif TEMP_SENSOR_3 == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_3."
#elif TEMP_SENSOR_3 == -2
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_3."
#elif TEMP_SENSOR_3 == -1
#define HEATER_3_USES_AD595
#define HEATER_3_USES_AD595 1
#elif TEMP_SENSOR_3 > 0
#define THERMISTOR_HEATER_3 TEMP_SENSOR_3
#define HEATER_3_USES_THERMISTOR
#define HEATER_3_USES_THERMISTOR 1
#if TEMP_SENSOR_3 == 1000
#define HEATER_3_USER_THERMISTOR
#define HEATER_3_USER_THERMISTOR 1
#endif
#else
#undef HEATER_3_MINTEMP
#undef HEATER_3_MAXTEMP
#endif

#if TEMP_SENSOR_4 == -4
#define HEATER_4_USES_AD8495
#define HEATER_4_USES_AD8495 1
#elif TEMP_SENSOR_4 == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_4."
#elif TEMP_SENSOR_4 == -2
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_4."
#elif TEMP_SENSOR_4 == -1
#define HEATER_4_USES_AD595
#define HEATER_4_USES_AD595 1
#elif TEMP_SENSOR_4 > 0
#define THERMISTOR_HEATER_4 TEMP_SENSOR_4
#define HEATER_4_USES_THERMISTOR
#define HEATER_4_USES_THERMISTOR 1
#if TEMP_SENSOR_4 == 1000
#define HEATER_4_USER_THERMISTOR
#define HEATER_4_USER_THERMISTOR 1
#endif
#else
#undef HEATER_4_MINTEMP
#undef HEATER_4_MAXTEMP
#endif

#if TEMP_SENSOR_5 == -4
#define HEATER_5_USES_AD8495
#define HEATER_5_USES_AD8495 1
#elif TEMP_SENSOR_5 == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_5."
#elif TEMP_SENSOR_5 == -2
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_5."
#elif TEMP_SENSOR_5 == -1
#define HEATER_5_USES_AD595
#define HEATER_5_USES_AD595 1
#elif TEMP_SENSOR_5 > 0
#define THERMISTOR_HEATER_5 TEMP_SENSOR_5
#define HEATER_5_USES_THERMISTOR
#define HEATER_5_USES_THERMISTOR 1
#if TEMP_SENSOR_5 == 1000
#define HEATER_5_USER_THERMISTOR
#define HEATER_5_USER_THERMISTOR 1
#endif
#else
#undef HEATER_5_MINTEMP
#undef HEATER_5_MAXTEMP
#endif

#if TEMP_SENSOR_6 == -4
#define HEATER_6_USES_AD8495
#define HEATER_6_USES_AD8495 1
#elif TEMP_SENSOR_6 == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_6."
#elif TEMP_SENSOR_6 == -2
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_6."
#elif TEMP_SENSOR_6 == -1
#define HEATER_6_USES_AD595
#define HEATER_6_USES_AD595 1
#elif TEMP_SENSOR_6 > 0
#define THERMISTOR_HEATER_6 TEMP_SENSOR_6
#define HEATER_6_USES_THERMISTOR
#define HEATER_6_USES_THERMISTOR 1
#if TEMP_SENSOR_6 == 1000
#define HEATER_6_USER_THERMISTOR
#define HEATER_6_USER_THERMISTOR 1
#endif
#else
#undef HEATER_6_MINTEMP
#undef HEATER_6_MAXTEMP
#endif

#if TEMP_SENSOR_7 == -4
#define HEATER_7_USES_AD8495
#define HEATER_7_USES_AD8495 1
#elif TEMP_SENSOR_7 == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_7."
#elif TEMP_SENSOR_7 == -2
#error "MAX7775 Thermocouples (-2) not supported for TEMP_SENSOR_7."
#elif TEMP_SENSOR_7 == -1
#define HEATER_7_USES_AD595
#define HEATER_7_USES_AD595 1
#elif TEMP_SENSOR_7 > 0
#define THERMISTOR_HEATER_7 TEMP_SENSOR_7
#define HEATER_7_USES_THERMISTOR
#define HEATER_7_USES_THERMISTOR 1
#if TEMP_SENSOR_7 == 1000
#define HEATER_7_USER_THERMISTOR
#define HEATER_7_USER_THERMISTOR 1
#endif
#else
#undef HEATER_7_MINTEMP
#undef HEATER_7_MAXTEMP
#endif

#if TEMP_SENSOR_BED == -4
#define HEATER_BED_USES_AD8495
#define HEATER_BED_USES_AD8495 1
#elif TEMP_SENSOR_BED == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_BED."
#elif TEMP_SENSOR_BED == -2
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_BED."
#elif TEMP_SENSOR_BED == -1
#define HEATER_BED_USES_AD595
#define HEATER_BED_USES_AD595 1
#elif TEMP_SENSOR_BED > 0
#define THERMISTORBED TEMP_SENSOR_BED
#define HEATER_BED_USES_THERMISTOR
#define HEATER_BED_USES_THERMISTOR 1
#if TEMP_SENSOR_BED == 1000
#define HEATER_BED_USER_THERMISTOR
#define HEATER_BED_USER_THERMISTOR 1
#endif
#else
#undef BED_MINTEMP
#undef BED_MAXTEMP
#endif

#if TEMP_SENSOR_CHAMBER == -4
#define HEATER_CHAMBER_USES_AD8495
#define HEATER_CHAMBER_USES_AD8495 1
#elif TEMP_SENSOR_CHAMBER == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_CHAMBER."
#elif TEMP_SENSOR_CHAMBER == -2
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_CHAMBER."
#elif TEMP_SENSOR_CHAMBER == -1
#define HEATER_CHAMBER_USES_AD595
#define HEATER_CHAMBER_USES_AD595 1
#elif TEMP_SENSOR_CHAMBER > 0
#define THERMISTORCHAMBER TEMP_SENSOR_CHAMBER
#define HEATER_CHAMBER_USES_THERMISTOR
#define HEATER_CHAMBER_USES_THERMISTOR 1
#if TEMP_SENSOR_CHAMBER == 1000
#define HEATER_CHAMBER_USER_THERMISTOR
#define HEATER_CHAMBER_USER_THERMISTOR 1
#endif
#else
#undef CHAMBER_MINTEMP
#undef CHAMBER_MAXTEMP
#endif

#if TEMP_SENSOR_PROBE == -4
#define HEATER_PROBE_USES_AD8495
#define HEATER_PROBE_USES_AD8495 1
#elif TEMP_SENSOR_PROBE == -3
#error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_PROBE."
#elif TEMP_SENSOR_PROBE == -2
#error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_PROBE."
#elif TEMP_SENSOR_PROBE == -1
#define HEATER_PROBE_USES_AD595
#define HEATER_PROBE_USES_AD595 1
#elif TEMP_SENSOR_PROBE > 0
#define THERMISTORPROBE TEMP_SENSOR_PROBE
#define PROBE_USES_THERMISTOR
#define HEATER_PROBE_USES_THERMISTOR 1
#if TEMP_SENSOR_PROBE == 1000
#define PROBE_USER_THERMISTOR
#define HEATER_PROBE_USER_THERMISTOR 1
#endif
#endif

#define HOTEND_USES_THERMISTOR ANY( \
HEATER_0_USES_THERMISTOR, HEATER_1_USES_THERMISTOR, HEATER_2_USES_THERMISTOR, HEATER_3_USES_THERMISTOR, \
HEATER_4_USES_THERMISTOR, HEATER_5_USES_THERMISTOR, HEATER_6_USES_THERMISTOR, HEATER_7_USES_THERMISTOR )

/**
* X_DUAL_ENDSTOPS endstop reassignment
*/
Expand Down
42 changes: 20 additions & 22 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1618,34 +1618,41 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
/**
* Required custom thermistor settings
*/
#if ENABLED(HEATER_0_USER_THERMISTOR) && !(defined(HOTEND0_PULLUP_RESISTOR_OHMS) && defined(HOTEND0_RESISTANCE_25C_OHMS) && defined(HOTEND0_BETA))
#if HEATER_0_USER_THERMISTOR && !(defined(HOTEND0_PULLUP_RESISTOR_OHMS) && defined(HOTEND0_RESISTANCE_25C_OHMS) && defined(HOTEND0_BETA))
#error "TEMP_SENSOR_0 1000 requires HOTEND0_PULLUP_RESISTOR_OHMS, HOTEND0_RESISTANCE_25C_OHMS and HOTEND0_BETA in Configuration_adv.h."
#elif ENABLED(HEATER_1_USER_THERMISTOR) && !(defined(HOTEND1_PULLUP_RESISTOR_OHMS) && defined(HOTEND1_RESISTANCE_25C_OHMS) && defined(HOTEND1_BETA))
#elif HEATER_1_USER_THERMISTOR && !(defined(HOTEND1_PULLUP_RESISTOR_OHMS) && defined(HOTEND1_RESISTANCE_25C_OHMS) && defined(HOTEND1_BETA))
#error "TEMP_SENSOR_1 1000 requires HOTEND1_PULLUP_RESISTOR_OHMS, HOTEND1_RESISTANCE_25C_OHMS and HOTEND1_BETA in Configuration_adv.h."
#elif ENABLED(HEATER_2_USER_THERMISTOR) && !(defined(HOTEND2_PULLUP_RESISTOR_OHMS) && defined(HOTEND2_RESISTANCE_25C_OHMS) && defined(HOTEND2_BETA))
#elif HEATER_2_USER_THERMISTOR && !(defined(HOTEND2_PULLUP_RESISTOR_OHMS) && defined(HOTEND2_RESISTANCE_25C_OHMS) && defined(HOTEND2_BETA))
#error "TEMP_SENSOR_2 1000 requires HOTEND2_PULLUP_RESISTOR_OHMS, HOTEND2_RESISTANCE_25C_OHMS and HOTEND2_BETA in Configuration_adv.h."
#elif ENABLED(HEATER_3_USER_THERMISTOR) && !(defined(HOTEND3_PULLUP_RESISTOR_OHMS) && defined(HOTEND3_RESISTANCE_25C_OHMS) && defined(HOTEND3_BETA))
#elif HEATER_3_USER_THERMISTOR && !(defined(HOTEND3_PULLUP_RESISTOR_OHMS) && defined(HOTEND3_RESISTANCE_25C_OHMS) && defined(HOTEND3_BETA))
#error "TEMP_SENSOR_3 1000 requires HOTEND3_PULLUP_RESISTOR_OHMS, HOTEND3_RESISTANCE_25C_OHMS and HOTEND3_BETA in Configuration_adv.h."
#elif ENABLED(HEATER_4_USER_THERMISTOR) && !(defined(HOTEND4_PULLUP_RESISTOR_OHMS) && defined(HOTEND4_RESISTANCE_25C_OHMS) && defined(HOTEND4_BETA))
#elif HEATER_4_USER_THERMISTOR && !(defined(HOTEND4_PULLUP_RESISTOR_OHMS) && defined(HOTEND4_RESISTANCE_25C_OHMS) && defined(HOTEND4_BETA))
#error "TEMP_SENSOR_4 1000 requires HOTEND4_PULLUP_RESISTOR_OHMS, HOTEND4_RESISTANCE_25C_OHMS and HOTEND4_BETA in Configuration_adv.h."
#elif ENABLED(HEATER_5_USER_THERMISTOR) && !(defined(HOTEND5_PULLUP_RESISTOR_OHMS) && defined(HOTEND5_RESISTANCE_25C_OHMS) && defined(HOTEND5_BETA))
#elif HEATER_5_USER_THERMISTOR && !(defined(HOTEND5_PULLUP_RESISTOR_OHMS) && defined(HOTEND5_RESISTANCE_25C_OHMS) && defined(HOTEND5_BETA))
#error "TEMP_SENSOR_5 1000 requires HOTEND5_PULLUP_RESISTOR_OHMS, HOTEND5_RESISTANCE_25C_OHMS and HOTEND5_BETA in Configuration_adv.h."
#elif ENABLED(HEATER_6_USER_THERMISTOR) && !(defined(HOTEND6_PULLUP_RESISTOR_OHMS) && defined(HOTEND6_RESISTANCE_25C_OHMS) && defined(HOTEND6_BETA))
#elif HEATER_6_USER_THERMISTOR && !(defined(HOTEND6_PULLUP_RESISTOR_OHMS) && defined(HOTEND6_RESISTANCE_25C_OHMS) && defined(HOTEND6_BETA))
#error "TEMP_SENSOR_6 1000 requires HOTEND6_PULLUP_RESISTOR_OHMS, HOTEND6_RESISTANCE_25C_OHMS and HOTEND6_BETA in Configuration_adv.h."
#elif ENABLED(HEATER_7_USER_THERMISTOR) && !(defined(HOTEND7_PULLUP_RESISTOR_OHMS) && defined(HOTEND7_RESISTANCE_25C_OHMS) && defined(HOTEND7_BETA))
#elif HEATER_7_USER_THERMISTOR && !(defined(HOTEND7_PULLUP_RESISTOR_OHMS) && defined(HOTEND7_RESISTANCE_25C_OHMS) && defined(HOTEND7_BETA))
#error "TEMP_SENSOR_7 1000 requires HOTEND7_PULLUP_RESISTOR_OHMS, HOTEND7_RESISTANCE_25C_OHMS and HOTEND7_BETA in Configuration_adv.h."
#elif ENABLED(HEATER_BED_USER_THERMISTOR) && !(defined(BED_PULLUP_RESISTOR_OHMS) && defined(BED_RESISTANCE_25C_OHMS) && defined(BED_BETA))
#elif HEATER_BED_USER_THERMISTOR && !(defined(BED_PULLUP_RESISTOR_OHMS) && defined(BED_RESISTANCE_25C_OHMS) && defined(BED_BETA))
#error "TEMP_SENSOR_BED 1000 requires BED_PULLUP_RESISTOR_OHMS, BED_RESISTANCE_25C_OHMS and BED_BETA in Configuration_adv.h."
#elif ENABLED(HEATER_CHAMBER_USER_THERMISTOR) && !(defined(CHAMBER_PULLUP_RESISTOR_OHMS) && defined(CHAMBER_RESISTANCE_25C_OHMS) && defined(CHAMBER_BETA))
#elif HEATER_CHAMBER_USER_THERMISTOR && !(defined(CHAMBER_PULLUP_RESISTOR_OHMS) && defined(CHAMBER_RESISTANCE_25C_OHMS) && defined(CHAMBER_BETA))
#error "TEMP_SENSOR_CHAMBER 1000 requires CHAMBER_PULLUP_RESISTOR_OHMS, CHAMBER_RESISTANCE_25C_OHMS and CHAMBER_BETA in Configuration_adv.h."
#endif

/**
* A Sensor ID has to be set for each heater
* Pins and Sensor IDs must be set for each heater
*/
#if HEATER_0_USES_MAX6675 && !PIN_EXISTS(MAX6675_SS)
#error "MAX6675_SS_PIN (required for TEMP_SENSOR_0) not defined for this board."
#elif HAS_HOTEND && !HAS_TEMP_HOTEND
#error "TEMP_0_PIN (required for TEMP_SENSOR_0) not defined for this board."
#elif EITHER(HAS_MULTI_HOTEND, HEATERS_PARALLEL) && !HAS_HEATER_1
#error "HEATER_1_PIN is not defined. TEMP_SENSOR_1 might not be set, or the board (not EEB / EEF?) doesn't define a pin."
#endif

#if HAS_MULTI_HOTEND
#if ENABLED(HEATER_1_USES_MAX6675) && !PIN_EXISTS(MAX6675_SS2)
#if HEATER_1_USES_MAX6675 && !PIN_EXISTS(MAX6675_SS2)
#error "MAX6675_SS2_PIN (required for TEMP_SENSOR_1) not defined for this board."
#elif TEMP_SENSOR_1 == 0
#error "TEMP_SENSOR_1 is required with 2 or more HOTENDS."
Expand Down Expand Up @@ -1808,7 +1815,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
#error "TEMP_SENSOR_1 is required with TEMP_SENSOR_1_AS_REDUNDANT."
#endif

#if ENABLED(MAX6675_IS_MAX31865) && (!defined(MAX31865_SENSOR_OHMS) || !defined(MAX31865_CALIBRATION_OHMS))
#if MAX6675_IS_MAX31865 && !(defined(MAX31865_SENSOR_OHMS) && defined(MAX31865_CALIBRATION_OHMS))
#error "MAX31865_SENSOR_OHMS and MAX31865_CALIBRATION_OHMS must be set in Configuration.h when using a MAX31865 temperature sensor."
#endif

Expand All @@ -1827,15 +1834,6 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
#error "TEMP_SENSOR_0 is required if there are any extruders."
#endif

// Pins are required for heaters
#if ENABLED(HEATER_0_USES_MAX6675) && !PIN_EXISTS(MAX6675_SS)
#error "MAX6675_SS_PIN (required for TEMP_SENSOR_0) not defined for this board."
#elif HAS_HOTEND && !HAS_TEMP_HOTEND
#error "TEMP_0_PIN (required for TEMP_SENSOR_0) not defined for this board."
#elif EITHER(HAS_MULTI_HOTEND, HEATERS_PARALLEL) && !HAS_HEATER_1
#error "HEATER_1_PIN is not defined. TEMP_SENSOR_1 might not be set, or the board (not EEB / EEF?) doesn't define a pin."
#endif

/**
* Temperature status LEDs
*/
Expand Down
Loading

0 comments on commit 59eca25

Please sign in to comment.