distribution/projects/Rockchip/packages/system-utils/sources/fancontrol

38 lines
1.1 KiB
Text
Raw Normal View History

2022-02-05 14:23:32 +00:00
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2021-present Fewtarius (https://github.com/fewtarius)
. /etc/profile
if [ -e "/storage/.config/fancontrol.conf" ]
then
2022-02-06 11:40:01 +00:00
$DEBUG && echo "Loading configuration file" 2>/dev/null
2022-02-05 14:23:32 +00:00
source /storage/.config/fancontrol.conf
else
2022-02-06 11:40:01 +00:00
$DEBUG && echo "Configuration not found, loading defaults" 2>/dev/null
2022-02-05 14:23:32 +00:00
FAN_PWM="${DEVICE_PWM_FAN}"
SPEEDS=(255 127 85 0)
TEMPS=(75000 65000 55000 0)
fi
while true
do
INDEX=0
CPU_TEMP=$(printf "%.0f" $(cat /sys/devices/virtual/thermal/thermal_zone*/temp | awk '{ total += $1; count++ } END { print total/count }'))
2022-02-06 11:38:51 +00:00
$DEBUG && echo "CPU TEMP: ${CPU_TEMP}" 2>/dev/null
2022-02-05 14:23:32 +00:00
for TEMP in "${TEMPS[@]}"
do
2022-02-06 11:38:51 +00:00
$DEBUG && echo "INDEX: ${INDEX}" 2>/dev/null
$DEBUG && echo "CHK: ${TEMP}" 2>/dev/null
2022-02-05 14:23:32 +00:00
if (( "${CPU_TEMP}" > "${TEMP}" ))
then
2022-02-06 11:38:51 +00:00
$DEBUG && echo "Setting PWM FAN to ${SPEEDS[${INDEX}]} (${TEMP})" 2>/dev/null
2022-02-05 14:23:32 +00:00
echo ${SPEEDS[${INDEX}]} >${FAN_PWM}
break
fi
INDEX=$(( $INDEX + 1 ))
done
sleep 2
2022-02-06 11:38:51 +00:00
$DEBUG && echo "Loop" 2>/dev/null
2022-02-05 14:23:32 +00:00
done