From 4479b0222bb66dd54f2c60f50a35a9d35f3230dc Mon Sep 17 00:00:00 2001 From: Katelyn Schiesser Date: Mon, 12 Jul 2021 20:57:01 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Followup=20to=20TEMP=5FSENSOR=5F?= =?UTF-8?q?BOARD=20(#22343,=20#22344)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Followup to #22279 --- Marlin/src/inc/Conditionals_adv.h | 4 +++- Marlin/src/inc/Conditionals_post.h | 17 +++++++++++++++++ Marlin/src/module/temperature.cpp | 16 ++++++++-------- Marlin/src/module/temperature.h | 2 +- buildroot/tests/mega2560 | 11 +++++++++++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 33ed0dad38..c781ebb595 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -127,7 +127,9 @@ // Usurp a sensor to do redundant readings #if TEMP_SENSOR_REDUNDANT - #define REDUNDANT_TEMP_MATCH(M,N) (TEMP_SENSOR_REDUNDANT_##M == HID_##N) + #define _HEATER_ID(M) HID_##M + #define HEATER_ID(M) _HEATER_ID(M) + #define REDUNDANT_TEMP_MATCH(M,N) (HEATER_ID(TEMP_SENSOR_REDUNDANT_##M) == _HEATER_ID(N)) #else #define REDUNDANT_TEMP_MATCH(...) 0 #endif diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index d62debf755..1bac56339f 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1135,6 +1135,23 @@ #endif #endif +#if TEMP_SENSOR_BOARD == -4 + #define TEMP_SENSOR_BOARD_IS_AD8495 1 +#elif TEMP_SENSOR_BOARD == -3 + #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_BOARD." +#elif TEMP_SENSOR_BOARD == -2 + #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_BOARD." +#elif TEMP_SENSOR_BOARD == -1 + #define TEMP_SENSOR_BOARD_IS_AD595 1 +#elif TEMP_SENSOR_BOARD > 0 + #define TEMP_SENSOR_BOARD_IS_THERMISTOR 1 + #if TEMP_SENSOR_BOARD == 1000 + #define TEMP_SENSOR_BOARD_IS_CUSTOM 1 + #elif TEMP_SENSOR_BOARD == 998 || TEMP_SENSOR_BOARD == 999 + #define TEMP_SENSOR_BOARD_IS_DUMMY 1 + #endif +#endif + /** * X_DUAL_ENDSTOPS endstop reassignment */ diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 4a56ba66e9..fd2c260fd3 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -440,7 +440,7 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, board_info_t Temperature::temp_board; // = { 0 } #if ENABLED(THERMAL_PROTECTION_BOARD) int16_t Temperature::mintemp_raw_BOARD = TEMP_SENSOR_BOARD_RAW_LO_TEMP, - Temperature::maxtemp_raw_BOARD = TEMP_SENSOR_COOLER_RAW_HI_TEMP; + Temperature::maxtemp_raw_BOARD = TEMP_SENSOR_BOARD_RAW_HI_TEMP; #endif #endif @@ -951,7 +951,7 @@ void Temperature::_temp_error(const heater_id_t heater_id, PGM_P const serial_ms #if HAS_TEMP_REDUNDANT if (heater_id == H_REDUNDANT) { SERIAL_ECHOPGM(STR_REDUNDANT); // print redundant and cascade to print target, too. - real_heater_id = (heater_id_t)TEMP_SENSOR_REDUNDANT_TARGET; + real_heater_id = (heater_id_t)HEATER_ID(TEMP_SENSOR_REDUNDANT_TARGET); } #endif @@ -1323,7 +1323,7 @@ void Temperature::manage_heater() { #if HAS_TEMP_REDUNDANT // Make sure measured temperatures are close together if (ABS(degRedundantTarget() - degRedundant()) > TEMP_SENSOR_REDUNDANT_MAX_DIFF) - _temp_error((heater_id_t)TEMP_SENSOR_REDUNDANT_TARGET, PSTR(STR_REDUNDANCY), GET_TEXT(MSG_ERR_REDUNDANT_TEMP)); + _temp_error((heater_id_t)HEATER_ID(TEMP_SENSOR_REDUNDANT_TARGET), PSTR(STR_REDUNDANCY), GET_TEXT(MSG_ERR_REDUNDANT_TEMP)); #endif #if HAS_AUTO_FAN @@ -2015,7 +2015,7 @@ void Temperature::updateTemperaturesFromRawValues() { TERN_(TEMP_SENSOR_0_IS_MAX_TC, temp_hotend[0].raw = READ_MAX_TC(0)); TERN_(TEMP_SENSOR_1_IS_MAX_TC, temp_hotend[1].raw = READ_MAX_TC(1)); - TERN_(TEMP_SENSOR_REDUNDANT_IS_MAX_TC, temp_redundant.raw = READ_MAX_TC(TEMP_SENSOR_REDUNDANT_SOURCE)); + TERN_(TEMP_SENSOR_REDUNDANT_IS_MAX_TC, temp_redundant.raw = READ_MAX_TC(HEATER_ID(TEMP_SENSOR_REDUNDANT_SOURCE))); #if HAS_HOTEND HOTEND_LOOP() temp_hotend[e].celsius = analog_to_celsius_hotend(temp_hotend[e].raw, e); @@ -2455,9 +2455,9 @@ void Temperature::init() { while (analog_to_celsius_cooler(maxtemp_raw_COOLER) < COOLER_MAXTEMP) maxtemp_raw_COOLER -= TEMPDIR(COOLER) * (OVERSAMPLENR); #endif - #if HAS_TEMP_BOARD - while (analog_to_celsius_board(mintemp_raw_BOARD) > BOARD_MINTEMP) mintemp_raw_BOARD += TEMPDIR(BOARD) * (OVERSAMPLENR); - while (analog_to_celsius_board(maxtemp_raw_BOARD) < BOARD_MAXTEMP) maxtemp_raw_BOARD -= TEMPDIR(BOARD) * (OVERSAMPLENR); + #if BOTH(HAS_TEMP_BOARD, THERMAL_PROTECTION_BOARD) + while (analog_to_celsius_board(mintemp_raw_BOARD) < BOARD_MINTEMP) mintemp_raw_BOARD += TEMPDIR(BOARD) * (OVERSAMPLENR); + while (analog_to_celsius_board(maxtemp_raw_BOARD) > BOARD_MAXTEMP) maxtemp_raw_BOARD -= TEMPDIR(BOARD) * (OVERSAMPLENR); #endif #if HAS_TEMP_REDUNDANT @@ -2473,7 +2473,7 @@ void Temperature::init() { #elif REDUNDANT_TEMP_MATCH(TARGET, BED) && HAS_TEMP_BED temp_bed #else - temp_hotend[TEMP_SENSOR_REDUNDANT_TARGET] + temp_hotend[HEATER_ID(TEMP_SENSOR_REDUNDANT_TARGET)] #endif ); #endif diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index 61993c43a8..c78dfa9372 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -815,7 +815,7 @@ class Temperature { static inline int16_t rawBoardTemp() { return temp_board.raw; } #endif static inline celsius_float_t degBoard() { return temp_board.celsius; } - static inline celsius_t wholeDegBoard() { return static_cast(degBoard() + 0.5f); } + static inline celsius_t wholeDegBoard() { return static_cast(temp_board.celsius + 0.5f); } #endif #if HAS_TEMP_REDUNDANT diff --git a/buildroot/tests/mega2560 b/buildroot/tests/mega2560 index 0932388969..edae6d24ae 100755 --- a/buildroot/tests/mega2560 +++ b/buildroot/tests/mega2560 @@ -198,6 +198,17 @@ opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS EEPROM_BOO exec_test $1 $2 "REPRAP MEGA2560 RAMPS | Laser Feature | Air Evacuation | Air Assist | Cooler | Flowmeter | 44780 LCD " "$3" +# +# Test redundant temperature sensors + MAX TC +# +restore_configs +opt_set MOTHERBOARD BOARD_RAMPS_14_EFB EXTRUDERS 1 \ + TEMP_SENSOR_0 -2 TEMP_SENSOR_REDUNDANT -2 \ + TEMP_SENSOR_REDUNDANT_SOURCE E1 TEMP_SENSOR_REDUNDANT_TARGET E0 \ + TEMP_0_CS_PIN 11 TEMP_1_CS_PIN 12 + +exec_test $1 $2 "MEGA2560 RAMPS | Redundant temperature sensor | 2x MAX6675" "$3" + # # Language files test with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER #