temp.c: improved condition checks for next_read_time timers.
As @phord observed, the conditions and the meaning of next_read_time was not very intuitive. Changed that so that now it represents the number of 10ms clock ticks before next sensor reading, i.e. 1 is for 10ms, 2 for 20ms, etc.
This commit is contained in:
parent
678184b037
commit
1aa8698f62
16
temp.c
16
temp.c
|
|
@ -115,7 +115,7 @@ struct {
|
|||
needs frequent updates, otherwise 250ms so that we don't waste time on
|
||||
unnecessary reads.
|
||||
*/
|
||||
#define ANALOG_READ_INTERVAL ((TEMP_EWMA == 1.0) ? 25 : 0)
|
||||
#define ANALOG_READ_INTERVAL ((TEMP_EWMA == 1.0) ? 25 : 1)
|
||||
|
||||
|
||||
/// Set up temp sensors.
|
||||
|
|
@ -305,10 +305,7 @@ void temp_sensor_tick() {
|
|||
temp_sensor_t i = 0;
|
||||
|
||||
for (; i < NUM_TEMP_SENSORS; i++) {
|
||||
if (temp_sensors_runtime[i].next_read_time > 1) {
|
||||
temp_sensors_runtime[i].next_read_time--;
|
||||
}
|
||||
else {
|
||||
if (temp_sensors_runtime[i].next_read_time == 0) {
|
||||
uint16_t temp = 0;
|
||||
//time to deal with this temp sensor
|
||||
switch(temp_sensors[i].temp_type) {
|
||||
|
|
@ -404,7 +401,7 @@ void temp_sensor_tick() {
|
|||
else if (temp_sensors_runtime[i].target_temp < temp)
|
||||
temp--;
|
||||
|
||||
temp_sensors_runtime[i].next_read_time = 0;
|
||||
temp_sensors_runtime[i].next_read_time = 1;
|
||||
|
||||
break;
|
||||
#endif /* TEMP_DUMMY */
|
||||
|
|
@ -421,6 +418,13 @@ void temp_sensor_tick() {
|
|||
(EWMA_SCALE-EWMA_ALPHA) * temp_sensors_runtime[i].last_read_temp
|
||||
) / EWMA_SCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
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--;
|
||||
}
|
||||
|
||||
#ifdef NEEDS_START_ADC
|
||||
|
|
|
|||
Loading…
Reference in New Issue