75 lines
1.2 KiB
Bash
Executable File
75 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
BASE_PATH=/sys/class
|
|
GPIO_PATH="$BASE_PATH"/gpio
|
|
PWM_PATH="$BASE_PATH"/pwm/pwmchip0
|
|
|
|
# GPIO pins
|
|
SATA0=26
|
|
SATA1=25
|
|
CPU_FAN=12
|
|
|
|
# Values
|
|
LOW=0
|
|
HIGH=1
|
|
|
|
export_pin() {
|
|
if [ ! -e $GPIO_PATH/gpio"$1" ]; then
|
|
echo "$1" >$GPIO_PATH/export
|
|
fi
|
|
}
|
|
|
|
unexport_pin() {
|
|
if [ -e $GPIO_PATH/gpio"$1" ]; then
|
|
echo "$1" >$GPIO_PATH/unexport
|
|
fi
|
|
}
|
|
|
|
set_gpio() {
|
|
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
|
|
}
|
|
|
|
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() {
|
|
enable_pwm_channel 1
|
|
if [ "$1" = "clean" ]; then
|
|
echo 0 >$PWM_PATH/unexport
|
|
fi
|
|
}
|
|
|
|
turn_on() {
|
|
set_gpio $SATA0 $HIGH
|
|
sleep 1
|
|
set_gpio $SATA1 $HIGH
|
|
set_gpio $CPU_FAN $HIGH
|
|
set_pwm
|
|
}
|
|
|
|
turn_off() {
|
|
set_gpio $SATA0 $LOW clean
|
|
set_gpio $SATA1 $LOW clean
|
|
set_gpio $CPU_FAN $LOW clean
|
|
set_pwm clean
|
|
}
|
|
|
|
trap turn_off INT
|
|
|
|
if [ "$1" = "on" ]; then
|
|
turn_on
|
|
else
|
|
turn_off
|
|
fi
|
|
|
|
exit 0
|