summaryrefslogtreecommitdiff
path: root/prog
diff options
context:
space:
mode:
authorKarol Szklarski <szklarskikarol@gmail.com>2019-01-26 22:12:15 +0100
committerKarol Szklarski <szklarskikarol@gmail.com>2019-01-26 22:12:15 +0100
commitb2039f04e19832d4d9aa9c11465a3014f32047ed (patch)
tree6ce7ad8eee283a8642493185e73a4619659117fd /prog
parenta60d30785e60e3ad9f56dd5aa1e6e10f23390c4e (diff)
downloadlm-sensors-git-b2039f04e19832d4d9aa9c11465a3014f32047ed.tar.gz
Adding AVERAGE option to fancontrol
Diffstat (limited to 'prog')
-rwxr-xr-xprog/pwm/fancontrol32
-rw-r--r--prog/pwm/fancontrol.85
2 files changed, 35 insertions, 2 deletions
diff --git a/prog/pwm/fancontrol b/prog/pwm/fancontrol
index 000a09be..44fdd116 100755
--- a/prog/pwm/fancontrol
+++ b/prog/pwm/fancontrol
@@ -67,6 +67,7 @@ function LoadConfig
FCFANS=$(grep -E '^FCFANS=.*$' $1 | sed -e 's/FCFANS=//g')
MINPWM=$(grep -E '^MINPWM=.*$' $1 | sed -e 's/MINPWM=//g')
MAXPWM=$(grep -E '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM=//g')
+ AVERAGE=$(grep -E '^AVERAGE=.*$' $1 | sed -e 's/AVERAGE=//g')
# Check whether all mandatory settings are set
if [[ -z ${INTERVAL} || -z ${FCTEMPS} || -z ${MINTEMP} || -z ${MAXTEMP} || -z ${MINSTART} || -z ${MINSTOP} ]]
@@ -107,6 +108,8 @@ function LoadConfig
[ -z "${AFCMINPWM[$fcvcount]}" ] && AFCMINPWM[$fcvcount]=0
AFCMAXPWM[$fcvcount]=$(echo $MAXPWM |sed -e 's/ /\n/g' |grep -E "${AFCPWM[$fcvcount]}" |cut -d'=' -f2)
[ -z "${AFCMAXPWM[$fcvcount]}" ] && AFCMAXPWM[$fcvcount]=255
+ AFCAVERAGE[$fcvcount]=$(echo $AVERAGE |sed -e 's/ /\n/g' |grep -E "${AFCPWM[$fcvcount]}" |cut -d'=' -f2)
+ [ -z "${AFCAVERAGE[$fcvcount]}" ] && AFCAVERAGE[$fcvcount]=1
# verify the validity of the settings
if [ "${AFCMINTEMP[$fcvcount]}" -ge "${AFCMAXTEMP[$fcvcount]}" ]
@@ -139,6 +142,13 @@ function LoadConfig
echo "MINPWM must be at least 0" >&2
exit 1
fi
+ if [ "${AFCAVERAGE[$fcvcount]}" -lt 1 ]
+ then
+ echo "Error in configuration file (${AFCPWM[$fcvcount]}):" >&2
+ echo "AVERAGE must be at least 1" >&2
+ exit 1
+ fi
+ declare -a PREVIOUSTEMP_$fcvcount
echo
echo "Settings for ${AFCPWM[$fcvcount]}:"
@@ -150,6 +160,7 @@ function LoadConfig
echo " MINSTOP=${AFCMINSTOP[$fcvcount]}"
echo " MINPWM=${AFCMINPWM[$fcvcount]}"
echo " MAXPWM=${AFCMAXPWM[$fcvcount]}"
+ echo " AVERAGE=${AFCAVERAGE[$fcvcount]}"
let fcvcount=fcvcount+1
done
echo
@@ -511,7 +522,7 @@ function UpdateFanSpeeds
{
local fcvcount
local pwmo tsens fan mint maxt minsa minso minpwm maxpwm
- local tval pwmpval fanval min_fanval one_fan one_fanval
+ local tval tlastval pwmpval fanval min_fanval one_fan one_fanval
local -i pwmval
let fcvcount=0
@@ -527,8 +538,9 @@ function UpdateFanSpeeds
minso=${AFCMINSTOP[$fcvcount]}
minpwm=${AFCMINPWM[$fcvcount]}
maxpwm=${AFCMAXPWM[$fcvcount]}
+ avg=${AFCAVERAGE[$fcvcount]}
- read tval < ${tsens}
+ read tlastval < ${tsens}
if [ $? -ne 0 ]
then
echo "Error reading temperature from $DIR/$tsens"
@@ -542,6 +554,20 @@ function UpdateFanSpeeds
restorefans 1
fi
+ # copy PREVIOUSTEMP_$fcvcount array to prevtemp
+ declare -a 'prevtemp=(${'"PREVIOUSTEMP_$fcvcount"'[@]})'
+ # add new element to the end of the array
+ prevtemp+=($tlastval)
+ # if needed, remove the first element of the array
+ if [ "${#prevtemp[@]}" -gt $avg ]
+ then
+ prevtemp=("${prevtemp[@]:1}")
+ fi
+ # calculate the average value of all elements
+ tval=$(( ( ${prevtemp[@]/%/+}0 ) / ${#prevtemp[@]} ))
+ # copy prevtemp back to PREVIOUSTEMP_$fcvcount
+ eval "PREVIOUSTEMP_$fcvcount=(\"${prevtemp[@]}\")"
+
# If fanspeed-sensor output shall be used, do it
if [[ -n ${fan} ]]
then
@@ -586,6 +612,8 @@ function UpdateFanSpeeds
echo "minso=$minso"
echo "minpwm=$minpwm"
echo "maxpwm=$maxpwm"
+ echo "tlastval=$tlastval"
+ echo "prevtemp=${prevtemp[@]}"
echo "tval=$tval"
echo "pwmpval=$pwmpval"
echo "fanval=$fanval"
diff --git a/prog/pwm/fancontrol.8 b/prog/pwm/fancontrol.8
index 98fc5e59..43325903 100644
--- a/prog/pwm/fancontrol.8
+++ b/prog/pwm/fancontrol.8
@@ -80,6 +80,11 @@ If this value isn't defined, it defaults to 0 (stopped fan).
.B MAXPWM
The PWM value to use when the temperature is over MAXTEMP.
If this value isn't defined, it defaults to 255 (full speed).
+.TP
+.B AVERAGE
+How many last temperature readings are used to average the temperature.
+It can be used to smoothen short temperature peaks.
+If this value isn't defined, it defaults to 1 (no averaging).
.PP
The configuration file format is a bit strange:
.IP