2021-05-15 16:51:46 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-07-28 12:48:03 +02:00
|
|
|
BASE_PATH=/sys/class
|
|
|
|
GPIO_PATH="$BASE_PATH"/gpio
|
2022-05-16 23:30:06 +02:00
|
|
|
PWM_PATH="$BASE_PATH"/pwm/pwmchip0
|
2021-05-15 16:51:46 +02:00
|
|
|
|
|
|
|
# GPIO pins
|
|
|
|
CPU_FAN=12
|
2023-12-12 14:58:06 +01:00
|
|
|
HDD_FAN=13
|
2021-05-15 16:51:46 +02:00
|
|
|
|
|
|
|
# Values
|
|
|
|
LOW=0
|
|
|
|
HIGH=1
|
|
|
|
|
|
|
|
export_pin() {
|
2021-07-28 12:48:03 +02:00
|
|
|
if [ ! -e $GPIO_PATH/gpio"$1" ]; then
|
|
|
|
echo "$1" >$GPIO_PATH/export
|
|
|
|
fi
|
2021-05-15 16:51:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unexport_pin() {
|
2021-07-28 12:48:03 +02:00
|
|
|
if [ -e $GPIO_PATH/gpio"$1" ]; then
|
|
|
|
echo "$1" >$GPIO_PATH/unexport
|
|
|
|
fi
|
2021-05-15 16:51:46 +02:00
|
|
|
}
|
|
|
|
|
2022-05-16 23:30:06 +02:00
|
|
|
set_gpio() {
|
2021-07-28 12:48:03 +02:00
|
|
|
export_pin "$1"
|
|
|
|
echo "out" >$GPIO_PATH/gpio"$1"/direction
|
|
|
|
echo "$2" >$GPIO_PATH/gpio"$1"/value
|
|
|
|
if [ "$3" = "clean" ]; then
|
|
|
|
unexport_pin "$1"
|
|
|
|
fi
|
2021-05-15 16:51:46 +02:00
|
|
|
}
|
|
|
|
|
2022-05-16 23:30:06 +02:00
|
|
|
enable_pwm_channel() {
|
|
|
|
echo "$1" >$PWM_PATH/export
|
|
|
|
echo 40000 >$PWM_PATH/pwm"$1"/period
|
|
|
|
echo 30000 >$PWM_PATH/pwm"$1"/duty_cycle
|
|
|
|
echo 1 >$PWM_PATH/pwm"$1"/enable
|
|
|
|
}
|
|
|
|
|
|
|
|
set_pwm() {
|
|
|
|
if [ "$1" = "clean" ]; then
|
2022-07-05 17:47:24 +02:00
|
|
|
echo 1 >$PWM_PATH/unexport
|
2023-01-02 12:41:43 +01:00
|
|
|
else
|
|
|
|
enable_pwm_channel 1
|
2022-05-16 23:30:06 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-05-15 16:51:46 +02:00
|
|
|
turn_on() {
|
2022-05-16 23:30:06 +02:00
|
|
|
set_gpio $CPU_FAN $HIGH
|
2023-12-12 14:58:06 +01:00
|
|
|
set_gpio $HDD_FAN $HIGH
|
2022-05-16 23:30:06 +02:00
|
|
|
set_pwm
|
2021-05-15 16:51:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
turn_off() {
|
2022-05-16 23:30:06 +02:00
|
|
|
set_gpio $CPU_FAN $LOW clean
|
2023-12-12 14:58:06 +01:00
|
|
|
set_gpio $HDD_FAN $LOW clean
|
2022-05-16 23:30:06 +02:00
|
|
|
set_pwm clean
|
2021-05-15 16:51:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
trap turn_off INT
|
|
|
|
|
|
|
|
if [ "$1" = "on" ]; then
|
2021-07-28 12:48:03 +02:00
|
|
|
turn_on
|
2021-05-15 16:51:46 +02:00
|
|
|
else
|
2021-07-28 12:48:03 +02:00
|
|
|
turn_off
|
2021-05-15 16:51:46 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|