=== modified file 'control.c' --- control.c 2012-04-22 04:48:52 +0000 +++ control.c 2014-01-27 17:40:40 +0000 @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -68,17 +69,25 @@ }; //------------------------------------------------------------------------------ +#define MAX_FANS 10 char base_path[PATH_MAX]; -char fan1_min[PATH_MAX]; -char fan2_min[PATH_MAX]; -char fan1_man[PATH_MAX]; -char fan2_man[PATH_MAX]; + +struct Fan { + char minimum[PATH_MAX]; + char manual[PATH_MAX]; + char label[PATH_MAX]; +}; + +struct Fan fans[MAX_FANS]; + int sensor_count = 0; int fan_count = 0; float temp_avg = 0; int fan_speed; +int fan_TC0P_speed; +int fan_TG0P_speed; struct sensor *sensors = NULL; struct sensor *sensor_TC0P = NULL; @@ -163,11 +172,6 @@ exit(-1); } - sprintf(fan1_min, "%s/fan1_min", base_path); - sprintf(fan2_min, "%s/fan2_min", base_path); - sprintf(fan1_man, "%s/fan1_manual", base_path); - sprintf(fan2_man, "%s/fan2_manual", base_path); - printf("Found applesmc at %s\n", base_path); } @@ -201,6 +205,12 @@ sensors[i].value = (float)atoi(val_buf) / 1000.0; } close(fd); + + if (sensors[i].value < 5) { + printf("Error: Sensors %s was exluded due to invalid value '%f'.\n", sensors[i].fname, sensors[i].value); + fflush(stdout); + sensors[i].excluded = 1; + } } } } @@ -228,6 +238,8 @@ { fan_speed = fan_min; fan_ctl = CTL_NONE; + + //printf("temp_avg %d\n", (int)temp_avg); // calc fan speed on average @@ -235,6 +247,7 @@ float temp_avg_window = temp_avg_ceiling - temp_avg_floor; float normalized_temp =(temp_avg - temp_avg_floor) / temp_avg_window; float fan_avg_speed =(normalized_temp * fan_window); + //printf("fan_avg_speed %d\n", (int)fan_avg_speed); if(fan_avg_speed > fan_speed) { fan_speed = fan_avg_speed; @@ -247,10 +260,11 @@ { float temp_window = temp_TC0P_ceiling - temp_TC0P_floor; float normalized_temp =(sensor_TC0P->value - temp_TC0P_floor) / temp_window; - float fan_TC0P_speed =(normalized_temp * fan_window); - if(fan_TC0P_speed > fan_speed) + fan_TC0P_speed =(normalized_temp * fan_window); + //printf("fan_TC0P_speed %d\n", (int)fan_TC0P_speed); + if(fan_TC0P_speed < fan_min) { - fan_speed = fan_TC0P_speed; + fan_TC0P_speed = fan_min; fan_ctl = CTL_TC0P; } } @@ -261,14 +275,16 @@ { float temp_window = temp_TG0P_ceiling - temp_TG0P_floor; float normalized_temp =(sensor_TG0P->value - temp_TG0P_floor) / temp_window; - float fan_TG0P_speed =(normalized_temp * fan_window); - if(fan_TG0P_speed > fan_speed) + fan_TG0P_speed =(normalized_temp * fan_window); + //printf("fan_TG0P_speed %d\n", (int)fan_TG0P_speed); + if(fan_TG0P_speed < fan_min) { - fan_speed = fan_TG0P_speed; + fan_TG0P_speed = fan_min; fan_ctl = CTL_TG0P; } } + fflush(stdout); // finally clamp fan_speed = min(fan_max, fan_speed); @@ -279,57 +295,43 @@ void set_fan() { char buf[16]; - - // update fan 1 - - int fd = open(fan1_min, O_WRONLY); - if(fd < 0) - { - printf("Error: Can't open %s\n", fan1_min); - } - else - { - sprintf(buf, "%d", fan_speed); - write(fd, buf, strlen(buf)); - close(fd); - } - - // set fan 1 manual to zero - - fd = open(fan1_man, O_WRONLY); - if(fd < 0) - { - printf("Error: Can't open %s\n", fan1_man); - } - else - { - strcpy(buf, "0"); - write(fd, buf, strlen(buf)); - close(fd); - } - - // update fan 2 - - if(fan_count > 1) - { - fd = open(fan2_min, O_WRONLY); + int index; + + // update fans + printf("set_fan %d\n", fan_count); + + for (index = 0; index < fan_count; ++index) + { + // update fan + + int fd = open(fans[index].minimum, O_WRONLY); if(fd < 0) { - printf("Error: Can't open %s\n", fan2_min); + printf("Error: Can't open %s\n", fans[index].minimum); } else { - sprintf(buf, "%d", fan_speed); + if (strcmp(fans[index].label, "ODD") == 0) { // TG0D - sensor + sprintf(buf, "%d", (int)fan_TG0P_speed); + } + else if (strcmp(fans[index].label, "CPU") == 0) { // TG0D - sensor + sprintf(buf, "%d", (int)fan_TC0P_speed); + } + else { + sprintf(buf, "%d", (int)fan_speed); + } write(fd, buf, strlen(buf)); close(fd); + + //printf("echo %s > %s\n", buf, fans[index].minimum); } - - // set fan 2 manual to zero - - fd = open(fan2_man, O_WRONLY); + + // set fan manual to zero + + fd = open(fans[index].manual, O_WRONLY); if(fd < 0) { - printf("Error: Can't open %s\n", fan2_man); + printf("Error: Can't open %s\n", fans[index].manual); } else { @@ -363,30 +365,48 @@ sensor_TC0P = NULL; sensor_TG0P = NULL; - // get number of fans - - result = stat(fan1_min, &buf); - if(result != 0) + // find all fans + do + { + sprintf(fans[fan_count].minimum, "%s/fan%d_min", base_path, fan_count+1); + sprintf(fans[fan_count].manual, "%s/fan%d_manual", base_path, fan_count+1); + memset(fans[fan_count].label, 0, PATH_MAX); + + char label_file[PATH_MAX]; + sprintf(label_file, "%s/fan%d_label", base_path, fan_count+1); + FILE *fp = fopen(label_file, "r"); + if (fp) { + int n = fread(fans[fan_count].label, 1, PATH_MAX - 1, fp); + if(n < 0) { + fans[fan_count].label[0] = 0; + } + else { + fans[fan_count].label[n--] = 0; + while (isspace((int) fans[fan_count].label[n])) { + fans[fan_count].label[n--] = 0; + } + } + } + } + while( (0 == stat(fans[fan_count].manual, &buf)) && ++fan_count ); + + if(fan_count == 0) { printf("No fans detected, terminating!\n"); exit(-1); } else { - fan_count = 1; - } - - result = stat(fan2_min, &buf); - if(result != 0) - { - printf("Found 1 fan.\n"); - } - else - { - fan_count = 2; - printf("Found 2 fans.\n"); - } - + printf("Found %d fan.\n", fan_count); + int index; + for (index = 0; index < fan_count; ++index) + { + printf(" %d: '%s' -> %s\n", index, fans[index].label, fans[index].minimum); + } + + fflush(stdout); + } + // count number of sensors int count = 0; @@ -490,6 +510,10 @@ { sensor_TG0P = &sensors[i]; } + else if(strcmp(sensors[i].name, "TG0p") == 0 && !sensor_TG0P) // not prefered + { + sensor_TG0P = &sensors[i]; + } } // print out sensor information. === modified file 'debian/compat' --- debian/compat 2012-04-22 04:48:52 +0000 +++ debian/compat 2013-04-24 18:29:01 +0000 @@ -1,1 +1,1 @@ -7 +7 === modified file 'debian/control' --- debian/control 2012-04-22 04:48:52 +0000 +++ debian/control 2013-04-24 18:26:51 +0000 @@ -11,4 +11,4 @@ Depends: ${shlibs:Depends}, ${misc:Depends} Description: Fan control daemon for MacBook This daemon is a customizable fan control to keep the working temperature - within resonable limits. Se manpage macfanctld(1) for more information. + within resonable limits. Se manpage macfanctld(1) for more information. === modified file 'debian/init.d' --- debian/init.d 2012-04-22 04:48:52 +0000 +++ debian/init.d 2013-04-24 18:25:52 +0000 @@ -100,4 +100,4 @@ ;; esac -: +: === modified file 'debian/macfanctld.manpages' --- debian/macfanctld.manpages 2012-04-22 04:48:52 +0000 +++ debian/macfanctld.manpages 2013-04-24 18:25:02 +0000 @@ -1,1 +1,1 @@ -macfanctld.1 +macfanctld.1 \ No newline at end of file === modified file 'debian/rules' (properties changed: +x to -x) --- debian/rules 2012-04-22 04:48:52 +0000 +++ debian/rules 2013-04-24 18:24:05 +0000 @@ -10,4 +10,4 @@ export DH_VERBOSE=1 %: - dh $@ + dh $@ === modified file 'macfanctl.conf' --- macfanctl.conf 2012-04-22 04:48:52 +0000 +++ macfanctl.conf 2014-01-27 18:12:33 +0000 @@ -3,19 +3,19 @@ # Note: 0 < temp_X_floor < temp_X_ceiling # 0 < fan_min < 6200 -fan_min: 2000 +fan_min: 1500 temp_avg_floor: 45 temp_avg_ceiling: 55 -temp_TC0P_floor: 50 -temp_TC0P_ceiling: 58 +temp_TC0P_floor: 40 +temp_TC0P_ceiling: 60 -temp_TG0P_floor: 50 -temp_TG0P_ceiling: 58 +temp_TG0P_floor: 48 +temp_TG0P_ceiling: 75 # Add sensors to be excluded here, separated by space, i.e. -# exclude: 1 7 +# exclude: 1 2 3 20 21 # will disable reading of sensors temp1_input and temp7_input. exclude: