#!/usr/bin/perl # You can find more information about this file at http://userlame.com/boards/tech/260. # Register and post on the boards there for help. # # This probably has some kind of license. Yep. # my $PIPE_FILE = "$ENV{'HOME'}/.g15pipe"; # path to the pipe for g15composer. you must have write permission here my $OUTPUT_CMD = "fortune -a"; # Really this could be any executable that returns short text my $SHOW_INTERVAL = "15"; # How long to show the fortune in seconds my $PAUSE_INTERVAL = "random"; # How often to pop up a fortune in seconds- "random" is a random interval (see below) my $SCROLL_INTERVAL = "3"; # Seconds between scrolling to next line my $SCREEN_WIDTH="32"; # Lcd width in charactars my $SCREEN_HEIGHT = "5"; # Lcd height in lines my $REVERSED = 1; # Draw white on black? my $DEBUG = 0; # Print debug messages? # The following values are only used if $PAUSE_INTERVAL is set to "random"; # In that case, PAUSE_INTERVAL will be between MIN and MAX_PAUSE_INTERVAL my $MIN_PAUSE_INTERVAL="45"; my $MAX_PAUSE_INTERVAL="300"; my $RAND_INTERVAL="0"; # initialize to 0 $SIG{'HUP'} = 'showdown'; $SIG{'INT'} = 'showdown'; $SIG{'QUIT'} = 'showdown'; $SIG{'KILL'} = 'showdown'; $SIG{'TERM'} = 'showdown'; $SIG{'CHILD'} = sub { wait }; sub g15_printscreen { # must be sent exactly $SCREEN_HEIGHT paramaters (lines of text) my @screenlines; while (my $line = shift) { my $length = length($line); $line = " " x (int ($SCREEN_WIDTH - $length) / 2) . $line . " " x ((int ($SCREEN_WIDTH - $length) / 2) + ($SCREEN_WIDTH - $length) % 2); push @screenlines, $line; } $| = 1; $DEBUG && print STDERR 'MC 1', "\n"; print 'MC 1', "\n"; $DEBUG && print STDERR 'MR 1', "\n" if $REVERSED; print 'MR 1', "\n" if $REVERSED; for (my $i=0; $i', $PIPE_FILE) or die("Couldn't open pipe $PIPE_FILE"); select LCDPIPE; if (scalar(@_) > $SCREEN_HEIGHT) { while (scalar(@_) > ($SCREEN_HEIGHT)) { g15_printscreen(@_[0 .. ($SCREEN_HEIGHT-1)]); shift; sleep $SCROLL_INTERVAL; } } elsif (scalar(@_) < $SCREEN_HEIGHT) { while (scalar(@_) < $SCREEN_HEIGHT) { push @_, ' ' x $SCREEN_WIDTH; } } g15_printscreen(@_); sleep $SHOW_INTERVAL; } sub g15_start { system("g15composer $PIPE_FILE &"); } sub g15_stop { system("killall g15composer"); unlink $PIPE_FILE; } sub showdown { g15_stop(); exit; } sub showtext { g15_start(); my $OUTPUT_TEXT = qx/$OUTPUT_CMD/; $OUTPUT_TEXT =~ s/^\s*$//sg; $OUTPUT_TEXT =~ s/"/'/g; $OUTPUT_TEXT =~ s/ {2,}/ /g; chomp($OUTPUT_TEXT); my @OUTPUT = split /\n/, $OUTPUT_TEXT; my @LINES = (); for (@OUTPUT) { next if /^\s*$/; my $CURR_LINE = $_; $CURR_LINE =~ s/[^ -~]//g; if (length($CURR_LINE) > $SCREEN_WIDTH) { while ($CURR_LINE) { my $line = $CURR_LINE; my $length = length($CURR_LINE); if ($length > $SCREEN_WIDTH) { my $tmp = $SCREEN_WIDTH-1; $line =~ s/^(.{1,$tmp}\S)\s.*?$/$1/; $length = length($line); push @LINES, $line; $CURR_LINE = substr($CURR_LINE, $length); $CURR_LINE =~ s/^\s+(.*)?$/$1/; } else { push @LINES, $line; $CURR_LINE = substr($CURR_LINE, $length); } } } else { push @LINES, $CURR_LINE; } } g15_send(@LINES); g15_stop(); } while (1) { if ($PAUSE_INTERVAL == "random") { sleep (int rand(($MAX_PAUSE_INTERVAL - $MIN_PAUSE_INTERVAL)) + $MIN_PAUSE_INTERVAL); } else { sleep $PAUSE_INTERVAL; } showtext(); } showdown;