From 537b93ae89f6525a034461a61fdfca311a5c7afd Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Wed, 20 Apr 2016 10:33:12 -0400 Subject: [PATCH] Properly handle temp sensor initialization The existing code eschews "break" apparently thinking that it will exit the loop prematurely. In fact this will only exit the switch correctly. The loop will run as normal. Maybe it's not a big deal, though, since the sensors get re-inited each time the type of sensor is encountered in the loop. Presumably it's ok for each of these sensors to get inited multiple times. If that's always the case, maybe there's no problem here. But with the current code sensor types might be initialized even when there is no sensor defined for that type if the TEMP_* boolean is #defined. For example, if I have this in my config: #define TEMP_MAX6675 #define TEMP_MCP3008 //#define TEMP_INTERCOM DEFINE_TEMP_SENSOR(extruder, TT_MAX6675, AIO5, 0) DEFINE_TEMP_SENSOR(bed, TT_MAX6675, AIO7, 0) Then the MAX6675 initialization code will be run twice and the MCP3008 code will, too, even though no temp sensor is defined for that type. This change does not address the "init runs twice" problem. It only addresses the "initialization of unused types" problem. --- temp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/temp.c b/temp.c index 236a6b3..3bf5d80 100644 --- a/temp.c +++ b/temp.c @@ -99,14 +99,14 @@ void temp_init() { // Note that MAX6675's Chip Select pin is currently hardcoded to SS. // This isn't neccessary. See also spi.h. spi_deselect_max6675(); - // Intentionally no break, we might have more than one sensor type. + break; #endif #ifdef TEMP_MCP3008 case TT_MCP3008: SET_OUTPUT(MCP3008_SELECT_PIN); spi_deselect_mcp3008(); - // Intentionally no break, we might have more than one sensor type. + break; #endif #ifdef TEMP_THERMISTOR @@ -131,7 +131,7 @@ void temp_init() { intercom_init(); send_temperature(0, 0); - // Intentionally no break. + break; #endif default: /* prevent compiler warning */