#!/usr/bin/perl -w # #--------------------------------------- # # test_lcd.pl display stuff to the LCD # # http://Linux-1U.net/LCD/scripts/test_lcd.20050307.pl # http://Linux-1U.net/LCD/scripts/test_lcd.20050320.c # http://Linux-1U.net/LCD/scripts/test_lcd.USB-LCD-HOWTO.txt # # # 07-Jul-00 amo Date-of-Birth ( stolen from record_sensors.pl ) # 12-Mar-01 amo Fixed ip# # 20-Apr-01 amo Use ifconfig instead ( os independent ) # 30-Jan-05 amo Use LCDATA, "\n" is needed, use 16char string to print to the lcd, rename to lcd_text() # 07-Mar-05 amo Added substr() # 20-Mar-05 amo Added /dev/ttyUSB0 for USB-LCD # # # #--------------------------------------- # # which serial port is the display attached to # #y ( $SERIALPORT ) = "/dev/ttyS0"; my ( $SERIALPORT ) = "/dev/ttyS1"; # # #y ( $SERIALPORT ) = "/dev/ttyUSB0"; # # end of User Changes... # # ------------------------------------------- # # # Get some info about the hosts # ----------------------------- # my ( $VER ) = "20050320"; my ( $NM ) = "test_lcd-$VER.pl"; # # my ( $host ) = `hostname -s`; chomp ( $host ); # my ( $dom ) = `hostname -d`; chomp ( $dom ); # # # my ( @route ) = split ( /\s+/, `route -nv | grep 166 | grep UH ` ); # my ( $ip ) = $route[0]; # #y ( @ipaddr ) = split ( /=/, `grep -i ^ipaddr /etc/sysconfig/network-scripts/ifcfg-eth0 ` ); # # inet addr:166.90.172.11 Bcast:166.90.172.255 Mask:255.255.255.0 my ( @ipaddr ) = split ( /:/, `ifconfig -v | grep -i "inet addr" | grep -v 127.0.0 ` ); my ( $ip ) = split ( /\s+/, $ipaddr[1] ); chomp ( $ip ); # #y ( $pid ) = ` ps auxw | grep $NM | cut -d ' ' -f 8 `; # my ( $str ) = ` ps auxw | grep $NM `; my ( $x_y, $pid, @foo ) = split ( /\s+/, $str ); # # # ------------------------------- # Rotate among the 16x2 LCD data # ------------------------------- # # 30-Jan-05 amo Use LCDATA, "\n" is needed, use 16char string to print to the lcd # my ( $width ) = 16; # left justify ( ljust() ) # my ( @LCDATA ) = (); # $LCDATA[0] = ""; # empty $LCDATA[1] = sprintf ( "%*s", -$width, $NM ); $LCDATA[2] = sprintf ( "%*s", -$width, $pid ); $LCDATA[3] = sprintf ( "%*s", -$width, $host ); $LCDATA[4] = sprintf ( "%*s", -$width, $dom ); $LCDATA[5] = sprintf ( "%*s", -$width, $ip ); $LCDATA[6] = sprintf ( "%*s", -$width, "192.168.1.1" ); # # # Show Something on the LCD # -------------------------- # &lcd_text ; # exit ; # # --------------------------------------------- # sub lcd_text { # # info dumped to the screen # print "\n"; print "$NM: LCD on serial port=$SERIALPORT..pid=$pid..\n"; print "\n"; # # # set up the serial port for output # SE board can be set to 2400 or 9600 bps # #ystem ( "stty 2400 <$SERIALPORT" ); system ( "stty 9600 <$SERIALPORT" ); #ystem ( "stty 19200 <$SERIALPORT" ); # # open ( LCDOUT, "> $SERIALPORT"); # # # LCD codes for this serial piggie back adapter # ============================================= # # 1 0x01 clear # 2 0x02 home # 128 0x80 line1 # 192 0xC0 line2 # 254 0xFE cmd # my ( $lcdcmd ) = "\xFE"; # general command prefix # my ( $cls ) = $lcdcmd."\x01" ; # clear display # my ( $cursorhome ) = $lcdcmd."\x02" ; # my ( $line1 ) = $lcdcmd."\x80"; my ( $line2 ) = $lcdcmd."\xC0"; # # my ( $r ) = 1; # first row of lcd data my ( $s ) = 1; # while ( 1 ) { # $s = $r; $s += 1; # # lcd data - left-justified # # $rs = $LCDATA[$r]; # $ss = $LCDATA[$s]; # # 07-Mar-05 amo Added substr() # $rs = substr ( $LCDATA[$r], 0, 16); $ss = substr ( $LCDATA[$s], 0, 16); # #rs= "line1"; #ss= "this is line2"; # # 16 char string # "1234567890123456"; #rs= " "; #ss= " "; # # printf "..$#LCDATA..data[$r]=$rs....$ss..\n"; # # # 30-Jan-05 amo "\n" is needed and use 16char string to print to the lcd # # Clear and home the LCD display # ------------------------------ # printf LCDOUT "$cls"; # printf LCDOUT "$cursorhome\n"; # printf LCDOUT "$line1\n$rs\n"; # printf LCDOUT "$line2\n$ss\n"; # printf LCDOUT "${cls}${line1}${rs}${line2}${ss}\n"; # $r += 1; $r = 1 if ( $r >= $#LCDATA ); # sleep 2 ; # } # loop forever # close ( LCDOUT ); # } # lcd_text # # end of file