Update autorotate.py
This commit is contained in:
parent
7901d8dbd9
commit
64b2cd3317
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from gi.repository import Notify
|
||||||
|
|
||||||
#FUNCTIONS
|
#FUNCTIONS
|
||||||
def readFile(path): #self.filename
|
def readFile(path): #self.filename
|
||||||
|
@ -27,11 +30,10 @@ def refreshtouch():
|
||||||
#PARAMETERS
|
#PARAMETERS
|
||||||
count = 0
|
count = 0
|
||||||
path = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
|
path = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
|
||||||
print (path)
|
|
||||||
|
|
||||||
devicename = "'NTRG0001:01 1B96:1B05'"
|
devicename = "'NTRG0001:01 1B96:1B05'"
|
||||||
penname = "'NTRG0001:01 1B96:1B05 Pen'"
|
penname = "'NTRG0001:01 1B96:1B05 Pen'"
|
||||||
freq = 10.0 # frequency to read the accelerometer
|
freq = 5.0
|
||||||
|
|
||||||
|
|
||||||
# Look for accelerometer
|
# Look for accelerometer
|
||||||
while count <= 9:
|
while count <= 9:
|
||||||
|
@ -46,45 +48,84 @@ normal = 'xrandr -o normal; '+'xinput set-prop ' + devicename +" 'Coordinate Tra
|
||||||
inverted = 'xrandr -o inverted; '+'xinput set-prop ' + devicename +" 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1;"+'xinput set-prop ' + penname +" 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1;"
|
inverted = 'xrandr -o inverted; '+'xinput set-prop ' + devicename +" 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1;"+'xinput set-prop ' + penname +" 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1;"
|
||||||
right = 'xrandr -o left; '+'xinput set-prop ' + devicename +" 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1;"+'xinput set-prop ' + penname +" 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1;"
|
right = 'xrandr -o left; '+'xinput set-prop ' + devicename +" 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1;"+'xinput set-prop ' + penname +" 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1;"
|
||||||
left = 'xrandr -o right; '+'xinput set-prop ' + devicename +" 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1;"+'xinput set-prop ' + penname +" 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1;"
|
left = 'xrandr -o right; '+'xinput set-prop ' + devicename +" 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1;"+'xinput set-prop ' + penname +" 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1;"
|
||||||
|
state_dict = {0: "normal", 1: "inverted", 2: "right", 3: "left"}
|
||||||
current_state = 0 # 0 normal, 1 inverted, 2 right, 3 left
|
current_state = 0
|
||||||
|
previous_tstate = "on"
|
||||||
|
previousStylusProximityStatus = "out"
|
||||||
|
#ACCELEROMETER
|
||||||
with open(dpath + 'in_accel_scale') as f:
|
with open(dpath + 'in_accel_scale') as f:
|
||||||
scale = float(f.readline())
|
scale = float(f.readline())
|
||||||
while True:
|
while True:
|
||||||
|
time.sleep(1.0/freq)
|
||||||
previous_state = current_state
|
previous_state = current_state
|
||||||
status = readFile(os.path.join(path, 'status.txt'))
|
status = readFile(os.path.join(path, 'status.txt'))
|
||||||
print(status)
|
|
||||||
if str(status[0]) == "on":
|
if str(status[0]) == "on":
|
||||||
with open(dpath + 'in_accel_x_raw', 'r') as fx:
|
with open(dpath + 'in_accel_x_raw', 'r') as fx:
|
||||||
with open(dpath + 'in_accel_y_raw', 'r') as fy:
|
with open(dpath + 'in_accel_y_raw', 'r') as fy:
|
||||||
with open(dpath + 'in_accel_z_raw', 'r') as fz:
|
with open(dpath + 'in_accel_z_raw', 'r') as fz:
|
||||||
time.sleep(1.0/freq)
|
|
||||||
thex = float(fx.readline())
|
thex = float(fx.readline())
|
||||||
they = float(fy.readline())
|
they = float(fy.readline())
|
||||||
thez = float(fz.readline())
|
thez = float(fz.readline())
|
||||||
print("x:" + str(thex))
|
|
||||||
print("y:" + str(they))
|
|
||||||
print("z:" + str(thez))
|
|
||||||
if (thex >= 65000 or thex <=650):
|
if (thex >= 65000 or thex <=650):
|
||||||
if (they <= 65000 and they >= 64000):
|
if (they <= 65000 and they >= 64000):
|
||||||
print("normal!")
|
|
||||||
os.system(normal)
|
os.system(normal)
|
||||||
current_state = 0
|
current_state = 0
|
||||||
if (they >= 650 and they <= 1100):
|
if (they >= 650 and they <= 1100):
|
||||||
print("inverted!")
|
|
||||||
os.system(inverted)
|
os.system(inverted)
|
||||||
current_state = 1
|
current_state = 1
|
||||||
if (thex <= 64999 and thex >= 650):
|
if (thex <= 64999 and thex >= 650):
|
||||||
if (thex >= 800 and thex <= 1000):
|
if (thex >= 800 and thex <= 1000):
|
||||||
print ("right!")
|
|
||||||
os.system(right)
|
os.system(right)
|
||||||
current_state = 2
|
current_state = 2
|
||||||
if (thex >= 64500 and thex <=64700):
|
if (thex >= 64500 and thex <=64700):
|
||||||
print ("left!")
|
|
||||||
os.system(left)
|
os.system(left)
|
||||||
current_state = 3
|
current_state = 3
|
||||||
if str(status[0]) == "off":
|
|
||||||
time.sleep(1.0)
|
os.system('clear')
|
||||||
|
print("A-ROT: " + status[0])
|
||||||
|
print(" x: " + str(thex))
|
||||||
|
print(" y: " + str(they))
|
||||||
|
print(" z: " + str(thez))
|
||||||
|
print(" POS: " + state_dict[current_state])
|
||||||
|
if status[0] == "off":
|
||||||
|
os.system('clear')
|
||||||
|
print("A-ROT: " + status[0])
|
||||||
|
print(" x: " + status[0])
|
||||||
|
print(" y: " + status[0])
|
||||||
|
print(" z: " + status[0])
|
||||||
|
print(" POS: " + state_dict[previous_state])
|
||||||
if current_state != previous_state:
|
if current_state != previous_state:
|
||||||
refreshtouch()
|
refreshtouch()
|
||||||
print "Touchscreen refreshed"
|
print "Touchscreen refreshed"
|
||||||
|
|
||||||
|
print("##########################")
|
||||||
|
#SCREEN
|
||||||
|
stylusProximityCommand = 'xinput query-state "NTRG0001:01 1B96:1B05 Pen" | grep Proximity | cut -d " " -f3 | cut -d "=" -f2'
|
||||||
|
stylusProximityStatus = str(subprocess.check_output(stylusProximityCommand, shell=True).lower().rstrip())
|
||||||
|
tstatus = readFile(os.path.join(path, 'touch.txt'))
|
||||||
|
#TOUCHSCREEN
|
||||||
|
if str(tstatus[0]) == "on" and stylusProximityStatus == "out":
|
||||||
|
os.system('xinput enable ' + devicename + '')
|
||||||
|
print("TOUCH: " + tstatus[0])
|
||||||
|
if str(tstatus[0]) != previous_tstate:
|
||||||
|
Notify.init ("Touchscreen-ON")
|
||||||
|
RotationON=Notify.Notification.new ("Touchscreen","Touchscreen is now turned ON","dialog-information")
|
||||||
|
RotationON.show()
|
||||||
|
elif str(tstatus[0]) == "off" and stylusProximityStatus == "out":
|
||||||
|
os.system('xinput disable ' + devicename + '')
|
||||||
|
print("TOUCH: " + tstatus[0])
|
||||||
|
if str(tstatus[0]) != previous_tstate:
|
||||||
|
Notify.init ("Touchscreen-OFF")
|
||||||
|
RotationOFF=Notify.Notification.new ("Touchscreen","Touchscreen is now turned OFF","dialog-information")
|
||||||
|
RotationOFF.show()
|
||||||
|
previous_tstate = str(tstatus[0])
|
||||||
|
#PEN
|
||||||
|
if str(tstatus[0]) == "off" and stylusProximityStatus == "in":
|
||||||
|
print("TOUCH: " + tstatus[0])
|
||||||
|
print(" PEN: " + stylusProximityStatus)
|
||||||
|
elif str(tstatus[0]) == "on" and stylusProximityStatus == "in":
|
||||||
|
os.system('xinput disable "NTRG0001:01 1B96:1B05"')
|
||||||
|
print("TOUCH: " + "off")
|
||||||
|
print(" PEN: " + stylusProximityStatus)
|
||||||
|
elif stylusProximityStatus == "out":
|
||||||
|
print(" PEN: " + stylusProximityStatus)
|
||||||
|
|
Loading…
Reference in New Issue