Skip to content

Instantly share code, notes, and snippets.

@pshchelo
Created March 25, 2015 14:49
Show Gist options
  • Save pshchelo/c74efae5f2ed73e2952b to your computer and use it in GitHub Desktop.
Save pshchelo/c74efae5f2ed73e2952b to your computer and use it in GitHub Desktop.
Using accelerometer to change desktop workspace by tilting the notebook
#!/usr/bin/python
import time
import os
with open('/sys/devices/platform/lis3lv02d/position','r') as f:
for i in xrange(100):
f.seek(0)
data = f.read()
x, y, z = map(int, data.strip()[1:-1].split(','))
print "{:d}\t{:d}\t{:d}".format(x, y, z)
if y > 200:
os.system('wmctrl -o 1600,0')
elif y < -200:
os.system('wmctrl -o 0,0')
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment