Changeset 2187
- Timestamp:
- 12/20/03 19:40:39 (9 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/prog/pwm/pwmconfig (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/prog/pwm/pwmconfig
r2178 r2187 1 1 #!/bin/bash 2 2 # 3 # pwmconfig v0. 63 # pwmconfig v0.7 4 4 # Tests the pwm outputs of sensors and configures fancontrol 5 5 # … … 40 40 41 41 DELAY=5 # 3 seconds delay is too short for large fans, thus I increased it to 5 42 MAX=255 42 43 43 44 DIR=/proc/sys/dev/sensors 45 SDIR=/sys/bus/i2c/devices 44 46 if [ ! -d $DIR ] 45 47 then 46 echo $0: 'No sensors found! (modprobe sensor modules?)' 47 exit 1 48 if [ ! -d $SDIR ] 49 then 50 echo $0: 'No sensors found! (modprobe sensor modules?)' 51 exit 1 52 else 53 SYSFS=1 54 DIR=$SDIR 55 fi 48 56 fi 49 57 … … 56 64 fi 57 65 58 PWM=`echo */pwm *`59 if [ "*/pwm *" = "$PWM" ]66 PWM=`echo */pwm[1-9]` 67 if [ "*/pwm[1-9]" = "$PWM" ] 60 68 then 61 69 echo $0: 'There are no pwm-capable sensor modules installed' … … 63 71 fi 64 72 65 FAN=`echo */fan[1-9]` 66 if [ "*/fan[1-9]" = "$FAN" ] 73 if [ "$SYSFS" = "1" ] 74 then 75 MATCH='*/fan_input[1-9]' 76 else 77 MATCH='*/fan[1-9]' 78 fi 79 FAN=`echo $MATCH` 80 if [ "$MATCH" = "$FAN" ] 67 81 then 68 82 echo $0: 'There are no fan-capable sensor modules installed' 69 83 exit 1 70 84 fi 85 86 function pwmdisable() 87 { 88 if [ "$SYSFS" = "1" ] 89 then 90 echo $MAX > $1 91 ENABLE=${1/pwm/pwm_enable} 92 if [ -f $ENABLE ] 93 then 94 echo 0 > $ENABLE 95 fi 96 else 97 echo $MAX 0 > $1 98 fi 99 } 100 101 function pwmenable() 102 { 103 if [ "$SYSFS" = "1" ] 104 then 105 ENABLE=${1/pwm/pwm_enable} 106 if [ -f $ENABLE ] 107 then 108 echo 1 > $ENABLE 109 fi 110 else 111 echo $MAX 1 > $1 112 fi 113 } 114 115 function pwmset() 116 { 117 echo $2 > $1 118 } 71 119 72 120 echo 'Found the following PWM controls:' … … 76 124 if [ -w $i ] 77 125 then 78 echo 255 0 >$i126 pwmdisable $i 79 127 else 80 128 NOTROOT=1 … … 86 134 for i in $FAN 87 135 do 136 # this will return the first field if there's only one (sysfs) 88 137 S=`cat $i | cut -d' ' -f2` 89 138 if [ "$S" = "0" -o "$S" = "-1" ] … … 162 211 fi 163 212 164 let pwm=255 213 let pwm=$MAX 214 pwmenable $P 165 215 while [ $pwm -ge 0 ] 166 216 do 167 echo $pwm 1 > $P 168 S=`cat $F | cut -d' ' -f2` 169 echo " PWM $pwm FAN $S" 170 if [ "$PLOT" = "y" ] 171 then 172 echo "$pwm $S" >> $TMP2 173 fi 174 if [ "$S" = "0" -o "S" = "-1" ] 175 then 176 echo 255 0 > $P 177 echo " Fan Stopped at PWM = $pwm" 178 if [ $pwm -eq 255 ] 179 then 180 echo " This fan appears to stop when the PWM is enabled;" 181 echo " perhaps the fan input shares a pin with the PWM output" 182 echo " on the sensor chip." 183 rm -f $TMP1 $TMP2 184 echo 185 return 0 186 fi 187 break 188 fi 189 let pwm=$pwm-$STEP 217 pwmset $P $pwm 190 218 sleep $PDELAY 191 219 if [ $? -ne 0 ] 192 220 then 193 echo 255 0 >$P221 pwmdisable $P 194 222 echo '^C received, aborting...' 195 223 rm -f $TMP1 $TMP2 196 224 exit 1 197 225 fi 226 # this will return the first field if there's only one (sysfs) 227 S=`cat $F | cut -d' ' -f2` 228 echo " PWM $pwm FAN $S" 229 if [ "$PLOT" = "y" ] 230 then 231 echo "$pwm $S" >> $TMP2 232 fi 233 if [ "$S" = "0" -o "S" = "-1" ] 234 then 235 pwmdisable $P 236 echo " Fan Stopped at PWM = $pwm" 237 if [ $pwm -eq $MAX ] 238 then 239 echo " This fan appears to stop when the PWM is enabled;" 240 echo " perhaps the fan input shares a pin with the PWM output" 241 echo " on the sensor chip." 242 echo " You cannot control this fan with this PWM output." 243 rm -f $TMP1 $TMP2 244 echo 245 return 0 246 fi 247 break 248 fi 249 let pwm=$pwm-$STEP 198 250 done 199 echo 255 0 >$P251 pwmdisable $P 200 252 if [ "$PLOT" = "y" ] 201 253 then … … 209 261 do 210 262 echo Testing pwm control $i ... 211 echo 0 1 > $i 263 pwmenable $i 264 pwmset $i 0 212 265 sleep $DELAY 213 266 if [ $? -ne 0 ] 214 267 then 215 echo 255 0 >$i268 pwmdisable $i 216 269 echo '^C received, restoring PWM and aborting...' 217 270 exit 1 … … 222 275 do 223 276 OS=`echo $SPEEDS | cut -d' ' -f$count` 277 # this will return the first field if there's only one (sysfs) 224 278 S=`cat $j | cut -d' ' -f2` 225 279 echo " $j ... speed was $OS now $S" 226 echo 255 0 >$i280 pwmdisable $i 227 281 let threshold=2*$OS/3 228 282 if [ $S -lt $threshold ] … … 244 298 exit 1 245 299 fi 300 # this will return the first field if there's only one (sysfs) 246 301 S=`cat $j | cut -d' ' -f2` 247 302 if [ $S -lt $threshold ] … … 295 350 fi 296 351 297 TEMPS=`echo */temp[1-9]` 298 if [ "*/temp[0-9]*" = "$TEMPS" ] 352 if [ "$SYSFS" = "1" ] 353 then 354 MATCH='*/temp_input[1-9]' 355 else 356 MATCH='*/temp[1-9]' 357 fi 358 TEMPS=`echo $MATCH` 359 if [ "$MATCH" = "$TEMPS" ] 299 360 then 300 361 echo $0: 'There are no temperature-capable sensor modules installed' … … 353 414 do 354 415 let fanval=fanval+10 355 if [ $fanval -gt 240 ] ; then let fanval= 255; let fanok=1 ; fi416 if [ $fanval -gt 240 ] ; then let fanval=$MAX ; let fanok=1 ; fi 356 417 echo -n "Setting $pwms to $fanval..." 357 418 echo $fanval > $pwms … … 360 421 done 361 422 let fanval=fanval+20 362 if [ $fanval -gt 240 ] ; then let fanval= 255; fi423 if [ $fanval -gt 240 ] ; then let fanval=$MAX ; fi 363 424 echo "OK, using $fanval" 364 echo 255> $pwms425 echo $MAX > $pwms 365 426 } 366 427 … … 372 433 echo 'We will use this value +20 as the minimum speed.' 373 434 let fanok=0 374 let fanval= 255435 let fanval=$MAX 375 436 until [ "$fanok" = "1" ] 376 437 do … … 383 444 done 384 445 let fanval=fanval+20 385 if [ $fanval -gt 255 ] ; then let fanval=255; fi446 if [ $fanval -gt $MAX ] ; then let fanval=$MAX ; fi 386 447 echo "OK, using $fanval" 387 echo 255> $pwms448 echo $MAX > $pwms 388 449 } 389 450 … … 445 506 for j in $TEMPS 446 507 do 508 # this will return the first field if there's only one (sysfs) 447 509 S=`cat $j | cut -d' ' -f3` 510 if [ "$SYSFS" = "1" ] 511 then 512 let S="$S / 1000" 513 fi 448 514 echo "$j $S" 449 515 done … … 458 524 if [ "$FCTEMPS" = "" ] 459 525 then 460 FCTEMPS="${pwms}= >${tempss}"526 FCTEMPS="${pwms}=${tempss}" 461 527 else 462 528 FCTEMPS="`echo $FCTEMPS | sed -e "s/${pwmsed}[^ ]* *//g\"` ${pwms}=${tempss}" … … 473 539 if [ "$MINTEMP" = "" ] 474 540 then 475 MINTEMP="${pwms}= >${XMT}"541 MINTEMP="${pwms}=${XMT}" 476 542 else 477 543 MINTEMP="`echo $MINTEMP | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMT}" … … 487 553 if [ "$MAXTEMP" = "" ] 488 554 then 489 MAXTEMP="${pwms}= >${XMT}"555 MAXTEMP="${pwms}=${XMT}" 490 556 else 491 557 MAXTEMP="`echo $MAXTEMP | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMT}" 492 558 fi 493 559 echo 494 echo 'Enter the minimum PWM value (0-255)'560 echo "Enter the minimum PWM value (0-$MAX)" 495 561 echo -n "at which the fan STARTS spinning (press t to test) ($DEFMINSTART): " 496 562 read XMV … … 506 572 if [ "$MINSTART" = "" ] 507 573 then 508 MINSTART="${pwms}= >${XMV}"574 MINSTART="${pwms}=${XMV}" 509 575 else 510 576 MINSTART="`echo $MINSTART | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMV}" 511 577 fi 512 578 echo 513 echo 'Enter the minimum PWM value (0-255)'579 echo "Enter the minimum PWM value (0-$MAX)" 514 580 echo -n "at which the fan STOPS spinning (press t to test) ($DEFMINSTOP): " 515 581 read XMV … … 525 591 if [ "$MINSTOP" = "" ] 526 592 then 527 MINSTOP="${pwms}= >${XMV}"593 MINSTOP="${pwms}=${XMV}" 528 594 else 529 595 MINSTOP="`echo $MINSTOP | sed -e \"s/${pwmsed}[^ ]* *//g\"` ${pwms}=${XMV}"
