#!/usr/bin/perl -w

sub find_dell_wmi_input()
{
	my $evdev="";

	foreach my $input (glob("/sys/devices/virtual/input/input*"))
	{
		if(`cat $input/name` =~ /Dell WMI hotkeys/)
		{
			$evdev=glob("$input/event*");
			chomp $evdev;
			$evdev=~s/^.*\/(event\d+)/\/dev\/input\/$1/;
		}
	}
	return $evdev;
}
my $dev=&find_dell_wmi_input();

open(DEV,"$dev") or die;
my @bytes=((0) x 16);
my $i;
while(1)
{
	@bytes=map { ord(getc DEV) } @bytes;
#map { printf "%0.2x ",$_ } @bytes;
#	print "\n";

	if( $bytes[8] == 5 && $bytes[10] == 1)
	{
#		print "rotate ".($bytes[12]?"right":"normal")."\n";
		cmd("rotate_func ".($bytes[12]?"right":"normal"));
	}
}
