mbpfan-josie

Calculate temperature using maximum

Previously mbpfan used the mean temperature of all sensors which could
throttle processors by too slowly spinning the fans.  Fixes #199.

2c743b08e91cf9aee3612de98fe25dc36e9fc4ce
Andrew Gaul <andrew@gaul.org> · 2019-10-19T16:30 · browse files at this commit

parents: a28dd3e

diff --git a/src/mbpfan.c b/src/mbpfan.c
index 14bf795..fad6ac9 100644
--- a/src/mbpfan.c
+++ b/src/mbpfan.c
@@ -452,26 +452,16 @@ void set_fan_minimum_speed(t_fans* fans)
 unsigned short get_temp(t_sensors* sensors)
 {
     sensors = refresh_sensors(sensors);
-    int sum_temp = 0;
-    unsigned short temp = 0;
+    unsigned int temp = 0;
 
     t_sensors* tmp = sensors;
 
-    int number_sensors = 0;
-
     while(tmp != NULL) {
-        sum_temp += tmp->temperature;
+        temp = max(temp, tmp->temperature);
         tmp = tmp->next;
-        number_sensors++;
-    }
-
-    // just to be safe
-    if (number_sensors == 0) {
-        number_sensors++;
     }
 
-    temp = (unsigned short)( ceil( (float)( sum_temp ) / (number_sensors * 1000) ) );
-    return temp;
+    return temp / 1000;
 }
 
 void retrieve_settings(const char* settings_path, t_fans* fans)
diff --git a/src/mbpfan.h b/src/mbpfan.h
index 5198a13..595bc09 100644
--- a/src/mbpfan.h
+++ b/src/mbpfan.h
@@ -94,7 +94,7 @@ void set_fan_speed(t_fans* fan, int speed);
  */
 void set_fan_minimum_speed(t_fans* fans);
 /**
- *  Return average CPU temp in degrees (ceiling)
+ *  Return maximum CPU temp in degrees
  */
 unsigned short get_temp(t_sensors* sensors);