Topic: Accelerometer on Novena rotating the display with xrandr:
from sourcerer on irc/pastebin:
#!/usr/bin/perl -w
use strict;
sub readfile($)
{
open IN,$_[0];
my $content=<IN>;
close IN;
return $content;
}
my $state=0;
my $newstate=0;
while(1)
{
my $x=readfile("/sys/module/mma8452/drivers/i2c:mma8452/0-001c/iio:device0/in_accel_x_raw");
my $y=readfile("/sys/module/mma8452/drivers/i2c:mma8452/0-001c/iio:device0/in_accel_y_raw");
my $z=readfile("/sys/module/mma8452/drivers/i2c:mma8452/0-001c/iio:device0/in_accel_z_raw");
print "x: $x y: $y z: $z\n";
if($x >=1000 && $x <=1050)
{
$newstate=1;
}
if($x >=-1050 && $x <=-1000)
{
$newstate=2;
}
if($ z>=1000 && $z <=1050)
{
$newstate=3;
}
if($newstate!=$state)
{
my %xrandr=(3=>"normal",1=>"right",2=>"left");
system("xrandr -o ".$xrandr{$newstate});
$state=$newstate;
}
}