ich lese vom Touch Display die Events in ein kleines Python Programm. Es zeigt sich jedoch, dass die CPU load immer bei 100% liegt.
Ich konnte das auf den Befehl event = in_file.read(EVENT_SIZE) eingrenzen.
Wie kann ich das ändern?
Code: Select all
#!/usr/bin/python
import struct
import time
import sys
from multiprocessing import Process
infile_path = "/dev/input/event" + (sys.argv[1] if len(sys.argv) > 1 else "0")
#long int, long int, unsigned short, unsigned short, unsigned int
FORMAT = 'llHHI'
EVENT_SIZE = struct.calcsize(FORMAT)
#open file in binary mode
in_file = open(infile_path, "rb")
def touchEvent():
event = in_file.read(EVENT_SIZE)
X_Axis = Y_Axis = BTN_TOUCH = False
while not (X_Axis and Y_Axis and BTN_TOUCH):
(tv_sec, tv_usec, type, code, value) = struct.unpack(FORMAT, event)
if type != 0:
print("Event type %u, code %u, value %u at %d.%d" % \
(type, code, value, tv_sec, tv_usec))
if (code == 0):
X_Axis = True if 110 <= value <= 170 else False
if (code == 1):
Y_Axis = True if 350 <= value <= 420 else False
if (code == 330):
BTN_TOUCH = True if value else False
event = in_file.read(EVENT_SIZE)
if __name__ == "__main__":
try:
while 1:
touch = Process(target=touchEvent,args=())
touch.start()
while 1:
if not touch.is_alive():
touch.terminate()
print ('active : ',touch.is_alive())
time.sleep(1)
break
del (touch)
print ('sleeping..')
time.sleep(3)
print ('END')
except KeyboardInterrupt:
print("goodbye")
except Exception as exception:
print("unexpected error: ", str(exception))
finally:
in_file.close()