temp.c: cleanup temp_sensor_tick() and next_read_time sanity.
Integrate the next_read_time countdown into the loop as is common. Check for start_adc() in the same loop -- before decrementing the timer -- and call it when needed on the tick before we need the results. One concern I have still is that start_adc() may be called twice within a few microseconds if two probes need to be read. I expect it should only be called once, but I am not readily familiar with the AVR ADC conversion protocol.
This commit is contained in:
parent
86c3d97315
commit
afb81f21be
40
temp.c
40
temp.c
|
|
@ -288,6 +288,7 @@ void temp_sensor_tick() {
|
||||||
temp_sensor_t i = 0;
|
temp_sensor_t i = 0;
|
||||||
|
|
||||||
for (; i < NUM_TEMP_SENSORS; i++) {
|
for (; i < NUM_TEMP_SENSORS; i++) {
|
||||||
|
temp_sensors_runtime[i].next_read_time--;
|
||||||
if (temp_sensors_runtime[i].next_read_time == 0) {
|
if (temp_sensors_runtime[i].next_read_time == 0) {
|
||||||
uint16_t temp = 0;
|
uint16_t temp = 0;
|
||||||
//time to deal with this temp sensor
|
//time to deal with this temp sensor
|
||||||
|
|
@ -403,44 +404,13 @@ void temp_sensor_tick() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NEEDS_START_ADC
|
#ifdef NEEDS_START_ADC
|
||||||
/**
|
// Start the ADC one tick (10ms) before it's needed, if it'll be needed.
|
||||||
Sensors that use analog_read() need an start_adc() a 10ms cycle before
|
|
||||||
they actually do the reading so that ADC conversion can start and
|
|
||||||
finish in time.
|
|
||||||
*/
|
|
||||||
if (temp_sensors_runtime[i].next_read_time == 1) {
|
if (temp_sensors_runtime[i].next_read_time == 1) {
|
||||||
uint8_t needs_start_adc = 0;
|
if (temp_sensors[i].temp_type == TT_THERMISTOR ||
|
||||||
|
temp_sensors[i].temp_type == TT_AD595)
|
||||||
// Determine if the sensor uses analog_read().
|
start_adc();
|
||||||
switch(temp_sensors[i].temp_type) {
|
|
||||||
#ifdef TEMP_THERMISTOR
|
|
||||||
case TT_THERMISTOR:
|
|
||||||
needs_start_adc = 1;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TEMP_AD595
|
|
||||||
case TT_AD595:
|
|
||||||
needs_start_adc = 1;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* Prevent compiler warning. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needs_start_adc) {
|
|
||||||
start_adc();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
Decrement the counter here so that we avoid a off-by-one error. It's
|
|
||||||
assumed that sensor update code in the switch statement above has set a
|
|
||||||
non-zero next_read_time (!).
|
|
||||||
*/
|
|
||||||
temp_sensors_runtime[i].next_read_time--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue