#!/usr/bin/perl # # Original Version # ---------------- # http://www.Linux-1U.net/LCD/scripts/lcd-sensors.pl # # #--------------------------------------- # lcd-sensors.pl # # read sensor data from /proc/sys/dev/sensors/*/* # convert units and display to Orbital Matrix LCD # (on ttyS1) and to the console # written by Ray Olszewski # begun February 4, 2000 # this version current as of February 6, 2000 #--------------------------------------- # filenames and other constants ----------------------- $sleeptime = 3 ; $sensorpath = "/proc/sys/dev/sensors/w83627hf-isa-0290/" ; @sensornames = ( "in0","in1","in2","in3","in4","in5", "in6","in7","in8","fan1","fan2","fan3", "temp1","temp2","temp3" ) ; @sensorlabels = ( "VCore1","Vcore2","+3.3V","+5V", "+12V","-12V","-5V","V5SB","VBat", "CPU fan","case fan","backup fan", "case temp","CPU temp","other temp" ) ; # the LCD stuff ---------------------------------------- # set up the serial port for output system ("stty 19200 /dev/ttyS1") ; # the special LCD codes (for the Orbital Matrix display/controller) $lcdcmd = "\xFE" ; $wrapon = $lcdcmd."C" ; $wrapoff = $lcdcmd."D" ; $scrollon = $wrapon."Q" ; $scrolloff = $lcdcmd."R" ; $blinkon = $lcdcmd."S" ; $blinkoff = $lcdcmd."T" ; $cls = $lcdcmd."X" ; $cursoron = $lcdcmd."J" ; $cursoroff = $lcdcmd."K" ; $cursorleft = $lcdcmd."L" ; $cursorright = $lcdcmd."M" ; $cursorhome = $lcdcmd."H" ; $gotoxy = $lcdcmd."G" ; # follow by column-number row-number # stuff for custom characters (to be added later) # the main program ----------------------------------------- $whichone = 0 ; # set the LCD to line wrap print LCDOUT "$wrapon" ; while ( 1 ) { open (READING,"$sensorpath/$sensornames[$whichone]") ; $rawvalue = ; close READING ; @pieces = split(/ /,$rawvalue) ; $dispvalue = "" ; # now do sensor-specific scaling and settings # conversion rules taken from /etc/sensors.conf values # for the w83627 chip -- accuracy not guaranteed by me (RO) if ( $whichone == 0 ) { $dispvalue = 1 * @pieces[2] ; } elsif ( $whichone == 1 ) { $dispvalue = 1 * @pieces[2] ; } elsif ( $whichone == 2 ) { $dispvalue = 1 * @pieces[2] ; } elsif ( $whichone == 3 ) { $dispvalue = @pieces[2] * ( ( 6.8 / 10 ) + 1 ) ; } elsif ( $whichone == 4 ) { $dispvalue = @pieces[2] * ( ( 28 / 10 ) + 1 ) ; } elsif ( $whichone == 5 ) { $dispvalue = ( @pieces[2] * 5.14 ) - 14.91 ; } elsif ( $whichone == 6 ) { $dispvalue = ( @pieces[2] * 3.14 ) - 7.71 ; } elsif ( $whichone == 7 ) { $dispvalue = @pieces[2] * ( ( 6.8 / 10 ) + 1 ) ; } elsif ( $whichone == 8 ) { $dispvalue = 1 * @pieces[2] ; } # fix later # this is the fan group elsif ( $whichone == 9 || $whichone == 10 || $whichone == 11 ) { $dispvalue = 1 * @pieces[1] ; } # this is the temperature group elsif ( $whichone == 12 || $whichone == 13 || $whichone == 14 ) { @pieces[3] = @pieces[2] * ( 9 / 5 ) + 32 ; @pieces[2] = 1 * @pieces[2] ; $dispvalue = @pieces[2]." C -- ".@pieces[3]." F" ; } else { $dispvalue = "****ERROR****" ; } ; print LCDOUT "$sensorlabels[$whichone]: $dispvalue\n" ; print "$whichone $sensorlabels[$whichone]: $dispvalue \n" ; $whichone = ( $whichone + 1 ) % 15 ; sleep $sleeptime ; } ; # should never get here print LCDOUT " EXITING PROGRAM\n" ; print "EXITING PROGRAM\N" ; close LCDOUT ; # EOP -----------------------------------------------