Skip to content

Commit

Permalink
🐛 Followup to TEMP_SENSOR_BOARD (MarlinFirmware#22343, MarlinFirmware…
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbro authored and Night69 committed Aug 31, 2021
1 parent af96513 commit 6a7bfcc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<celsius_t>(degBoard() + 0.5f); }
static inline celsius_t wholeDegBoard() { return static_cast<celsius_t>(temp_board.celsius + 0.5f); }
#endif

#if HAS_TEMP_REDUNDANT
Expand Down
11 changes: 11 additions & 0 deletions buildroot/tests/mega2560
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,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
#
Expand Down

0 comments on commit 6a7bfcc

Please sign in to comment.