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.
This commit is contained in:
parent
fbe1832467
commit
537b93ae89
6
temp.c
6
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 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue