root/lm-sensors/branches/lm-sensors-3.0.0/prog/pwm/pwmconfig @ 5343

Revision 5343, 21.0 KB (checked in by khali, 5 years ago)

Add support for drivers that place the hwmon attributes in the hwmon
class device directory rather than directly in the device directory.
This is what virtual devices have.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/bin/bash
2#
3# pwmconfig
4# Tests the pwm outputs of sensors and configures fancontrol
5#
6#    Warning!!! This program will stop your fans, one at a time,
7#    for approximately 5 seconds each!!!
8#    This may cause your processor temperature to rise!!!
9#    Verify that all fans are running at normal speed after this
10#    program has exited!!!
11#
12#    Copyright (C) 2007-2008 Jean Delvare <khali@linux-fr.org>
13#
14#    This program is free software; you can redistribute it and/or modify
15#    it under the terms of the GNU General Public License as published by
16#    the Free Software Foundation; either version 2 of the License, or
17#    (at your option) any later version.
18#
19#    This program is distributed in the hope that it will be useful,
20#    but WITHOUT ANY WARRANTY; without even the implied warranty of
21#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22#    GNU General Public License for more details.
23#
24#    You should have received a copy of the GNU General Public License
25#    along with this program; if not, write to the Free Software
26#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27#    MA 02110-1301 USA.
28#
29#
30
31REVISION=$(echo '$Revision$' | cut -d' ' -f2)
32REVDATE=$(echo '$Date$' | cut -d' ' -f2)
33PIDFILE="/var/run/fancontrol.pid"
34
35if [ -f "$PIDFILE" ]
36then
37        echo "File $PIDFILE exists. This typically means that the"
38        echo "fancontrol deamon is running. You should stop it before running pwmconfig."
39        echo "If you are certain that fancontrol is not running, then you can delete"
40        echo "$PIDFILE manually."
41        exit 1
42fi
43
44echo "# pwmconfig revision $REVISION ($REVDATE)"
45echo 'This program will search your sensors for pulse width modulation (pwm)'
46echo 'controls, and test each one to see if it controls a fan on'
47echo 'your motherboard. Note that many motherboards do not have pwm'
48echo 'circuitry installed, even if your sensor chip supports pwm.'
49echo
50echo 'We will attempt to briefly stop each fan using the pwm controls.'
51echo 'The program will attempt to restore each fan to full speed'
52echo 'after testing. However, it is ** very important ** that you'
53echo 'physically verify that the fans have been to full speed'
54echo 'after the program has completed.'
55echo
56
57DELAY=5 # 3 seconds delay is too short for large fans, thus I increased it to 5
58MAX=255
59
60DIR=/proc/sys/dev/sensors
61if [ ! -d $DIR ]
62then
63        if [ -d "/sys/class/hwmon" ]
64        then
65                SYSFS=2
66                DIR="/sys/class/hwmon"
67        elif [ -d "/sys/bus/i2c/devices" ]
68        then
69                SYSFS=1
70                DIR="/sys/bus/i2c/devices"
71        else
72                echo $0: 'No sensors found! (modprobe sensor modules?)'
73                exit 1
74        fi
75fi
76
77cd $DIR
78if [ "$SYSFS" = "2" ]
79then
80        PREFIX='hwmon*'
81else
82        PREFIX='*-*'
83fi
84DEVICES=`echo $PREFIX`
85if [ "$PREFIX" = "$DEVICES" ]
86then
87        echo $0: 'No sensors found! (modprobe sensor modules?)'
88        exit 1
89fi
90
91# For sysfs, we may need to adjust the device path
92if [ "$SYSFS" = "2" ]
93then
94        OLD_DEVICES="$DEVICES"
95        DEVICES=""
96
97        for device in $OLD_DEVICES
98        do
99                if [ ! -r "$device/name" ]
100                then
101                        device="$device/device"
102                fi
103               
104                DEVICES="$DEVICES $device"
105        done
106fi
107
108
109for device in $DEVICES
110do
111        # Find available fan control outputs
112        MATCH=$device/'pwm[1-9]'
113        device_pwm=`echo $MATCH`
114        if [ "$SYSFS" = "1" -a "$MATCH" = "$device_pwm" ]
115        then
116                # Deprecated naming scheme (used in kernels 2.6.5 to 2.6.9)
117                MATCH=$device/'fan[1-9]_pwm'
118                device_pwm=`echo $MATCH`
119        fi
120        if [ "$MATCH" != "$device_pwm" ]
121        then
122                PWM="$PWM $device_pwm"
123        fi
124
125        # Find available fan monitoring inputs
126        if [ -n "$SYSFS" ]
127        then
128                MATCH=$device/'fan[1-9]_input'
129        else
130                MATCH=$device/'fan[1-9]'
131        fi
132        device_fan=`echo $MATCH`
133        if [ "$MATCH" != "$device_fan" ]
134        then
135                FAN="$FAN $device_fan"
136        fi
137done
138
139if [ -z "$PWM" ]
140then
141        echo $0: 'There are no pwm-capable sensor modules installed'
142        exit 1
143fi
144if [ -z "$FAN" ]
145then
146        echo $0: 'There are no fan-capable sensor modules installed'
147        exit 1
148fi
149
150# $1 = padding
151# Only works with Linux 2.6
152function print_devices()
153{
154        for device in $DEVICES
155        do
156                echo "$1$device is `cat $device/name`"
157        done
158}
159
160# $1 = pwm file name
161function is_pwm_auto()
162{
163        if [ -n "$SYSFS" ]
164        then
165                ENABLE=${1}_enable
166                if [ -f $ENABLE ]
167                then
168                        if [ "`cat $ENABLE`" -gt 1 ]
169                        then
170                                return 0
171                        fi
172                fi
173        fi
174
175        return 1
176}
177
178# $1 = pwm file name
179function pwmdisable()
180{
181        if [ -n "$SYSFS" ]
182        then
183                ENABLE=${1}_enable
184                # No enable file? Just set to max
185                if [ ! -f $ENABLE ]
186                then
187                        echo $MAX > $1
188                        return 0
189                fi
190
191                # Try pwmN_enable=0
192                echo 0 2>/dev/null > $ENABLE
193                if [ "`cat $ENABLE`" -eq 0 ]
194                then
195                        # Success
196                        return 0
197                fi
198
199                # It didn't work, try pwmN_enable=1 pwmN=255
200                echo 1 2>/dev/null > $ENABLE
201                if [ "`cat $ENABLE`" -ne 1 ]
202                then
203                        echo "$ENABLE stuck to `cat $ENABLE`" >&2
204                        return 1
205                fi
206
207                echo $MAX > $1
208                if [ "`cat $1`" -ge 190 ]
209                then
210                        # Success
211                        return 0
212                fi
213
214                # Nothing worked
215                echo "$1 stuck to `cat $1`" >&2
216                return 1
217        else
218                echo $MAX 0 > $1
219        fi
220}
221
222# $1 = pwm file name
223function pwmenable()
224{
225        if [ -n "$SYSFS" ]
226        then
227                ENABLE=${1}_enable
228                if [ -w $ENABLE ]
229                then
230                        echo 1 2>/dev/null > $ENABLE
231                        if [ $? -ne 0 ]
232                        then
233                                return 1
234                        fi
235                fi
236                echo $MAX > $1
237        else
238                echo $MAX 1 > $1
239        fi
240}
241
242# $1 = pwm file name; $2 = pwm value 0-255
243function pwmset()
244{
245        echo $2 > $1
246}
247
248if [ -n "$SYSFS" ]
249then
250        echo 'Found the following devices:'
251        print_devices "   "
252        echo
253fi
254
255echo 'Found the following PWM controls:'
256for i in $PWM
257do
258        echo "   $i"
259        if [ -w $i ]
260        then
261                # First check if PWM output is in automatic mode
262                if is_pwm_auto $i
263                then
264                        echo "$i is currently setup for automatic speed control."
265                        echo 'In general, automatic mode is preferred over manual mode, as'
266                        echo 'it is more efficient and it reacts faster. Are you sure that'
267                        echo -n 'you want to setup this output for manual control? (n) '
268                        read X
269                        if [ "$X" = "" -o "$X" != "y" -a "$X" != "Y" ]
270                        then
271                                continue
272                        fi
273                fi
274
275                pwmdisable $i
276                if [ $? -ne 0 ]
277                then
278                        echo "Manual control mode not supported, skipping $i."
279                elif [ "$GOODPWM" = "" ]
280                then
281                        GOODPWM=$i
282                else
283                        GOODPWM="$GOODPWM $i"
284                fi
285        else
286                NOTROOT=1
287        fi
288done
289
290if [ "$GOODPWM" = "" ]
291then
292        echo 'There are no usable PWM outputs.'
293        exit 1
294fi
295
296echo
297echo "Giving the fans some time to reach full speed..."
298sleep $DELAY
299echo 'Found the following fan sensors:'
300for i in $FAN
301do
302        # this will return the first field if there's only one (sysfs)
303        S=`cat $i | cut -d' ' -f2`
304        if [ "$S" = "0" -o "$S" = "-1" ]
305        then
306                echo "   $i     current speed: 0 ... skipping!"
307        else
308                echo "   $i     current speed: $S RPM"
309                if [ "$GOODFAN" = "" ]
310                then
311                        GOODFAN=$i
312                        SPEEDS=$S
313                else
314                        GOODFAN="$GOODFAN $i"
315                        SPEEDS="$SPEEDS $S"
316                fi
317        fi
318done
319echo
320
321if [ "$GOODFAN" = "" ]
322then
323        echo 'There are no working fan sensors, all readings are 0.'
324        echo 'Make sure you have a 3-wire fan connected.'
325        echo 'You may also need to increase the fan divisors.'
326        echo 'See doc/fan-divisors for more information.'
327        exit 1
328fi
329
330if [ "$NOTROOT" = "1" ]
331then
332        echo 'As you are not root, we cannot write the PWM settings.'
333        echo 'Please run as root to continue.'
334        exit 1
335fi
336
337echo 'Warning!!! This program will stop your fans, one at a time,'
338echo "for approximately $DELAY seconds each!!!"
339echo 'This may cause your processor temperature to rise!!!'
340echo 'If you do not want to do this hit control-C now!!!'
341echo -n 'Hit return to continue: '
342read X
343echo
344
345PLOTTER=gnuplot
346STEP=15
347PDELAY=2
348# Use a smaller step for low PWM values as this is typically where the
349# more important fan speed changes are happening.
350STEP2=2
351STEP2_BELOW=31
352
353function pwmdetail()
354{
355        P=$1
356        F=$2
357        PLOT=
358
359        type $PLOTTER > /dev/null 2>&1
360        if [ $? -eq 0 ]
361        then
362                echo -n "Would you like to generate a graphical plot using $PLOTTER (y)? "
363                read X
364                if [ "$X" = "y" -o "$X" = "Y" -o "$X" = "" ]
365                then
366                        PLOT=y
367                fi
368        else
369                if [ -n "$DISPLAY" ]
370                then
371                        echo "Note: If you had $PLOTTER installed, I could generate a graphical plot."
372                fi
373        fi
374
375        if [ "$PLOT" = "y" ]
376        then
377                TMP1=`mktemp -t pwmtest1.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1; }
378                TMP2=`mktemp -t pwmtest2.XXXXXXXXXX` || { rm -f $TMP1 ; echo "$0: Cannot create temporary file" >&2; exit 1; }
379                echo "set xlabel \"PWM: $P\"" > $TMP1
380                echo "set ylabel \"FAN: $F (RPM)\"" >> $TMP1
381                echo 'set nokey' >> $TMP1
382                echo 'set xrange [0:255]' >> $TMP1
383                echo "plot \"$TMP2\" with lines" >> $TMP1
384                echo 'pause -1 "    Hit return to continue..."' >> $TMP1
385                > $TMP2
386        fi
387
388        local threshold=100000
389        let pwm=$MAX
390        pwmenable $P
391        while [ $pwm -ge 0 ]
392        do
393                pwmset $P $pwm
394                sleep $PDELAY
395                if [ $? -ne 0 ]
396                then
397                        pwmdisable $P
398                        echo '^C received, aborting...'
399                        rm -f $TMP1 $TMP2
400                        exit 1
401                fi
402                # this will return the first field if there's only one (sysfs)
403                S=`cat $F | cut -d' ' -f2`
404                # Fan speed should never increase significantly
405                if [ $S -gt $threshold ]
406                then
407                        echo "    PWM $pwm FAN $S (probably incorrect)"
408                else
409                        echo "    PWM $pwm FAN $S"
410                        let threshold=S*6/5
411                fi
412
413                if [ "$PLOT" = "y" ]
414                then
415                        echo "$pwm $S" >> $TMP2
416                fi
417                if [ "$S" = "0" -o "$S" = "-1" ]
418                then
419                        pwmdisable $P
420                        echo "    Fan Stopped at PWM = $pwm"
421                        if [ $pwm -eq $MAX ]
422                        then
423                                echo "    This fan appears to stop when the PWM is enabled;"
424                                echo "    perhaps the fan input shares a pin with the PWM output"
425                                echo "    on the sensor chip."
426                                echo "    You cannot control this fan with this PWM output."
427                                rm -f $TMP1 $TMP2
428                                echo
429                                return 0
430                        fi
431                        break
432                fi
433                if [ $pwm -lt $STEP2_BELOW ]
434                then
435                        let pwm=$pwm-$STEP2
436                else
437                        let pwm=$pwm-$STEP
438                fi
439        done
440        pwmdisable $P
441        if [ "$PLOT" = "y" ]
442        then
443                $PLOTTER  $TMP1
444                rm -f $TMP1 $TMP2
445        fi
446        echo
447}
448
449for i in $GOODPWM
450do
451        echo Testing pwm control $i ...
452        pwmenable $i
453        if [ $? -ne 0 ]
454        then
455                echo "Manual control mode not supported, skipping."
456                continue
457        fi
458        pwmset $i 0
459        sleep $DELAY
460        if [ $? -ne 0 ]
461        then
462                pwmdisable $i
463                echo '^C received, restoring PWM and aborting...'
464                exit 1
465        fi
466        let pwmactivecount=0
467        let count=1
468        for j in $GOODFAN
469        do
470                OS=`echo $SPEEDS | cut -d' ' -f$count`
471                # this will return the first field if there's only one (sysfs)
472                S=`cat $j | cut -d' ' -f2`
473                echo "  $j ... speed was $OS now $S"
474                pwmdisable $i
475                let threshold=2*$OS/3
476                if [ $S -lt $threshold ]
477                then
478                        echo "    It appears that fan $j"
479                        echo "    is controlled by pwm $i"
480#
481# a PWM can control more than one fan....
482#
483                        if [ $pwmactivecount -eq 0 ]
484                        then
485                                let pwmactivecount=1
486                                pwmactive="$i ${pwmactive}"
487                                fanactive="$j ${fanactive}"
488                                fanactive_min="$S ${fanactive_min}"
489                        else
490                                fanactive="$j+${fanactive}" #not supported yet by fancontrol
491                                fanactive_min="$S+${fanactive_min}"
492                        fi
493                        sleep $DELAY
494                        if [ $? -ne 0 ]
495                        then
496                                echo '^C received, aborting...'
497                                exit 1
498                        fi
499                        # this will return the first field if there's only one (sysfs)
500                        S=`cat $j | cut -d' ' -f2`
501                        if [ $S -lt $threshold ]
502                        then
503                                echo "    Fan $j has not returned to speed, please investigate!"
504                        else
505                                echo -n "Would you like to generate a detailed correlation (y)? "
506                                read X
507                                if [ "$X" = "y" -o "$X" = "Y" -o "$X" = "" ]
508                                then
509                                        pwmdetail $i $j
510                                fi
511                        fi
512                else
513                        echo "    no correlation"
514                fi
515                let count=count+1
516        done
517        echo
518        if [ "$pwmactivecount" = "0" ]
519        then
520                echo "No correlations were detected."
521                echo "There is either no fan connected to the output of $i,"
522                echo "or the connected fan has no rpm-signal connected to one of"
523                echo "the tested fan sensors. (Note: not all motherboards have"
524                echo "the pwm outputs connected to the fan connectors,"
525                echo "check out the hardware database on http://www.almico.com/forumindex.php)"
526                echo
527                echo -n "Did you see/hear a fan stopping during the above test (n)? "
528                read X
529                if [ "$X" = "y" -o "$X" = "Y" ]
530                then
531                        pwmactive="$i ${pwmactive}"
532                fi
533                echo
534        fi
535done
536
537
538echo 'Testing is complete.'
539echo 'Please verify that all fans have returned to their normal speed.'
540echo
541echo 'The fancontrol script can automatically respond to temperature changes'
542echo 'of your system by changing fanspeeds.'
543echo -n 'Do you want to set up its configuration file now (y)? '
544
545read X
546if [ "$X" = "n" -o "$X" = "N" ]
547then
548        exit
549fi
550
551for device in $DEVICES
552do
553        # Find available temperature monitoring inputs
554        if [ -n "$SYSFS" ]
555        then
556                MATCH=$device/'temp[1-9]_input'
557        else
558                MATCH=$device/'temp[1-9]'
559        fi
560        device_temp=`echo $MATCH`
561        if [ "$MATCH" != "$device_temp" ]
562        then
563                TEMPS="$TEMPS $device_temp"
564        fi
565done
566
567if [ -z "$TEMPS" ]
568then
569        echo $0: 'There are no temperature-capable sensor modules installed'
570        exit 1
571fi
572
573function AskPath()
574{
575        echo -n 'What should be the path to your fancontrol config file (/etc/fancontrol)? '
576
577        read FCCONFIG
578        if [ "$FCCONFIG" = "" ]
579        then
580                FCCONFIG="/etc/fancontrol"
581        fi
582}
583
584AskPath
585
586function ClearConfig()
587{
588        FCTEMPS=""
589        FCFANS=""
590        MINTEMP=""
591        MAXTEMP=""
592        MINSTART=""
593        MINSTOP=""
594        MINPWM=""
595        MAXPWM=""
596}
597
598function LoadConfig()
599{
600        # Nothing to do
601        if [ ! -f "$1" ]
602        then
603                ClearConfig
604                return 0
605        fi
606
607        echo "Loading configuration from $1 ..."
608        INTERVAL=`egrep '^INTERVAL=.*$' $1 | sed -e 's/INTERVAL= *//g'`
609        FCTEMPS=`egrep '^FCTEMPS=.*$' $1 | sed -e 's/FCTEMPS= *//g'`
610        FCFANS=`egrep '^FCFANS=.*$' $1 | sed -e 's/FCFANS= *//g'`
611        MINTEMP=`egrep '^MINTEMP=.*$' $1 | sed -e 's/MINTEMP= *//g'`
612        MAXTEMP=`egrep '^MAXTEMP=.*$' $1 | sed -e 's/MAXTEMP= *//g'`
613        MINSTART=`egrep '^MINSTART=.*$' $1 | sed -e 's/MINSTART= *//g'`
614        MINSTOP=`egrep '^MINSTOP=.*$' $1 | sed -e 's/MINSTOP= *//g'`
615        MINPWM=`egrep '^MINPWM=.*$' $1 | sed -e 's/MINPWM= *//g'`
616        MAXPWM=`egrep '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM= *//g'`
617
618        # Check for configuration change
619        local item
620        for item in $FCFANS
621        do
622                if [ ! -f "`echo $item | sed -e 's/=.*$//'`" ]
623                then
624                        echo "Configuration appears to be outdated, discarded"
625                        ClearConfig
626                        return 0
627                fi
628        done
629}
630
631LoadConfig $FCCONFIG
632
633# $1 = pwm value below which the fan is stopped
634function TestMinStart()
635{
636        echo
637        echo 'Now we increase the PWM value in 10-unit-steps.'
638        echo 'Let the fan stop completely, then press return until the'
639        echo "fan starts spinning. Then enter 'y'."
640        echo 'We will use this value +20 as the starting speed.'
641        let fanok=0
642        let fanval="$1"
643
644        pwmenable $pwms
645        until [ "$fanok" = "1" ]
646        do
647                if [ $fanval -gt 240 ] ; then let fanval=$MAX ; let fanok=1 ; fi
648                echo -n "Setting $pwms to $fanval..."
649                pwmset $pwms $fanval
650                read FANTEST
651                if [ "$FANTEST" != "" ] ; then let fanok=1 ; fi
652                let fanval=fanval+10
653        done
654        pwmdisable $pwms
655
656        let fanval=fanval+20
657        if [ $fanval -gt 240 ] ; then let fanval=$MAX ; fi
658        echo "OK, using $fanval"
659}
660
661# $1 = fan input to read the fan speed from
662function TestMinStop()
663{
664        local faninput=$1
665        local threshold=100000
666        local fanspeed
667
668        echo
669        echo 'Now we decrease the PWM value to figure out the lowest usable value.'
670        echo 'We will use a slightly greater value as the minimum speed.'
671        let fanval=$MAX
672
673        pwmenable $pwms
674        while [ $fanval -ge 0 ]
675        do
676                pwmset $pwms $fanval
677                sleep $PDELAY
678                fanspeed=`cat $faninput | cut -d' ' -f2`
679                if [ $fanspeed -gt $threshold ]
680                then
681                        echo "    PWM $fanval -> $fanspeed RPM (probably incorrect)"
682                        break
683                else
684                        echo "    PWM $fanval -> $fanspeed RPM"
685                        if [ $fanspeed = "0" -o $fanspeed = "-1" ]
686                        then
687                                break
688                        fi
689                        let threshold=fanspeed*6/5
690                fi
691                if [ $fanval -lt $STEP2_BELOW ]
692                then
693                        let fanval=$fanval-$STEP2
694                else
695                        let fanval=$fanval-$STEP
696                fi
697        done
698        pwmdisable $pwms
699
700        if [ $fanval -lt $STEP2_BELOW ]
701        then
702                let 'fanval=fanval+2*STEP2'
703        else
704                let 'fanval=fanval+STEP'
705        fi
706        echo "OK, using $fanval"
707}
708
709function SaveConfig()
710{
711        echo
712        echo "Saving configuration to $FCCONFIG..."
713        tmpfile=`mktemp -t pwmcfg.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1;  }
714        trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15
715        echo "# Configuration file generated by pwmconfig, changes will be lost" >$tmpfile
716        echo -e "INTERVAL=$INTERVAL\nFCTEMPS=$FCTEMPS\nFCFANS=$FCFANS\nMINTEMP=$MINTEMP\nMAXTEMP=$MAXTEMP\nMINSTART=$MINSTART\nMINSTOP=$MINSTOP" >>$tmpfile
717        [ -n "$MINPWM" ] && echo "MINPWM=$MINPWM" >>$tmpfile
718        [ -n "$MAXPWM" ] && echo "MAXPWM=$MAXPWM" >>$tmpfile
719        mv $tmpfile $FCCONFIG
720        chmod +r $FCCONFIG
721        #check if file was written correctly
722        echo 'Configuration saved'
723}
724
725INTERVAL=10
726PS3='select (1-n): '
727DEFMINTEMP=20
728DEFMAXTEMP=60
729DEFMINSTART=150
730DEFMINSTOP=100
731
732function filter_cfgvar()
733{
734        echo "$1" | sed -e 's/ /\n/g' \
735                  | egrep "$2" \
736                  | sed -e 's/.*=//g'
737}
738
739# "select" won't repeat the list of options, so we enclose it in a
740# never-ending loop so that it starts over again with each iteration.
741# I admit it's not exactly nice, but I do not have a better idea to
742# keep usability at an acceptable level.
743while [ 1 ] ; do
744echo
745echo 'Select fan output to configure, or other action:'
746select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show configuration"; do
747        case $pwms in
748        "Change INTERVAL")
749                echo
750                echo "Current interval is $INTERVAL seconds."
751                echo -n "Enter the interval at which fancontrol should update PWM values (in s): "
752                read INTERVAL #check user input here
753                break ;;
754        "Just quit")
755                exit ;;
756        "Save and quit")
757                SaveConfig
758                exit ;;
759        "Show configuration")
760                echo
761                echo "Common Settings:"
762                echo "INTERVAL=$INTERVAL"
763                for pwmo in $pwmactive
764                do
765                        echo
766                        echo "Settings of ${pwmo}:"
767                        echo "  Depends on `filter_cfgvar "$FCTEMPS" "$pwmo"`"
768                        echo "  Controls `filter_cfgvar "$FCFANS" "$pwmo"`"
769                        echo "  MINTEMP=`filter_cfgvar "$MINTEMP" $pwmo`"
770                        echo "  MAXTEMP=`filter_cfgvar "$MAXTEMP" "$pwmo"`"
771                        echo "  MINSTART=`filter_cfgvar "$MINSTART" "$pwmo"`"
772                        echo "  MINSTOP=`filter_cfgvar "$MINSTOP" "$pwmo"`"
773                        XMINP=`filter_cfgvar "$MINPWM" "$pwmo"`
774                        [ -n "$XMINP" ] && echo "  MINPWM=$XMINP"
775                        XMAXP=`filter_cfgvar "$MAXPWM" "$pwmo"`
776                        [ -n "$XMAXP" ] && echo "  MAXPWM=$XMAXP"
777                done
778                echo
779                break ;;
780
781        "`echo ${pwmactive} |sed -e 's/ /\n/g' | egrep "${pwms}"`" )
782                pwmsed=`echo ${pwms} | sed -e 's/\//\\\\\//g'` #escape / for sed
783                echo
784                if [ -n "$SYSFS" ]
785                then
786                        echo 'Devices:'
787                        print_devices ""
788                        echo
789                fi
790                echo 'Current temperature readings are as follows:'
791                for j in $TEMPS
792                do
793                        # this will return the first field if there's only one (sysfs)
794                        S=`cat $j | cut -d' ' -f3`
795                        if [ -n "$SYSFS" ]
796                        then
797                                let S="$S / 1000"
798                        fi
799                        echo "$j        $S"
800                done
801                FAN=`echo $fanactive|cut -d' ' -f$REPLY`
802                FAN_MIN=`echo $fanactive_min|cut -d' ' -f$REPLY`
803                FCFANS="`echo $FCFANS | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=$FAN"
804                echo
805                echo "Select a temperature sensor as source for ${pwms}:"
806                select tempss in $TEMPS "None (Do not affect this PWM output)"; do
807                        if [ "$tempss" = "None (Do not affect this PWM output)" ]
808                        then
809
810                                break;
811                        else
812                                if [ "$FCTEMPS" = "" ]
813                                then
814                                        FCTEMPS="${pwms}=${tempss}"
815                                else
816                                        FCTEMPS="`echo $FCTEMPS | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${tempss}"
817                                fi
818                        fi
819                        echo
820                        echo 'Enter the low temperature (degree C)'
821                        echo -n "below which the fan should spin at minimum speed ($DEFMINTEMP): "
822                        read XMT
823                        if [ "$XMT" = "" ]
824                        then
825                                XMT=$DEFMINTEMP
826                        fi
827                        if [ "$MINTEMP" = "" ]
828                        then
829                                MINTEMP="${pwms}=${XMT}"
830                        else
831                                MINTEMP="`echo $MINTEMP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMT}"
832                        fi
833                        echo
834                        echo 'Enter the high temperature (degree C)'
835                        echo -n "over which the fan should spin at maximum speed ($DEFMAXTEMP): "
836                        read XMT
837                        if [ "$XMT" = "" ]
838                        then
839                                XMT=$DEFMAXTEMP
840                        fi
841                        if [ "$MAXTEMP" = "" ]
842                        then
843                                MAXTEMP="${pwms}=${XMT}"
844                        else
845                                MAXTEMP="`echo $MAXTEMP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMT}"
846                        fi
847
848                        if [ $FAN_MIN -eq 0 ]
849                        then
850                                echo
851                                echo "Enter the minimum PWM value (0-$MAX)"
852                                echo -n "at which the fan STOPS spinning (press t to test) ($DEFMINSTOP): "
853                                read XMSTOP
854
855                                if [ "$XMSTOP" = "" ]
856                                then
857                                        XMSTOP=$DEFMINSTOP
858                                fi
859                                if [ "$XMSTOP" = "t" -o "$XMSTOP" = "T" ]
860                                then
861                                        TestMinStop $FAN
862                                        XMSTOP=$fanval
863                                fi
864                        else
865                                XMSTOP=0
866                        fi
867                        if [ "$MINSTOP" = "" ]
868                        then
869                                MINSTOP="${pwms}=${XMSTOP}"
870                        else
871                                MINSTOP="`echo $MINSTOP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMSTOP}"
872                        fi
873
874                        if [ $FAN_MIN -eq 0 ]
875                        then
876                                echo
877                                echo "Enter the minimum PWM value ($XMSTOP-$MAX)"
878                                echo -n "at which the fan STARTS spinning (press t to test) ($DEFMINSTART): "
879                                read XMSTART
880
881                                if [ "$XMSTART" = "" ]
882                                then
883                                        XMSTART=$DEFMINSTART
884                                fi
885                                if [ "$XMSTART" = "t" -o "$XMSTART" = "T" ]
886                                then
887                                        TestMinStart $XMSTOP
888                                        XMSTART=$fanval
889                                fi
890                        else
891                                XMSTART=$DEFMINSTART
892                        fi
893                        if [ "$MINSTART" = "" ]
894                        then
895                                MINSTART="${pwms}=${XMSTART}"
896                        else
897                                MINSTART="`echo $MINSTART | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMSTART}"
898                        fi
899
900                        if [ $XMSTOP -gt 0 ]
901                        then
902                                echo
903                                echo "Enter the PWM value (0-$XMSTOP) to use when the temperature"
904                                echo -n "is below the low temperature limit (0): "
905                                read XMINP
906                        else
907                                XMINP=""
908                        fi
909                        if [ -n "$XMINP" ]
910                        then
911                                if [ "$MINPWM" = "" ]
912                                then
913                                        MINPWM="${pwms}=${XMINP}"
914                                else
915                                        MINPWM="`echo $MINPWM | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMINP}"
916                                fi
917                        fi
918                        echo
919                        echo "Enter the PWM value ($XMSTOP-$MAX) to use when the temperature"
920                        echo -n "is over the high temperature limit ($MAX): "
921                        read XMAXP
922                        if [ -n "$XMAXP" ]
923                        then
924                                if [ "$MAXPWM" = "" ]
925                                then
926                                        MAXPWM="${pwms}=${XMAXP}"
927                                else
928                                        MAXPWM="`echo $MAXPWM | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMAXP}"
929                                fi
930                        fi
931                        echo
932                        break;
933                done
934                break ;;
935
936        *)
937                echo "No such option. Enter a number."
938                break ;;
939        esac
940done
941done
Note: See TracBrowser for help on using the browser.