Advertisement
uselessfire

rotate.py

Feb 28th, 2015
1,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/python2
  2. import sys, os, gc, time, glob
  3.  
  4. for device in glob.glob('/sys/bus/iio/devices/iio:device*'):
  5.     if open(device + '/name').read() == 'accel_3d\n':
  6.         scale = float(open(device + '/in_accel_scale').read())
  7.         break
  8.  
  9. if __name__ == '__main__':
  10.     x = open(device + '/in_accel_x_raw')
  11.     y = open(device + '/in_accel_y_raw')
  12.     try:
  13.         while True:
  14.             x.seek(0)
  15.             y.seek(0)
  16.             current_x = float(x.read()) * scale
  17.             current_y = float(y.read()) * scale
  18.             if current_y <= -7.0:
  19.                 os.popen('xrandr -o normal')
  20.             elif current_y >= 7.0:
  21.                 os.popen('xrandr -o inverted')
  22.             elif current_x >= 7.0:
  23.                 os.popen('xrandr -o left')
  24.             elif current_x <= -7.0:
  25.                 os.popen('xrandr -o right')
  26.            
  27.             time.sleep(1)
  28.     except KeyboardInterrupt:
  29.         sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement