#!/usr/bin/perl -w use FileHandle; use Time::HiRes; # Changes: # 2006-08-04 added arrow if displayed string is too long # 2006-08-11 fork; changed this version for 2x20 VFD # 2006-08-11 improved line breaks and stream name removal system ("stty -F /dev/ttyS0 9600 -ocrnl -onlcr -onlret"); open (SERIAL, ">/dev/ttyS0") || die ("Could not open serial port: $!\n"); autoflush SERIAL 1; $oldstatus = 23; $oldtitle = "Blubb"; while (1) { ($status, $time, $bitrate, $channels, $pos, $len, $title) = GetInfo (); if ($status == 2) { # display nothing if stopped $title = ""; } if (($oldtitle ne $title) or ($oldstatus ne $status)) { print (SERIAL chr(0x1F)); # reset Time::HiRes::usleep (5*1000); print (SERIAL chr(0x1B), chr(0x00), chr(0x86), chr(0x39), chr(0xEE), chr(0x62), chr(0x00)); # custom char #0 - "play" print (SERIAL chr(0x1B), chr(0x01), chr(0x06), chr(0xF7), chr(0xBD), chr(0xEC), chr(0x00)); # custom char #1- "pause" print (SERIAL chr(0x1B), chr(0x02), chr(0x07), chr(0xFF), chr(0xFF), chr(0xFC), chr(0x00)); # custom char #2 - "stop" print (SERIAL chr(0x14)); # cursor off print (SERIAL chr(0x11)); # no scrolling print (SERIAL chr(0x04), chr(0x40)); # brightness 40% $message = chr($status) . " " . $title; $message = strip ($message); if ($len < 0) { # remove stream name $closing = rindex ($message, ")"); $opening = rindex ($message, "(", $closing - 1); if (($opening > -1) and ($closing > -1)) { $closing_new = $closing; while (1) { $closing_new = rindex ($message, ")", $closing_new - 1); if ($closing_new > $opening) { $opening_new = rindex ($message, "(", $opening - 1); if ($opening_new > -1) { $opening = $opening_new; } else { last; } } else { last; } } substr ($message, $opening, $closing - $opening + 1) = ""; } } $message = strip ($message); print (SERIAL chr(0x10), chr(0x00)); # line 1 $line = Line (20, 1); print (SERIAL $line); print (SERIAL chr(0x10), chr(0x14)); # line 2 $line = Line (20, 0); print (SERIAL $line); if (length ($message) > 0) { # right arrow if text is too long print (SERIAL chr(0x10), chr(0x26), chr(0x20), chr(0xFA)); } $oldstatus = $status; $oldtitle = $title; } sleep (1); } # return the first <= 20 chars of $message, splitting at spaces only if $space == 1 sub Line { my ($end, $line, $len, $space); ($len, $space) = @_; if(length($message) <= $len) { $line = $message; $message = ""; } else { $end = rindex($message, " ", $len); if (($end > -1) and ($space != 0)) { $line = substr($message, 0, $end); $message = substr($message, $end + 1); } else { $line = substr($message, 0, $len); $message = substr($message, $len); } } return $line; } # return currently playing title from XMMS info file sub GetInfo { my (@info, $line, $title, $status, $pos, $len, $time, $channels, $bitrate); open (DATA, "/tmp/xmms-info") || return (2, "0:00", 128, 2, 0, -1, "Could not open /tmp/xmms-info: $!"); @info = ; close (DATA); $title = ""; $pos = 0; $len = -1; $time = "0:00"; $channels = 2; $bitrate = 128; foreach $line (@info) { chomp ($line); if ($line =~ /^Title: /) { $title = substr ($line, 7); $title =~ s/^Title: //; } elsif ($line =~ /^Status: /) { if ($line =~ /Playing/) { $status = 0; } elsif ($line =~ /Paused/) { $status = 1; } elsif ($line =~ /Stopped/) { $status = 2; } } elsif ($line =~ /^uSecPosition: /) { $pos = substr ($line, 14); } elsif ($line =~ /^uSecTime: /) { $len = substr ($line, 10); } elsif ($line =~ /^Time: /) { $time = substr ($line, 6); } elsif ($line =~ /^Current bitrate: /) { $bitrate = substr ($line, 17) / 1000; } elsif ($line =~ /^Channels: /) { $channels = substr ($line, 10); } } return ($status, $time, $bitrate, $channels, $pos, $len, $title); } # remove trailing \n and leading and trailing spaces sub strip { my ($text) = @_; chomp ($text); while ($text =~ s/^ //) { } while ($text =~ s/ $//) { } return ($text); }