-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript
More file actions
executable file
·36 lines (31 loc) · 921 Bytes
/
script
File metadata and controls
executable file
·36 lines (31 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python3
from collections import deque
from time import sleep
from os import system
def tilt1():
with open('/sys/devices/platform/lis3lv02d/position') as f:
return int(f.read().split(",")[1])
def tilt2():
with open('/sys/devices/platform/lis3lv02d/position') as f:
return int(f.read().split(",")[0].split("(")[1])
print("Starting service...")
state = "normal"
newstate = state
while True:
avg1 = tilt1()
avg2 = tilt2()
if state == "normal":
if avg1 < -800:
newstate = "left"
if avg1 > 800:
newstate = "right"
elif state == "left":
if avg1 > -250 and avg2 < 500:
newstate = "normal"
elif state == "right":
if avg1 < 250 and avg2 < 500:
newstate = "normal"
if state != newstate:
system("xrandr --output eDP1 --rotate " + newstate)
state = newstate
sleep(0.04)