aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhesicong <derekhe@april1985.com>2015-10-26 09:24:01 +0800
committerhesicong <derekhe@april1985.com>2015-10-26 09:24:01 +0800
commit19f1ba6ffb85d4b4f502def29bfefdd086344f29 (patch)
treed946df150653ee7e8c60dab2d8c6aa08892dd152
parent13e21d0a988dcde80b42efe00e98b75429b133e7 (diff)
parent6c7dbb2744aad3b44c3202b7c59d13779e0b29ca (diff)
downloadwaveshare-7inch-touchscreen-driver-19f1ba6ffb85d4b4f502def29bfefdd086344f29.tar.xz
waveshare-7inch-touchscreen-driver-19f1ba6ffb85d4b4f502def29bfefdd086344f29.zip
Merge pull request #5 from rodriada000/patch-1
Handle read fail and detect device again.
Diffstat (limited to '')
-rw-r--r--touch.py13
1 files 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)