#!/usr/bin/perl use constant B1 => 4; use constant B2 => 8; use constant B3 => 16; use constant B4 => 32; use constant ALL => 1; use constant TEAM => 2; use constant COMM => 64; use constant MUTE => 128; use constant OFF => 0; my $state; my $device; if(@ARGV){ $device = $ARGV[0]; }else{ $device = "/dev/" . getDeviceName(); } sysopen(DATA, $device, O_RDONLY | O_NODELAY | O_BINARY) or die "could not open $device!\n"; while(1){ my $buf; if(sysread(DATA, $buf, 1)){ my @ascii = map { ord } split //, $buf; foreach (@ascii){ my $code = getCode($_); print "read: $code\n"; } } } close(DATA); sub getCode{ my $code = shift; if($code == OFF){$state = OFF; return "off";} if($code == ALL){$state = ALL; return "all";} if($code == TEAM){$state = TEAM; return "team";} if($code == COMM){$state = COMM; return "command";} if($code == MUTE){$state = MUTE; return "mic mute";} my $binarystring = unpack('b*', pack("n",$code)); my @dest; if($binarystring =~ m/.*(\d)(\d)(\d)(\d)\d(\d)/){ if($5){push @dest, "mic mute";}else{ if($1){push @dest, "1";} if($2){push @dest, "2";} if($3){push @dest, "3";} if($4){push @dest, "4";} } } my $ret = ""; foreach (@dest){ $ret = $ret . $_ . " "; } $state = $code; return $ret; } sub getDeviceName{ my $uhidev = undef; my $uhid = undef; my @dmesg = `dmesg`; foreach (@dmesg){ if($_ =~ m/(.*):\sMicrosoft\sSideWinder\sGame\sVoice.*/){ $uhidev = $1; } } if($uhidev){ foreach (@dmesg){ if($_ =~ m/(.*)\sat\s$uhidev:/){ $uhid = $1; } } return $uhid; } die "could not find a GameVoice device!\n"; }