From 6c7dbb2744aad3b44c3202b7c59d13779e0b29ca Mon Sep 17 00:00:00 2001 From: Adam Rodriguez Date: Sun, 25 Oct 2015 14:07:48 -0700 Subject: Update touch.py Added a try, except: around f.read(25). This ensures that if it cant read from the device then it will exit the function then reconnect to the device. In my case whenever i plugged in any USB it would disconnect and change the driver name. this should fix that problem. --- touch.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/touch.py b/touch.py index 223c3da..71e88ca 100644 --- a/touch.py +++ b/touch.py @@ -26,10 +26,15 @@ def read_and_emulate_mouse(deviceFound): startTime = time.time() while True: - b = f.read(25) - (tag, btnLeft, x, y) = struct.unpack_from('>c?HH', b) - print(btnLeft, x, y) - time.sleep(0.01) + try: + b = f.read(25) + (tag, btnLeft, x, y) = struct.unpack_from('>c?HH', b) + print(btnLeft, x, y) + except: + print('failed to read from deviceFound' + str(deviceFound)) + return + + time.sleep(0.01) if btnLeft: device.emit(uinput.ABS_X, x, True) -- cgit v1.2.1