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
7d041128
Commit
7d041128
authored
Jan 25, 2012
by
Rafael Vega
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial Import
parents
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
237 additions
and
0 deletions
+237
-0
PKGBUILD
PKGBUILD
+23
-0
mbpfan.c
mbpfan.c
+147
-0
mbpfan.rc
mbpfan.rc
+67
-0
No files found.
PKGBUILD
0 → 100644
View file @
7d041128
# Maintainer: Allan McRae <allan@archlinux.org>
pkgname
=
mbpfan
pkgver
=
1.1
pkgrel
=
1
pkgdesc
=
"Automatically adjust the fan on a MacBook Pro"
arch
=(
'i686'
'x86_64'
)
license
=(
'GPL3'
)
source
=(
mbpfan.c
mbpfan.rc
)
md5sums
=(
'6febab2978d51dfe4c4ff550ace35fc2'
'6b58ce23ade4c2ccb8cadc004bb9e172'
)
build
()
{
cd
$srcdir
/
gcc
-o
mbpfan
-lm
-Wall
$CFLAGS
$LDFLAGS
mbpfan.c
}
package
()
{
install
-Dm755
$srcdir
/mbpfan
$pkgdir
/usr/bin/mbpfan
install
-Dm755
$srcdir
/mbpfan.rc
$pkgdir
/etc/rc.d/mbpfan
}
\ No newline at end of file
mbpfan.c
0 → 100644
View file @
7d041128
/*
* mbpfan.c - automatically control fan for MacBook Pro
* Copyright (C) 2010 Allan McRae <allan@archlinux.org>
* Modifications by Rafael Vega <rvega@elsoftwarehamuerto.org>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 20110811 - v1.1
*
* Notes:
* Uses only the temperatures from the processors as input.
* Assumes two processors and one fan.
* Requires coretemp and applesmc kernel modules to be loaded.
*
* Tested models:
* MacBook Pro 8.1 13" (Intel i7 - Linux 3.2)
*/
#include <math.h>
#include <stdio.h>
#include <unistd.h>
/* lazy min/max... */
#define min(a,b) a < b ? a : b
#define max(a,b) a > b ? a : b
/* basic fan speed parameters */
unsigned
short
min_fan_speed
=
2000
;
unsigned
short
max_fan_speed
=
6200
;
/* temperature thresholds
* low_temp - temperature below which fan speed will be at minimum
* high_temp - fan will increase speed when higher than this temperature
* max_temp - fan will run at full speed above this temperature */
unsigned
short
low_temp
=
63
;
unsigned
short
high_temp
=
66
;
unsigned
short
max_temp
=
86
;
/* unsigned short low_temp=55; */
/* unsigned short high_temp=65; */
/* unsigned short max_temp=80; */
/* temperature polling interval */
unsigned
short
polling_interval
=
10
;
/* Controls the speed of the fan */
void
set_fan_speed
(
unsigned
short
speed
)
{
FILE
*
file
;
file
=
fopen
(
"/sys/devices/platform/applesmc.768/fan1_min"
,
"w"
);
fprintf
(
file
,
"%d"
,
speed
);
fclose
(
file
);
}
/* Takes "manual" control of fan */
/* void prepare_fan() */
/* { */
/* FILE *file; */
/* */
/* file=fopen("/sys/devices/platform/applesmc.768/fan1_manual", "w"); */
/* fprintf(file, "%d", 1); */
/* fclose(file); */
/* } */
/* Returns average CPU temp in degrees (ceiling) */
unsigned
short
get_temp
()
{
FILE
*
file
;
unsigned
short
temp
;
unsigned
int
t0
,
t1
;
file
=
fopen
(
"/sys/devices/platform/coretemp.0/temp2_input"
,
"r"
);
fscanf
(
file
,
"%d"
,
&
t0
);
fclose
(
file
);
file
=
fopen
(
"/sys/devices/platform/coretemp.0/temp3_input"
,
"r"
);
fscanf
(
file
,
"%d"
,
&
t1
);
fclose
(
file
);
temp
=
(
unsigned
short
)(
ceil
((
float
)(
t0
+
t1
)
/
2000
.));
return
temp
;
}
int
main
()
{
unsigned
short
old_temp
,
new_temp
,
fan_speed
,
steps
;
short
temp_change
;
float
step_up
,
step_down
;
/* prepare_fan(); */
/* assume running on boot so set fan speed to minimum */
new_temp
=
get_temp
();
fan_speed
=
2000
;
set_fan_speed
(
fan_speed
);
sleep
(
polling_interval
);
step_up
=
(
float
)(
max_fan_speed
-
min_fan_speed
)
/
(
float
)((
max_temp
-
high_temp
)
*
(
max_temp
-
high_temp
+
1
)
/
2
);
step_down
=
(
float
)(
max_fan_speed
-
min_fan_speed
)
/
(
float
)((
max_temp
-
low_temp
)
*
(
max_temp
-
low_temp
+
1
)
/
2
);
while
(
1
)
{
old_temp
=
new_temp
;
new_temp
=
get_temp
();
if
(
new_temp
>=
max_temp
&&
fan_speed
!=
max_fan_speed
)
{
fan_speed
=
max_fan_speed
;
}
if
(
new_temp
<=
low_temp
&&
fan_speed
!=
min_fan_speed
)
{
fan_speed
=
min_fan_speed
;
}
temp_change
=
new_temp
-
old_temp
;
if
(
temp_change
>
0
&&
new_temp
>
high_temp
&&
new_temp
<
max_temp
)
{
steps
=
(
new_temp
-
high_temp
)
*
(
new_temp
-
high_temp
+
1
)
/
2
;
fan_speed
=
max
(
fan_speed
,
ceil
(
min_fan_speed
+
steps
*
step_up
));
}
if
(
temp_change
<
0
&&
new_temp
>
low_temp
&&
new_temp
<
max_temp
)
{
steps
=
(
max_temp
-
new_temp
)
*
(
max_temp
-
new_temp
+
1
)
/
2
;
fan_speed
=
min
(
fan_speed
,
floor
(
max_fan_speed
-
steps
*
step_down
));
}
set_fan_speed
(
fan_speed
);
sleep
(
polling_interval
);
}
return
0
;
}
mbpfan.rc
0 → 100644
View file @
7d041128
#!/bin/bash
daemon_name
=
mbpfan
.
/etc/rc.conf
.
/etc/rc.d/functions
get_pid
()
{
pidof
-o
%PPID
$daemon_name
}
case
"
$1
"
in
start
)
stat_busy
"Starting
$daemon_name
daemon"
PID
=
$(
get_pid
)
if
[
-z
"
$PID
"
]
;
then
[
-f
/var/run/
$daemon_name
.pid
]
&&
rm
-f
/var/run/
$daemon_name
.pid
# RUN
$daemon_name
&
#
if
[
$?
-gt
0
]
;
then
stat_fail
exit
1
else
echo
$(
get_pid
)
>
/var/run/
$daemon_name
.pid
add_daemon
$daemon_name
stat_done
fi
else
stat_fail
exit
1
fi
;;
stop
)
stat_busy
"Stopping
$daemon_name
daemon"
PID
=
$(
get_pid
)
# KILL
[
!
-z
"
$PID
"
]
&&
kill
$PID
&> /dev/null
#
if
[
$?
-gt
0
]
;
then
stat_fail
exit
1
else
rm
-f
/var/run/
$daemon_name
.pid &> /dev/null
rm_daemon
$daemon_name
stat_done
fi
;;
restart
)
$0
stop
sleep
3
$0
start
;;
status
)
stat_busy
"Checking
$daemon_name
status"
;
ck_status
$daemon_name
;;
*
)
echo
"usage:
$0
{start|stop|restart|status}"
esac
exit
0
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