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;
  }

}

Re: Accelerometer on Novena rotating the display with xrandr:

That looks like it should work, but it will burn a LOT of CPU cycles in doing so, as it's a while(1) loop with no delay in it. I'd suggest if you want to have this running for auto-rotation that you and a non-busy delay in the loop.

Otherwise, it looks good. Are people working on Novena tablets/convertables? Or was this just 'cause? I guess I don't really see use in auto-rotating a traditional laptop.

Re: Accelerometer on Novena rotating the display with xrandr:

The busy loop was to see the values from the senors on the screen with a high update rate, to get a feeling for the data quality the sensor delivers. Feel free to add a sleep depending on your application.
I am not working on a Novena tablet/convertable, no. I am currently using gyro for a different application, so I thought, why not look into the one we have in the Novena and learn a bit about it.
There are 2 possible applications I see for the Novena: When you hang it on a wall-mount, you have to rotate the display, since the screw-holes are in a location to make sure that the Novena gets enough air-flow.
When I played around with it, I noticed that it's interesting to read websites in landscape mode on a Novena.