From 64b2cd3317cfe0f2c4a8ed716d1c4dfc9d3434ab Mon Sep 17 00:00:00 2001 From: AykoPoel Date: Mon, 5 Jan 2015 16:09:27 +0100 Subject: [PATCH] Update autorotate.py --- autorotate/autorotate.py | 73 +++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/autorotate/autorotate.py b/autorotate/autorotate.py index ac0d474..b86210f 100755 --- a/autorotate/autorotate.py +++ b/autorotate/autorotate.py @@ -1,6 +1,9 @@ #!/usr/bin/env python2 import time import os +import subprocess +import sys +from gi.repository import Notify #FUNCTIONS def readFile(path): #self.filename @@ -27,11 +30,10 @@ def refreshtouch(): #PARAMETERS count = 0 path = os.path.abspath(os.path.dirname(os.path.abspath(__file__))) -print (path) - devicename = "'NTRG0001:01 1B96:1B05'" penname = "'NTRG0001:01 1B96:1B05 Pen'" -freq = 10.0 # frequency to read the accelerometer +freq = 5.0 + # Look for accelerometer 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;" 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;" - -current_state = 0 # 0 normal, 1 inverted, 2 right, 3 left +state_dict = {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: scale = float(f.readline()) while True: + time.sleep(1.0/freq) previous_state = current_state status = readFile(os.path.join(path, 'status.txt')) - print(status) if str(status[0]) == "on": 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_z_raw', 'r') as fz: - time.sleep(1.0/freq) thex = float(fx.readline()) they = float(fy.readline()) thez = float(fz.readline()) - print("x:" + str(thex)) - print("y:" + str(they)) - print("z:" + str(thez)) if (thex >= 65000 or thex <=650): if (they <= 65000 and they >= 64000): - print("normal!") os.system(normal) current_state = 0 if (they >= 650 and they <= 1100): - print("inverted!") os.system(inverted) current_state = 1 if (thex <= 64999 and thex >= 650): if (thex >= 800 and thex <= 1000): - print ("right!") os.system(right) current_state = 2 if (thex >= 64500 and thex <=64700): - print ("left!") os.system(left) 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: refreshtouch() 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)