forked from rvega/Fan-Control-Daemon
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for configfile /etc/mbpfan.conf
- Loading branch information
Showing
5 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
MAINTAINERS AND CONTRIBUTORS | ||
---------------------------- | ||
|
||
Daniel Graziotin <dgraziotin AT task3 DOT cc> | ||
CeRiAl <ikhatib AT imail DOT de> | ||
Daniel Graziotin <dgraziotin AT task3 DOT cc> | ||
Ismail Khatib <ikhatib AT gmail DOT com> | ||
|
||
|
||
ORIGINARY AUTHORS | ||
----------------- | ||
|
||
Allan McRae mbpfan <http://allanmcrae.com/2010/05/simple-macbook-pro-fan-daemon> | ||
rvega <https://github.com/rvega/Fan-Control-Daemon> | ||
Allan McRae mbpfan <http://allanmcrae.com/2010/05/simple-macbook-pro-fan-daemon> | ||
rvega <https://github.com/rvega/Fan-Control-Daemon> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[general] | ||
min_fan_speed = 2000 # default is 2000 | ||
max_fan_speed = 6200 # default is 6200 | ||
low_temp = 63 # try ranges 55-63, default is 63 | ||
high_temp = 66 # try ranges 58-66, default is 66 | ||
max_temp = 86 # do not set it > 90, default is 86 | ||
polling_interval = 7 # default is 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/** | ||
* Copyright (C) 2012 Peter Lombardo <http://peterlombardo.wikidot.com/linux-daemon-in-c> | ||
* Modifications (2012) by Daniel Graziotin <[email protected]> | ||
* Modifications (2012) by Ismail Khatib <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -162,23 +163,23 @@ void go_daemon(void (*fan_control)()) | |
{ | ||
if (verbose) | ||
{ | ||
printf("Writing a new .pid file with value %d at: %s", current_pid, program_pid); | ||
printf("Writing a new .pid file with value %d at: %s\n", current_pid, program_pid); | ||
syslog(LOG_INFO, "Writing a new .pid file with value %d at: %s", current_pid, program_pid); | ||
} | ||
if (write_pid(current_pid) == 0) | ||
{ | ||
syslog(LOG_ERR, "Can not create a .pid file at: %s. Aborting", program_pid); | ||
if (verbose) | ||
{ | ||
printf("ERROR: Can not create a .pid file at: %s. Aborting", program_pid); | ||
printf("ERROR: Can not create a .pid file at: %s. Aborting\n", program_pid); | ||
} | ||
exit(EXIT_FAILURE); | ||
} | ||
else | ||
{ | ||
if (verbose) | ||
{ | ||
printf("Successfully written a new .pid file with value %d at: %s", current_pid, program_pid); | ||
printf("Successfully written a new .pid file with value %d at: %s\n", current_pid, program_pid); | ||
syslog(LOG_INFO, "Successfully written a new .pid file with value %d at: %s", current_pid, program_pid); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
* Copyright (C) 2010 Allan McRae <[email protected]> | ||
* Modifications by Rafael Vega <[email protected]> | ||
* Modifications (2012) by Daniel Graziotin <[email protected]> | ||
* Modifications (2012) by Ismail Khatib <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -24,7 +25,8 @@ | |
* | ||
* Tested models: | ||
* MacBook Pro 8.1 13" (Intel i7 - Linux 3.2) | ||
* Macbook Pro 6,2 15" (Intel i7 - Linux 3.2) | ||
* MacBook Pro 6,2 15" (Intel i7 - Linux 3.2) | ||
* MacBook Pro 2,2 15" (Intel Core 2 Duo - Linux 3.4.4) | ||
*/ | ||
|
||
|
||
|
@@ -36,6 +38,7 @@ | |
#include <syslog.h> | ||
#include "mbpfan.h" | ||
#include "global.h" | ||
#include "settings.h" | ||
|
||
/* lazy min/max... */ | ||
#define min(a,b) a < b ? a : b | ||
|
@@ -273,19 +276,72 @@ void mbpfan() | |
int old_temp, new_temp, fan_speed, steps; | ||
int temp_change; | ||
int step_up, step_down; | ||
FILE *f = NULL; | ||
Settings *settings = NULL; | ||
int result = 0; | ||
|
||
t_sensors* sensors = retrieve_sensors(); | ||
set_fans_man(sensors); | ||
new_temp = get_temp(sensors); | ||
fan_speed = 2000; | ||
set_fan_speed(sensors, fan_speed); | ||
|
||
f = fopen("/etc/mbpfan.conf", "r"); | ||
if (f == NULL) | ||
{ | ||
/* Could not open configfile */ | ||
if(verbose) | ||
{ | ||
printf("Couldn't open configfile, using defaults\n"); | ||
if(daemonize) | ||
{ | ||
syslog(LOG_INFO, "Couldn't open configfile, using defaults"); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
settings = settings_open(f); | ||
fclose(f); | ||
if (settings == NULL) | ||
{ | ||
/* Could not read configfile */ | ||
if(verbose) | ||
{ | ||
printf("Couldn't read configfile\n"); | ||
if(daemonize) | ||
{ | ||
syslog(LOG_INFO, "Couldn't read configfile"); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
/* Read configfile values */ | ||
result = settings_get_int(settings, "general", "min_fan_speed"); | ||
if (result != 0) min_fan_speed = result; | ||
result = settings_get_int(settings, "general", "max_fan_speed"); | ||
if (result != 0) max_fan_speed = result; | ||
result = settings_get_int(settings, "general", "low_temp"); | ||
if (result != 0) low_temp = result; | ||
result = settings_get_int(settings, "general", "high_temp"); | ||
if (result != 0) high_temp = result; | ||
result = settings_get_int(settings, "general", "max_temp"); | ||
if (result != 0) max_temp = result; | ||
result = settings_get_int(settings, "general", "polling_interval"); | ||
if (result != 0) polling_interval = result; | ||
|
||
/* Destroy the settings object */ | ||
settings_delete(settings); | ||
} | ||
} | ||
|
||
if(verbose) | ||
{ | ||
printf("Sleeping for %d seconds\n", polling_interval); | ||
if(daemonize) | ||
{ | ||
syslog(LOG_INFO, "Sleeping for %d seconds\n", polling_interval); | ||
syslog(LOG_INFO, "Sleeping for %d seconds", polling_interval); | ||
} | ||
} | ||
sleep(polling_interval); | ||
|
@@ -330,7 +386,7 @@ void mbpfan() | |
printf("Old Temp %d: New Temp: %d, Fan Speed: %d\n", old_temp, new_temp, fan_speed); | ||
if(daemonize) | ||
{ | ||
syslog(LOG_INFO, "Old Temp %d: New Temp: %d, Fan Speed: %d\n", old_temp, new_temp, fan_speed); | ||
syslog(LOG_INFO, "Old Temp %d: New Temp: %d, Fan Speed: %d", old_temp, new_temp, fan_speed); | ||
} | ||
} | ||
|
||
|
@@ -341,7 +397,7 @@ void mbpfan() | |
printf("Sleeping for %d seconds\n", polling_interval); | ||
if(daemonize) | ||
{ | ||
syslog(LOG_INFO, "Sleeping for %d seconds\n", polling_interval); | ||
syslog(LOG_INFO, "Sleeping for %d seconds", polling_interval); | ||
} | ||
} | ||
sleep(polling_interval); | ||
|