Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
Fan-Control-Daemon
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CeRiAl
Fan-Control-Daemon
Commits
45755d62
Commit
45755d62
authored
Oct 24, 2012
by
Daniel Graziotin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First attempt to fix #24
parent
eda84439
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
54 deletions
+78
-54
global.h
src/global.h
+10
-3
mbpfan.c
src/mbpfan.c
+59
-45
mbpfan.h
src/mbpfan.h
+6
-3
minunit.c
src/minunit.c
+3
-3
No files found.
src/global.h
View file @
45755d62
...
@@ -9,11 +9,18 @@ extern const char* program_pid;
...
@@ -9,11 +9,18 @@ extern const char* program_pid;
struct
s_sensors
{
struct
s_sensors
{
char
*
path
;
char
*
path
;
char
*
fan_output_path
;
char
*
fan_manual_path
;
unsigned
int
temperature
;
unsigned
int
temperature
;
struct
s_sensors
*
next
;
struct
s_sensors
*
next
;
};
};
typedef
s_sensors
t_sensors
;
struct
s_fans
{
char
*
path
;
char
*
fan_output_path
;
char
*
fan_manual_path
;
struct
s_fans
*
next
;
};
typedef
struct
s_sensors
t_sensors
;
typedef
struct
s_fans
t_fans
;
#endif
#endif
\ No newline at end of file
src/mbpfan.c
View file @
45755d62
...
@@ -57,18 +57,8 @@ int max_temp = 86; // do not set it > 90
...
@@ -57,18 +57,8 @@ int max_temp = 86; // do not set it > 90
int
polling_interval
=
7
;
int
polling_interval
=
7
;
/*
struct s_sensors {
char* path;
char* fan_output_path;
char* fan_manual_path;
unsigned int temperature;
struct s_sensors *next;
};
*/
typedef
struct
s_sensors
t_sensors
;
typedef
struct
s_sensors
t_sensors
;
typedef
struct
s_fans
t_fans
;
t_sensors
*
retrieve_sensors
()
t_sensors
*
retrieve_sensors
()
{
{
...
@@ -84,12 +74,12 @@ t_sensors *retrieve_sensors()
...
@@ -84,12 +74,12 @@ t_sensors *retrieve_sensors()
char
number
[
2
];
char
number
[
2
];
sprintf
(
number
,
"%d"
,
0
);
sprintf
(
number
,
"%d"
,
0
);
int
i
=
0
;
int
counter
=
0
;
int
sensors_found
=
0
;
for
(
i
=
0
;
i
<
10
;
i
++
)
{
for
(
counter
=
0
;
counter
<
10
;
counter
++
)
{
path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_size
);
path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_size
);
sprintf
(
number
,
"%d"
,
i
);
sprintf
(
number
,
"%d"
,
counter
);
path
[
0
]
=
'\0'
;
path
[
0
]
=
'\0'
;
strncat
(
path
,
path_begin
,
strlen
(
path_begin
)
);
strncat
(
path
,
path_begin
,
strlen
(
path_begin
)
);
strncat
(
path
,
number
,
strlen
(
number
)
);
strncat
(
path
,
number
,
strlen
(
number
)
);
...
@@ -119,22 +109,29 @@ t_sensors *retrieve_sensors()
...
@@ -119,22 +109,29 @@ t_sensors *retrieve_sensors()
}
}
fclose
(
file
);
fclose
(
file
);
sensors_found
++
;
}
}
free
(
path
);
free
(
path
);
path
=
NULL
;
path
=
NULL
;
}
}
if
(
sensors_head
!=
NULL
)
{
if
(
verbose
)
{
find_fans
(
sensors_head
);
printf
(
"Found %d sensors
\n
"
,
sensors_found
);
if
(
daemonize
)
{
syslog
(
LOG_INFO
,
"Found %d sensors"
,
sensors_found
);
}
}
}
return
sensors_head
;
return
sensors_head
;
}
}
void
find_fans
(
t_sensors
*
sensors
)
t_fans
*
retrieve_fans
(
)
{
{
t_sensors
*
tmp
=
sensors
;
t_fans
*
fans_head
=
NULL
;
t_fans
*
fan
=
NULL
;
char
*
path_output
=
NULL
;
char
*
path_output
=
NULL
;
char
*
path_manual
=
NULL
;
char
*
path_manual
=
NULL
;
...
@@ -142,17 +139,17 @@ void find_fans(t_sensors* sensors)
...
@@ -142,17 +139,17 @@ void find_fans(t_sensors* sensors)
const
char
*
path_begin
=
"/sys/devices/platform/applesmc.768/fan"
;
const
char
*
path_begin
=
"/sys/devices/platform/applesmc.768/fan"
;
const
char
*
path_output_end
=
"_output"
;
const
char
*
path_output_end
=
"_output"
;
const
char
*
path_man_end
=
"_manual"
;
const
char
*
path_man_end
=
"_manual"
;
int
path_min_size
=
strlen
(
path_begin
)
+
strlen
(
path_output_end
)
+
2
;
int
path_min_size
=
strlen
(
path_begin
)
+
strlen
(
path_output_end
)
+
2
;
int
path_man_size
=
strlen
(
path_begin
)
+
strlen
(
path_man_end
)
+
2
;
int
path_man_size
=
strlen
(
path_begin
)
+
strlen
(
path_man_end
)
+
2
;
char
number
[
2
];
char
number
[
2
];
sprintf
(
number
,
"%d"
,
0
);
sprintf
(
number
,
"%d"
,
0
);
int
counter
=
0
;
int
counter
=
0
;
int
n_sensors
=
0
;
int
fans_found
=
0
;
int
n_fans
=
0
;
for
(
counter
=
0
;
counter
<
10
;
counter
++
)
{
for
(
int
counter
=
0
;
counter
<
10
;
counter
++
)
{
path_output
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_min_size
);
path_output
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_min_size
);
path_output
[
0
]
=
'\0'
;
path_output
[
0
]
=
'\0'
;
path_manual
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_man_size
);
path_manual
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_man_size
);
...
@@ -171,38 +168,53 @@ void find_fans(t_sensors* sensors)
...
@@ -171,38 +168,53 @@ void find_fans(t_sensors* sensors)
FILE
*
file
=
fopen
(
path_output
,
"r"
);
FILE
*
file
=
fopen
(
path_output
,
"r"
);
if
(
file
!=
NULL
)
{
if
(
file
!=
NULL
)
{
if
(
tmp
->
path
!=
NULL
)
{
fan
=
(
t_fans
*
)
malloc
(
sizeof
(
t_fans
)
);
tmp
->
fan_output_path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_min_size
);
fan
->
fan_output_path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_min_size
);
tmp
->
fan_manual_path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_man_size
);
fan
->
fan_manual_path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_man_size
);
strcpy
(
fan
->
fan_output_path
,
path_output
);
strcpy
(
fan
->
fan_manual_path
,
path_manual
);
if
(
fans_head
==
NULL
)
{
fans_head
=
fan
;
fans_head
->
next
=
NULL
;
}
else
{
t_fans
*
tmp
=
fans_head
;
while
(
tmp
->
next
!=
NULL
)
{
tmp
=
tmp
->
next
;
}
tmp
->
next
=
fan
;
tmp
->
next
->
next
=
NULL
;
}
}
strcpy
(
tmp
->
fan_output_path
,
path_output
);
strcpy
(
tmp
->
fan_manual_path
,
path_manual
);
tmp
=
tmp
->
next
;
n_fans
++
;
n_sensors
++
;
fclose
(
file
);
fclose
(
file
);
fans_found
++
;
}
}
free
(
path_output
);
path_output
=
NULL
;
free
(
path_manual
);
path_manual
=
NULL
;
}
}
if
(
verbose
)
{
if
(
verbose
)
{
printf
(
"Found %d sensors and %d fans
\n
"
,
n_sensors
,
n_fans
);
printf
(
"Found %d fans
\n
"
,
fans_found
);
if
(
daemonize
)
{
if
(
daemonize
)
{
syslog
(
LOG_INFO
,
"Found %d
sensors and %d fans"
,
n_sensors
,
n_fans
);
syslog
(
LOG_INFO
,
"Found %d
fans"
,
fans_found
);
}
}
}
}
free
(
path_output
);
path_output
=
NULL
;
return
fans_head
;
free
(
path_manual
);
path_manual
=
NULL
;
}
}
void
set_fans_man
(
t_sensors
*
sensors
)
void
set_fans_man
(
t_fans
*
fans
)
{
{
t_
sensors
*
tmp
=
sensor
s
;
t_
fans
*
tmp
=
fan
s
;
FILE
*
file
;
FILE
*
file
;
while
(
tmp
!=
NULL
)
{
while
(
tmp
!=
NULL
)
{
...
@@ -238,9 +250,9 @@ t_sensors *refresh_sensors(t_sensors *sensors)
...
@@ -238,9 +250,9 @@ t_sensors *refresh_sensors(t_sensors *sensors)
/* Controls the speed of the fan */
/* Controls the speed of the fan */
void
set_fan_speed
(
t_
sensors
*
sensor
s
,
int
speed
)
void
set_fan_speed
(
t_
fans
*
fan
s
,
int
speed
)
{
{
t_
sensors
*
tmp
=
sensor
s
;
t_
fans
*
tmp
=
fan
s
;
FILE
*
file
;
FILE
*
file
;
while
(
tmp
!=
NULL
)
{
while
(
tmp
!=
NULL
)
{
...
@@ -359,10 +371,12 @@ void mbpfan()
...
@@ -359,10 +371,12 @@ void mbpfan()
retrieve_settings
();
retrieve_settings
();
t_sensors
*
sensors
=
retrieve_sensors
();
t_sensors
*
sensors
=
retrieve_sensors
();
set_fans_man
(
sensors
);
t_fans
*
fans
=
retrieve_fans
();
set_fans_man
(
fans
);
new_temp
=
get_temp
(
sensors
);
new_temp
=
get_temp
(
sensors
);
fan_speed
=
2000
;
fan_speed
=
2000
;
set_fan_speed
(
sensor
s
,
fan_speed
);
set_fan_speed
(
fan
s
,
fan_speed
);
if
(
verbose
)
{
if
(
verbose
)
{
...
@@ -413,7 +427,7 @@ void mbpfan()
...
@@ -413,7 +427,7 @@ void mbpfan()
}
}
}
}
set_fan_speed
(
sensor
s
,
fan_speed
);
set_fan_speed
(
fan
s
,
fan_speed
);
if
(
verbose
)
{
if
(
verbose
)
{
printf
(
"Sleeping for %d seconds
\n
"
,
polling_interval
);
printf
(
"Sleeping for %d seconds
\n
"
,
polling_interval
);
...
...
src/mbpfan.h
View file @
45755d62
...
@@ -40,6 +40,9 @@ extern int polling_interval;
...
@@ -40,6 +40,9 @@ extern int polling_interval;
struct
s_sensors
;
struct
s_sensors
;
typedef
struct
s_sensors
t_sensors
;
typedef
struct
s_sensors
t_sensors
;
struct
s_fans
;
typedef
struct
s_fans
t_fans
;
/**
/**
* Tries to use the settings located in
* Tries to use the settings located in
* /etc/mbpfan.conf
* /etc/mbpfan.conf
...
@@ -63,19 +66,19 @@ t_sensors *refresh_sensors(t_sensors *sensors);
...
@@ -63,19 +66,19 @@ t_sensors *refresh_sensors(t_sensors *sensors);
* Detect the fans in /sys/devices/platform/applesmc.768/
* Detect the fans in /sys/devices/platform/applesmc.768/
* Associate each fan to a sensor
* Associate each fan to a sensor
*/
*/
void
find_fans
(
t_sensors
*
sensors
);
t_fans
*
retrieve_fans
(
);
/**
/**
* Given a list of sensors with associated fans
* Given a list of sensors with associated fans
* Set them to manual control
* Set them to manual control
*/
*/
void
set_fans_man
(
t_
sensors
*
sensor
s
);
void
set_fans_man
(
t_
fans
*
fan
s
);
/**
/**
* Given a list of sensors with associated fans
* Given a list of sensors with associated fans
* Change their speed
* Change their speed
*/
*/
void
set_fan_speed
(
t_
sensors
*
sensor
s
,
int
speed
);
void
set_fan_speed
(
t_
fans
*
fan
s
,
int
speed
);
/**
/**
* Return average CPU temp in degrees (ceiling)
* Return average CPU temp in degrees (ceiling)
...
...
src/minunit.c
View file @
45755d62
...
@@ -33,9 +33,9 @@ static const char *test_sensor_paths()
...
@@ -33,9 +33,9 @@ static const char *test_sensor_paths()
static
const
char
*
test_fan_paths
()
static
const
char
*
test_fan_paths
()
{
{
t_
sensors
*
sensors
=
retrieve_sensor
s
();
t_
fans
*
fans
=
retrieve_fan
s
();
mu_assert
(
"No
sensors found"
,
sensor
s
!=
NULL
);
mu_assert
(
"No
fans found"
,
fan
s
!=
NULL
);
t_
sensors
*
tmp
=
sensor
s
;
t_
fans
*
tmp
=
fan
s
;
int
found_fan_path
=
0
;
int
found_fan_path
=
0
;
while
(
tmp
!=
NULL
)
{
while
(
tmp
!=
NULL
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment