mirror of
https://github.com/erjiang/huion-keys.git
synced 2026-03-23 21:54:53 +03:00
do not terminate if the tablet is disconnected
This commit is contained in:
parent
fde83ef33b
commit
e93fd2599b
@ -62,28 +62,29 @@ def main():
|
|||||||
|
|
||||||
hidraw_paths = []
|
hidraw_paths = []
|
||||||
while True:
|
while True:
|
||||||
# search for a known tablet device
|
# search for a known tablet devices
|
||||||
for device_name, device_id in TABLET_MODELS.items():
|
for device_name, device_id in TABLET_MODELS.items():
|
||||||
hidraw_path = get_tablet_hidraw(device_id)
|
hidraw_path = get_tablet_hidraw(device_id)
|
||||||
if hidraw_path is not None:
|
if hidraw_path is not None:
|
||||||
|
print("Found %s at %s" % (device_name, hidraw_path))
|
||||||
hidraw_paths = hidraw_paths + hidraw_path
|
hidraw_paths = hidraw_paths + hidraw_path
|
||||||
if hidraw_paths:
|
if not hidraw_paths:
|
||||||
print("Found %s at %s" % (device_name, hidraw_paths))
|
|
||||||
break
|
|
||||||
elif not hidraw_paths:
|
|
||||||
print("Could not find any tablet hidraw devices")
|
print("Could not find any tablet hidraw devices")
|
||||||
time.sleep(2)
|
time.sleep(3)
|
||||||
|
continue
|
||||||
|
elif hidraw_paths:
|
||||||
|
threads = []
|
||||||
|
for hidraw_path in hidraw_paths:
|
||||||
|
thread = PollThread(hidraw_path)
|
||||||
|
# Do not let the threads to continue if main script is terminated
|
||||||
|
thread.daemon = True
|
||||||
|
threads.append(thread)
|
||||||
|
thread.start()
|
||||||
|
# TODO: Maybe should be reworked for the edge case of having more than one tablet connected at the same time.
|
||||||
|
for thread in threads:
|
||||||
|
thread.join()
|
||||||
|
hidraw_paths.clear()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
threads = []
|
|
||||||
for hidraw_path in hidraw_paths:
|
|
||||||
thread = PollThread(hidraw_path)
|
|
||||||
thread.daemon = True
|
|
||||||
threads.append(thread)
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
for thread in threads:
|
|
||||||
thread.join()
|
|
||||||
|
|
||||||
|
|
||||||
class PollThread(threading.Thread):
|
class PollThread(threading.Thread):
|
||||||
@ -115,8 +116,7 @@ class PollThread(threading.Thread):
|
|||||||
try:
|
try:
|
||||||
btn = self.get_button_press(hidraw)
|
btn = self.get_button_press(hidraw)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print("Lost connection with the tablet - searching for tablet...")
|
print("%s lost connection with the tablet..." % (self.name,))
|
||||||
time.sleep(3)
|
|
||||||
break
|
break
|
||||||
print("Got button %s" % (btn,))
|
print("Got button %s" % (btn,))
|
||||||
if btn == CYCLE_BUTTON and CYCLE_BUTTON is not None:
|
if btn == CYCLE_BUTTON and CYCLE_BUTTON is not None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user