mirror of
https://github.com/erjiang/huion-keys.git
synced 2026-03-23 21:54:53 +03:00
Fixed XDO not working
General cleanup in accordance with pep8
This commit is contained in:
parent
611621d4ab
commit
5d3f0778f1
@ -31,6 +31,7 @@ BUTTON_BITS = {
|
||||
0x80: 8,
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
# Commandline arguments processing
|
||||
parser = argparse.ArgumentParser(
|
||||
@ -66,7 +67,6 @@ def main():
|
||||
hidraw_path = get_tablet_hidraw(device_id)
|
||||
if hidraw_path is not None:
|
||||
hidraw_paths = hidraw_paths + hidraw_path
|
||||
|
||||
if hidraw_paths:
|
||||
print("Found %s at %s" % (device_name, hidraw_paths))
|
||||
break
|
||||
@ -85,14 +85,14 @@ def main():
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
|
||||
|
||||
class PollThread(threading.Thread):
|
||||
|
||||
cycle_mode = None
|
||||
scroll_state = None
|
||||
hidraw_path = None
|
||||
xdo = None
|
||||
|
||||
SCROLL_STATE=None
|
||||
|
||||
def __init__(self, hidraw_path):
|
||||
super(PollThread, self).__init__()
|
||||
self.xdo = lib.xdo_new(ffi.NULL)
|
||||
@ -119,8 +119,6 @@ class PollThread(threading.Thread):
|
||||
time.sleep(3)
|
||||
break
|
||||
print("Got button %s" % (btn,))
|
||||
print(CYCLE_MODES)
|
||||
print(self.cycle_mode)
|
||||
if btn == CYCLE_BUTTON and CYCLE_BUTTON is not None:
|
||||
self.cycle_mode = self.cycle_mode + 1
|
||||
if self.cycle_mode > CYCLE_MODES:
|
||||
@ -163,18 +161,18 @@ class PollThread(threading.Thread):
|
||||
scroll_pos = sequence[5]
|
||||
if scroll_pos == 0:
|
||||
# reset scroll state after lifting finger off scroll strip
|
||||
self.SCROLL_STATE = None
|
||||
elif self.SCROLL_STATE is not None:
|
||||
self.scroll_state = None
|
||||
elif self.scroll_state is not None:
|
||||
# scroll strip is numbered from top to bottom so a greater new
|
||||
# value means they scrolled down
|
||||
if scroll_pos > self.SCROLL_STATE:
|
||||
self.SCROLL_STATE = scroll_pos
|
||||
if scroll_pos > self.scroll_state:
|
||||
self.scroll_state = scroll_pos
|
||||
return 'scroll_down'
|
||||
elif scroll_pos < self.SCROLL_STATE:
|
||||
self.SCROLL_STATE = scroll_pos
|
||||
elif scroll_pos < self.scroll_state:
|
||||
self.scroll_state = scroll_pos
|
||||
return 'scroll_up'
|
||||
else:
|
||||
self.SCROLL_STATE = scroll_pos
|
||||
self.scroll_state = scroll_pos
|
||||
continue
|
||||
elif sequence[1] == 0xf1: # dial on Q620M, practically 2 buttons
|
||||
if sequence[5] == 0x1:
|
||||
@ -190,11 +188,12 @@ class PollThread(threading.Thread):
|
||||
if sequence[1] == 0xe0 and sequence[4] == 0 and sequence[5] == 0:
|
||||
return True
|
||||
|
||||
|
||||
def get_tablet_hidraw(device_id):
|
||||
"""Finds the /dev/hidrawX file or files that belong to the given device ID (in xxxx:xxxx format)."""
|
||||
# TODO: is this too fragile?
|
||||
hidraws = os.listdir('/sys/class/hidraw')
|
||||
inputs = [];
|
||||
inputs = []
|
||||
for h in hidraws:
|
||||
device_path = os.readlink(os.path.join('/sys/class/hidraw', h, 'device'))
|
||||
if device_id.upper() in device_path:
|
||||
@ -251,12 +250,14 @@ def read_config(config_file):
|
||||
for binding in CONFIG[key]:
|
||||
DIAL_MODES[mode][binding] = CONFIG[key][binding].encode('utf-8')
|
||||
|
||||
|
||||
def make_rules():
|
||||
for device_name, device_id in TABLET_MODELS.items():
|
||||
print("# %s" % (device_name, ))
|
||||
VID, PID = device_id.split(':')
|
||||
print('KERNEL=="hidraw*", ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s", MODE="0660", TAG+="uaccess"' % (VID, PID, ))
|
||||
|
||||
|
||||
def create_default_config(config_file):
|
||||
with open(config_file, 'w') as config:
|
||||
config.write("""
|
||||
@ -286,5 +287,6 @@ dial_cw=minus
|
||||
dial_ccw=equal
|
||||
""")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user