Changeset 4437

Show
Ignore:
Timestamp:
06/10/07 14:36:44 (6 years ago)
Author:
khali
Message:

More cleanups to fancontrol:
* No longer depend on grep. We already depend on egrep so let's use it

everywhere.

* Don't depend on awk to compute the target PWM value. Bash has an arithmetic

expression evaluation engine which does the job just fine.

* Use read instead of cat to read the sensor values. read is built-in, so

it's cheaper.

* When sysfs is used (2.6 kernel), do not postproces the sensor value reads

with cut, as it is not needed.

* Update the dependency list.

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r4436 r4437  
    1616                   Fix Super-I/O exit sequence for Winbond/Fintek chips 
    1717  Program fancontrol: Use let for arithmetic evaluation 
     18                      No longer need awk and grep 
     19                      Limit calls to external programs (Linux 2.6 only) 
    1820  Program pwmconfig: Use smaller steps for low PWM values 
    1921  Program rrd: Support non-i2c devices (hwmon class) 
  • lm-sensors/trunk/prog/pwm/fancontrol

    r4436 r4437  
    33# Simple script implementing a temperature dependent fan speed control 
    44# 
    5 # Version 0.64 
     5# Version 0.65 
    66# 
    77# Usage: fancontrol [CONFIGFILE] 
    88# 
    99# Dependencies: 
    10 #   bash, awk, egrep, sed, lm_sensors :) 
     10#   bash, egrep, sed, cut, sleep, lm_sensors :) 
    1111# 
    1212# Please send any questions, comments or success stories to 
     
    105105then 
    106106        # For Linux 2.6, detect if config file uses the hwmon class or not yet 
    107         if echo "$AFCPWM[0]" | grep '^hwmon[0-9]' 
     107        if echo "${AFCPWM[0]}" | egrep -q '^hwmon[0-9]' 
    108108        then 
    109109                SDIR=/sys/class/hwmon 
     
    196196 
    197197trap restorefans SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL 
    198  
    199 # function doing all the math 
    200 function calc () { 
    201         awk "BEGIN { print $@ }" 
    202 } 
    203198 
    204199# main function 
     
    216211                minso=${AFCMINSTOP[$fcvcount]} 
    217212                 
    218                 tval=`cat ${tsens}` 
     213                read tval < ${tsens} 
    219214                if [ $? -ne 0 ] 
    220215                then 
     
    222217                        restorefans 
    223218                fi 
    224                 tval=`echo ${tval} |cut -d' ' -f3 |cut -d'.' -f1` 
    225219                if [ "$SYSFS" = "1" ] 
    226220                then 
    227                         let tval="$tval / 1000" 
    228                 fi 
    229  
    230                 pwmpval=`cat ${pwmo}` 
     221                        let tval="($tval+500)/1000" 
     222                else 
     223                        tval=`echo ${tval} | cut -d' ' -f3 | cut -d'.' -f1` 
     224                fi 
     225 
     226                read pwmpval < ${pwmo} 
    231227                if [ $? -ne 0 ] 
    232228                then 
     
    234230                        restorefans 
    235231                fi 
    236                 pwmpval=`echo ${pwmpval} | cut -d' ' -f1` 
     232                if [ "$SYSFS" != "1" ] 
     233                then 
     234                        pwmpval=`echo ${pwmpval} | cut -d' ' -f1` 
     235                fi 
    237236                 
    238237                # If fanspeed-sensor output shall be used, do it 
    239238                if [[ -n ${fan} ]] 
    240239                then 
    241                         fanval=`cat ${fan}` 
     240                        read fanval < ${fan} 
    242241                        if [ $? -ne 0 ] 
    243242                        then 
     
    245244                                restorefans 
    246245                        fi 
    247                         fanval=`echo ${fanval} | cut -d' ' -f2` 
     246                        if [ "$SYSFS" != "1" ] 
     247                        then 
     248                                fanval=`echo ${fanval} | cut -d' ' -f2` 
     249                        fi 
    248250                else 
    249251                        fanval=1  # set it to a non zero value, so the rest of the script still works 
     
    271273                else  
    272274                  # calculate the new value from temperature and settings 
    273                   pwmval=`calc "(((${tval}-${mint})/(${maxt}-${mint}))^2*(255-${minso})+${minso})" |cut -d'.' -f1` 
     275                  let pwmval="((${tval}-${mint})**2)*(255-${minso})/((${maxt}-${mint})**2)+${minso}" 
    274276                  if [ $pwmpval -eq 0 -o $fanval -eq 0 ] 
    275277                  then # if fan was stopped start it using a safe value