public
Created

Timeout reading a Linux input event

  • Download Gist
play_movie.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#!/usr/bin/perl
$ENV{'DISPLAY'} = ":0.0";
system("xhost +");
#system("totem --quit");
#system("nice -n -5 totem --fullscreen /home/root/playlist.xml &");
$cmdline_start = "nice -n -5 mplayer /home/root/*.mov &";
system($cmdline_start);
 
open(FILE, "/dev/input/event0");
binmode(FILE);
while(1)
{
eval
{
local $SIG{ALRM} = sub { die("Alarm!\n") };
alarm(60*28); # 28 minutes
read(FILE, $buf, 16);
alarm(0);
};
if($@)
{
printf("Restarting due to timeout\n");
#system("totem --next");
system("killall -15 mplayer");
sleep(1);
system("killall -9 mplayer");
sleep(1);
system($cmdline_start);
}
else
{
($time1, $time2, $type, $code, $value) = unpack("iissi", $buf);
printf("%f %05d %05d 0x%08x\n", $time1+$time2/1000000, $type, $code, $value);
if($code == 276 && $value == 1) # USER button pressed
{
printf("Restarting due to USER button press\n");
#system("totem --next");
system("killall -15 mplayer");
sleep(1);
system("killall -9 mplayer");
sleep(1);
system($cmdline_start);
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.