Re: How to persist text on the screen when the client exits?

Dominique Dumont <[email protected]> Sat, 5 Jan 2013 11:13:52 +0100
Newsgroups gmane.comp.sysutils.lcdproc
Message-ID <[email protected]>
Le Wednesday 2 January 2013 00:59:03, Richard Neill a écrit :
> So, I'm attaching my script, which may make things a bit clearer. This 
> is launched from cron with "@reboot".
> 
> Anyway, it works fine, except that the screen is blank about half the time.
> 
> What I really want is to treat the LCD display like a simple character 
> device, into which I can echo text. I appreciate the sophistication of 
> the lcdproc architecture, with support for buttons, menus etc, but in 
> this particular use-case, I don't need it.

I've attached the perl script I use to display data from XBMC to lcdproc.  
This script is also launched with a @reboot statement in my crontab. It 
updates lcdproc display without launching new processes. 

Hope this helps

Dominique

_______________________________________________
LCDproc mailing list
[email protected]
http://lists.omnipotent.net/mailman/listinfo/lcdproc
imon2.pl (application/x-perl, 2.6 KB)
# (c) 2012 Dominique Dumont <domi.dumont at free.fr>
# license: GPLv2 or later

use IO::LCDproc;
use LWP::UserAgent ;
use feature ":5.10" ;
use strict ;
use warnings ;

my $client      = IO::LCDproc::Client->new(name => "dod");
my $screen      = IO::LCDproc::Screen->new(name => "screen");
my $title       = IO::LCDproc::Widget->new (
					    name => "date", type => "title"
					   );
my $first       = IO::LCDproc::Widget->new(
					   name => "first", align => "center", xPos => 1, yPos => 2, 
					  );

$client->add( $screen );
$screen->add( $title, $first );
$client->connect() or die "cannot connect: $!";
$client->initialize();

my $ua = LWP::UserAgent->new;

while (1) {
    my $output = "";

    my $progress = 0;
    my $icondata = 0;

    my $res = $ua->get('http://localhost:8080/xbmcCmds/xbmcHttp?command=GetCurrentlyPlaying');

    if ($res->is_success) {
	$output = $res->content;
	#say "UA got $output";

	#remove html tags
	$output =~ s/<html>//gi;
	$output =~ s/<.html>//gi;
	$output =~ s/<li>//gi;
    }
    else {
	sleep 10;
	next ;
    }

    my @lines = split(/\n/, $output);
    my $title_show = '';
    my $ep = '';

    foreach my $val (@lines) {
	if ($val =~ /show title/i) {
	    $title_show = (split /:/,$val,2)[1] ;
	}
	if ($val =~ /^title/i) {
	    $ep = (split /:/,$val,2)[1] ;
	}
	if ($val =~ /Filename:/i) {
	    given ($val) {
		when (/.mpg/i)  { $icondata |=  (1<<19) } #turn on MPG icon
		when (/.mpeg/i) { $icondata |=  (1<<19) } #turn on MPG icon
		when (/.avi/i)  { $icondata |=  (2<<19) } #turn on DIVX icon
		when (/.wmv/i)  { $icondata |=  (4<<19) } #turn on WMV icon
		when (/.wma/i)  { $icondata |=  (3<<13) } #turn on WMA icon
		when (/.mp3/i)  { $icondata |=  (1<<13) } #turn on MP3 icon
		when (/.ogg/i)  { $icondata |=  (2<<13) } #turn on OGG icon
		when (/.wav/i)  { $icondata |=  (4<<13) } #turn on WAV icon
	    }
	    $title_show ||= (split /:/,$val,2)[1] ;
	}

	if ($val =~ /Type:/) {
	    given ($val) {
		when (/Video/i)   { $icondata |=  (2<<1) } #turn on MOVIE icon
		when (/Audio/i)   { $icondata |=  (1<<1) } # turn on MUSIC icon
		when (/Audio|Video/i)   { $icondata |=  1 } # enable play animation
		when (/Picture/i) { $icondata |=  (3<<1) } # turn on PHOTO icon
	    }
	}

	if ($val =~ /Percentage:/) {
	    $val =~ s/Percentage://i;
	    $progress = $val *32 / 100;
	}
    }

    $title->set( data => $title_show );
    $first->set(data => $ep ) ;
    $client->output($icondata+0);
    $client->flushAnswers;
    sleep 1;
    $client->output( ( ($progress <<6) | (1<<28) ) + 0 ); # configure upper progress bar
    $client->flushAnswers;
    sleep 1;
};