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
0428dafb
Commit
0428dafb
authored
Jun 09, 2012
by
Daniel Graziotin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Take manual control of the fans
Converted all unsigned short to int Changed Polling Interval to 5
parent
e63b4d16
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
67 deletions
+104
-67
.gitignore
.gitignore
+1
-1
Makefile
Makefile
+2
-2
mbpfan.c
src/mbpfan.c
+86
-55
mbpfan.h
src/mbpfan.h
+15
-9
No files found.
.gitignore
View file @
0428dafb
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*.iml
*.iml
# Object files
# Object files
*.o
*.o
bin/*
# Libraries
# Libraries
*.lib
*.lib
...
...
Makefile
View file @
0428dafb
...
@@ -12,7 +12,7 @@ ifeq ($(COMPILER), G++)
...
@@ -12,7 +12,7 @@ ifeq ($(COMPILER), G++)
else
else
OBJ
=
o
OBJ
=
o
endif
endif
COPT
=
-O2
COPT
=
CCMD
=
g++
CCMD
=
g++
OBJFLAG
=
-o
OBJFLAG
=
-o
EXEFLAG
=
-o
EXEFLAG
=
-o
...
@@ -53,4 +53,4 @@ clean:
...
@@ -53,4 +53,4 @@ clean:
rm
-rf
$(SOURCE_PATH)
*
.
$(OBJ)
$(EXE)
rm
-rf
$(SOURCE_PATH)
*
.
$(OBJ)
$(EXE)
rebuild
:
clean all
rebuild
:
clean all
#rebuild
is
not
entirely
correct
#rebuild is not entirely correct
\ No newline at end of file
src/mbpfan.c
View file @
0428dafb
...
@@ -39,64 +39,28 @@
...
@@ -39,64 +39,28 @@
#define min(a,b) a < b ? a : b
#define min(a,b) a < b ? a : b
#define max(a,b) a > b ? a : b
#define max(a,b) a > b ? a : b
unsigned
shor
t
min_fan_speed
=
2000
;
in
t
min_fan_speed
=
2000
;
unsigned
shor
t
max_fan_speed
=
6200
;
in
t
max_fan_speed
=
6200
;
/* temperature thresholds
/* temperature thresholds
* low_temp - temperature below which fan speed will be at minimum
* low_temp - temperature below which fan speed will be at minimum
* high_temp - fan will increase speed when higher than this temperature
* high_temp - fan will increase speed when higher than this temperature
* max_temp - fan will run at full speed above this temperature */
* max_temp - fan will run at full speed above this temperature */
unsigned
shor
t
low_temp
=
63
;
// try ranges 55-63
in
t
low_temp
=
63
;
// try ranges 55-63
unsigned
shor
t
high_temp
=
66
;
// try ranges 58-66
in
t
high_temp
=
66
;
// try ranges 58-66
unsigned
shor
t
max_temp
=
86
;
// do not set it > 90
in
t
max_temp
=
86
;
// do not set it > 90
unsigned
short
polling_interval
=
7
;
int
polling_interval
=
5
;
struct
s_sensors
{
struct
s_sensors
{
char
*
path
;
char
*
path
;
char
*
fan_path
;
char
*
fan_min_path
;
char
*
fan_man_path
;
unsigned
int
temperature
;
unsigned
int
temperature
;
struct
s_sensors
*
next
;
struct
s_sensors
*
next
;
};
};
void
find_fans
(
t_sensors
*
sensors
)
{
t_sensors
*
tmp
=
sensors
;
char
*
path
=
NULL
;
const
char
*
path_begin
=
"/sys/devices/platform/applesmc.768/fan"
;
const
char
*
path_end
=
"_min"
;
int
path_size
=
strlen
(
path_begin
)
+
strlen
(
path_end
)
+
2
;
char
number
[
1
];
sprintf
(
number
,
"%d"
,
0
);
int
counter
=
0
;
for
(
counter
=
0
;
counter
<
10
;
counter
++
)
{
path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_size
);
path
[
0
]
=
'\0'
;
sprintf
(
number
,
"%d"
,
counter
);
strncat
(
path
,
path_begin
,
strlen
(
path_begin
)
);
strncat
(
path
,
number
,
strlen
(
number
)
);
strncat
(
path
,
path_end
,
strlen
(
path_begin
)
);
FILE
*
file
=
fopen
(
path
,
"r"
);
if
(
file
!=
NULL
)
{
if
(
tmp
->
path
!=
NULL
)
tmp
->
fan_path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_size
);
strcpy
(
tmp
->
fan_path
,
path
);
tmp
=
tmp
->
next
;
fclose
(
file
);
}
}
free
(
path
);
path
=
NULL
;
}
t_sensors
*
find_sensors
()
t_sensors
*
find_sensors
()
{
{
...
@@ -128,7 +92,7 @@ t_sensors *find_sensors()
...
@@ -128,7 +92,7 @@ t_sensors *find_sensors()
s
=
(
t_sensors
*
)
malloc
(
sizeof
(
t_sensors
)
);
s
=
(
t_sensors
*
)
malloc
(
sizeof
(
t_sensors
)
);
s
->
path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_size
);
s
->
path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_size
);
strcpy
(
s
->
path
,
path
);
strcpy
(
s
->
path
,
path
);
int
result
=
fscanf
(
file
,
"%d"
,
&
s
->
temperature
);
fscanf
(
file
,
"%d"
,
&
s
->
temperature
);
if
(
sensors_head
==
NULL
)
{
if
(
sensors_head
==
NULL
)
{
sensors_head
=
s
;
sensors_head
=
s
;
sensors_head
->
next
=
NULL
;
sensors_head
->
next
=
NULL
;
...
@@ -150,6 +114,75 @@ t_sensors *find_sensors()
...
@@ -150,6 +114,75 @@ t_sensors *find_sensors()
return
sensors_head
;
return
sensors_head
;
}
}
void
find_fans
(
t_sensors
*
sensors
)
{
t_sensors
*
tmp
=
sensors
;
char
*
path_min
=
NULL
;
char
*
path_man
=
NULL
;
const
char
*
path_begin
=
"/sys/devices/platform/applesmc.768/fan"
;
const
char
*
path_min_end
=
"_min"
;
const
char
*
path_man_end
=
"_manual"
;
int
path_min_size
=
strlen
(
path_begin
)
+
strlen
(
path_min_end
)
+
2
;
int
path_man_size
=
strlen
(
path_begin
)
+
strlen
(
path_man_end
)
+
2
;
char
number
[
1
];
sprintf
(
number
,
"%d"
,
0
);
int
counter
=
0
;
for
(
counter
=
0
;
counter
<
10
;
counter
++
)
{
path_min
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_min_size
);
path_min
[
0
]
=
'\0'
;
path_man
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_man_size
);
path_man
[
0
]
=
'\0'
;
sprintf
(
number
,
"%d"
,
counter
);
strncat
(
path_min
,
path_begin
,
strlen
(
path_begin
)
);
strncat
(
path_min
,
number
,
strlen
(
number
)
);
strncat
(
path_min
,
path_min_end
,
strlen
(
path_begin
)
);
strncat
(
path_man
,
path_begin
,
strlen
(
path_begin
)
);
strncat
(
path_man
,
number
,
strlen
(
number
)
);
strncat
(
path_man
,
path_man_end
,
strlen
(
path_begin
)
);
FILE
*
file
=
fopen
(
path_min
,
"r"
);
if
(
file
!=
NULL
)
{
if
(
tmp
->
path
!=
NULL
){
tmp
->
fan_min_path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_min_size
);
tmp
->
fan_man_path
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
path_man_size
);
}
strcpy
(
tmp
->
fan_min_path
,
path_min
);
strcpy
(
tmp
->
fan_man_path
,
path_man
);
tmp
=
tmp
->
next
;
fclose
(
file
);
}
}
free
(
path_min
);
path_min
=
NULL
;
free
(
path_man
);
path_man
=
NULL
;
}
void
set_fans_man
(
t_sensors
*
sensors
)
{
t_sensors
*
tmp
=
sensors
;
FILE
*
file
;
while
(
tmp
!=
NULL
)
{
file
=
fopen
(
tmp
->
fan_man_path
,
"rw+"
);
if
(
file
!=
NULL
)
{
fprintf
(
file
,
"%d"
,
0
);
fclose
(
file
);
}
tmp
=
tmp
->
next
;
}
}
t_sensors
*
refresh_sensors
(
t_sensors
*
sensors
)
t_sensors
*
refresh_sensors
(
t_sensors
*
sensors
)
{
{
...
@@ -159,7 +192,7 @@ t_sensors *refresh_sensors(t_sensors *sensors)
...
@@ -159,7 +192,7 @@ t_sensors *refresh_sensors(t_sensors *sensors)
FILE
*
file
=
fopen
(
tmp
->
path
,
"r"
);
FILE
*
file
=
fopen
(
tmp
->
path
,
"r"
);
if
(
file
!=
NULL
)
{
if
(
file
!=
NULL
)
{
int
result
=
fscanf
(
file
,
"%d"
,
&
tmp
->
temperature
);
fscanf
(
file
,
"%d"
,
&
tmp
->
temperature
);
fclose
(
file
);
fclose
(
file
);
}
}
...
@@ -171,14 +204,12 @@ t_sensors *refresh_sensors(t_sensors *sensors)
...
@@ -171,14 +204,12 @@ 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
*
sensors
,
unsigned
shor
t
speed
)
void
set_fan_speed
(
t_sensors
*
sensors
,
in
t
speed
)
{
{
t_sensors
*
tmp
=
sensors
;
t_sensors
*
tmp
=
sensors
;
FILE
*
file
;
while
(
tmp
!=
NULL
)
{
while
(
tmp
!=
NULL
)
{
FILE
*
file
=
fopen
(
tmp
->
path
,
"rw"
);
file
=
fopen
(
tmp
->
fan_min_path
,
"rw+"
);
if
(
file
!=
NULL
)
{
if
(
file
!=
NULL
)
{
fprintf
(
file
,
"%d"
,
speed
);
fprintf
(
file
,
"%d"
,
speed
);
fclose
(
file
);
fclose
(
file
);
...
@@ -210,12 +241,12 @@ unsigned short get_temp(t_sensors* sensors)
...
@@ -210,12 +241,12 @@ unsigned short get_temp(t_sensors* sensors)
int
main
()
int
main
()
{
{
unsigned
shor
t
old_temp
,
new_temp
,
fan_speed
,
steps
;
in
t
old_temp
,
new_temp
,
fan_speed
,
steps
;
shor
t
temp_change
;
in
t
temp_change
;
floa
t
step_up
,
step_down
;
in
t
step_up
,
step_down
;
t_sensors
*
sensors
=
find_sensors
();
t_sensors
*
sensors
=
find_sensors
();
set_fans_man
(
sensors
);
new_temp
=
get_temp
(
sensors
);
new_temp
=
get_temp
(
sensors
);
fan_speed
=
2000
;
fan_speed
=
2000
;
set_fan_speed
(
sensors
,
fan_speed
);
set_fan_speed
(
sensors
,
fan_speed
);
...
...
src/mbpfan.h
View file @
0428dafb
/** Basic fan speed parameters
/** Basic fan speed parameters
*/
*/
extern
unsigned
shor
t
min_fan_speed
;
extern
in
t
min_fan_speed
;
extern
unsigned
shor
t
max_fan_speed
;
extern
in
t
max_fan_speed
;
/** Temperature Thresholds
/** Temperature Thresholds
* low_temp - temperature below which fan speed will be at minimum
* low_temp - temperature below which fan speed will be at minimum
* high_temp - fan will increase speed when higher than this temperature
* high_temp - fan will increase speed when higher than this temperature
* max_temp - fan will run at full speed above this temperature */
* max_temp - fan will run at full speed above this temperature */
extern
unsigned
shor
t
low_temp
;
extern
in
t
low_temp
;
extern
unsigned
shor
t
high_temp
;
extern
in
t
high_temp
;
extern
unsigned
shor
t
max_temp
;
extern
in
t
max_temp
;
/** Temperature polling interval
/** Temperature polling interval
* Default value was 10 (seconds)
* Default value was 10 (seconds)
*/
*/
extern
unsigned
shor
t
polling_interval
;
extern
in
t
polling_interval
;
/** Represents a Temperature sensor
/** Represents a Temperature sensor
*/
*/
...
@@ -28,6 +28,12 @@ typedef struct s_sensors t_sensors;
...
@@ -28,6 +28,12 @@ typedef struct s_sensors t_sensors;
*/
*/
t_sensors
*
find_sensors
();
t_sensors
*
find_sensors
();
/**
* Given a linked list of t_sensors, refresh their detected
* temperature
*/
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
...
@@ -35,7 +41,7 @@ t_sensors *find_sensors();
...
@@ -35,7 +41,7 @@ t_sensors *find_sensors();
void
find_fans
(
t_sensors
*
sensors
);
void
find_fans
(
t_sensors
*
sensors
);
/**
/**
* Given a li
nked list of t_sensors, refresh their detected
* Given a li
st of sensors with associated fans
*
temperature
*
Set them to manual control
*/
*/
t_sensors
*
refresh_sensors
(
t_sensors
*
sensors
);
void
set_fans_man
(
t_sensors
*
sensors
);
\ No newline at end of file
\ No newline at end of file
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