Taking into account the number of sensors in averaging temp #24

This commit is contained in:
Daniel Graziotin 2012-10-24 14:18:11 +02:00
parent 45755d6228
commit 3ff1aad95f

View file

@ -277,12 +277,18 @@ unsigned short get_temp(t_sensors* sensors)
t_sensors* tmp = sensors;
int number_sensors = 0;
while(tmp != NULL) {
sum_temp += tmp->temperature;
tmp = tmp->next;
number_sensors++;
}
temp = (unsigned short)( ceil( (float)( sum_temp ) / 2000. ) );
// just to be safe
if (number_sensors == 0)
number_sensors++;
temp = (unsigned short)( ceil( (float)( sum_temp ) / (number_sensors * 1000) ) );
return temp;
}