#!/usr/bin/perl # #04/07/10 matthias # #wrapper for the blinken-frame-sender. sends STDIN to blinkenledd. #best used in a pipe. # #change: #04/07/27 at the end of the sentence the frame will move upwards, (just eyecandy) #04/08/13 took the above out again, cause it was buggy # #limitations: -for 18 rows and 8 lines blinken-layout only (classic) # #todo: # -generalize the blinken layout # -make some performance tests. try to increase. possible candidates are the building of the sentence array. also substr operations are rather slow # -test for memory usage # -it should be faster to build up an hash for the alphabet to avoid always search through the whole filestring!! # use Getopt::Std; use strict; my @array; #array of one sentence from STDIN my @blink_sentence=(); #the sentence to send. array of 8 binary lines my @dummy=(); #gues what that is my $velocity=100; #velocity frames/ms my $hostname="localhost"; #the host to send to my $senderprogram="blinken-frame-sender"; #must exist in an executable path my %opts; #the options my $string; #the alphabetfile slurped into one string my $tooneline; #one frame as a string my $noframes=0; #number of frames of one sentence my $i; #counter my %alphabet; #options getopts("a:V:H: vh",\%opts); if(exists($opts{a})) { open FILEHANDLE, $opts{a} or die $!; #the famous slurping idiom $string = do { local $/; }; close(FILEHANDLE);} else {die "usage: $0 -a \n\t[-v switch verbose on (off)]\n\t[-V velocity frames/ms (100)]\n\t[-H (localhost)]\n\t[-S (blinken-frame-sender)\n\t[-h print out helptext]\n";exit(0);} while($string =~ s/(.*)\/\n([01\n]*)\///) {$alphabet{$1}=$2;} #parsing the alphabet file into hash undef($string); #not needed anymore if(exists($opts{V})) {$velocity=$opts{V};} if(exists($opts{H})) {$hostname=$opts{H};} if(exists($opts{h})) {print"$0:\nwrapper for sending everything from STDIN to a blinkenledd server.\nneeds a\"blinken-frame-sender\" for sending the frames. the executable binary can be found within the blib-library.\nnote: you have to rename the framesender binary to \"$senderprogram\" and put it in an executable path.\nthis is for security reasons.\n(for the lib have a look at http://www.gnu.org/directory/graphics/anim/blib.html).\n";exit(0);} while(1) {#main loop @array = unpack ("C*",); #reading in. strip sentence into an array of asciis if(exists($opts{v})) {print"sending to $hostname: ".pack("c*",@array);} #tell what we#re sending #building big sentence foreach(@array) { #cycling through letters (@dummy) = split(/\n/,$alphabet{$_});#strip the 8 binary lines of one letter into dummyarray for(0..7) {$blink_sentence[$_].=$dummy[$_];} #actual letter an sentence array anhaengen. ugly code. dont know how to do this better. } $noframes=length($blink_sentence[0]); #ok this is the number of frames #cycling through the sentence for($i=0;$i<$noframes;$i++) {#cycling through offsets incblinsentence strings #building one frame foreach(@blink_sentence) { #line by line while($_!~/.{$i}.{18}.*/) {$_.=0;} $tooneline .= $1 if($_=~m/.{$i}(.{18}).*/); } #sending frame if(system($senderprogram, $hostname, $tooneline)==-1){die "senderprogramm $senderprogram didnt work!\n";} select(undef,undef,undef,$velocity/1000); #sleeps ($velovcity millisecons?? dont know) #resetting frame-string $tooneline=""; } #resetting sentence @blink_sentence=(); }