Skip to content

Commit 3098672

Browse files
committed
bind to hid touchpad on legos to avoid spurious lifts
1 parent 4f6e213 commit 3098672

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/hhd/device/legion_go/slim/base.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
from hhd.controller.lib.hide import unhide_all
1111
from hhd.controller.physical.evdev import B as EC
1212
from hhd.controller.physical.evdev import GenericGamepadEvdev, enumerate_evs
13+
from hhd.controller.physical.hidraw import GenericGamepadHidraw
1314
from hhd.controller.virtual.uinput import HHD_PID_VENDOR, UInputDevice
1415
from hhd.plugins import Config, Context, Emitter, get_outputs
1516

1617
from .const import (
1718
GOS_INTERFACE_AXIS_MAP,
1819
GOS_INTERFACE_BTN_ESSENTIALS,
1920
GOS_INTERFACE_BTN_MAP,
20-
GOS_TOUCHPAD_BUTTON_MAP,
21-
GOS_TOUCHPAD_AXIS_MAP,
21+
GOS_TOUCHPAD_AXIS_MAP_HID,
22+
GOS_TOUCHPAD_BUTTON_MAP_HID,
2223
)
2324
from .hid import LegionHidraw, LegionHidrawTs, rgb_callback
2425

25-
2626
FIND_DELAY = 0.1
2727
ERROR_DELAY = 0.5
2828
LONGER_ERROR_DELAY = 3
@@ -268,16 +268,25 @@ def controller_loop_xinput(
268268
)
269269

270270
uses_touch = d_params.get("uses_touch", False)
271-
d_touch = GenericGamepadEvdev(
271+
d_touch_mute = GenericGamepadEvdev(
272272
vid=[GOS_VID],
273273
pid=list(GOS_PIDS),
274274
capabilities={
275275
EC("EV_KEY"): [EC("BTN_LEFT")],
276276
EC("EV_ABS"): [EC("ABS_MT_POSITION_Y")],
277277
},
278-
btn_map=GOS_TOUCHPAD_BUTTON_MAP,
279-
axis_map=GOS_TOUCHPAD_AXIS_MAP,
280-
aspect_ratio=1,
278+
btn_map={},
279+
axis_map={},
280+
# aspect_ratio=1,
281+
required=True,
282+
)
283+
d_touch = GenericGamepadHidraw(
284+
vid=[GOS_VID],
285+
pid=list(GOS_PIDS),
286+
application=[0x000D0022],
287+
btn_map=GOS_TOUCHPAD_BUTTON_MAP_HID,
288+
axis_map=GOS_TOUCHPAD_AXIS_MAP_HID,
289+
# aspect_ratio=1,
281290
required=True,
282291
)
283292

@@ -342,13 +351,15 @@ def prepare(m):
342351
prepare(d_xinput)
343352
prepare(d_shortcuts)
344353
if uses_touch:
354+
prepare(d_touch_mute)
345355
prepare(d_touch)
346356
prepare(d_cfg)
347357
prepare(d_raw)
348358
for d in d_producers:
349359
prepare(d)
350360

351361
logger.info("Emulated controller launched, have fun!")
362+
352363
while not should_exit.is_set() and not updated.is_set():
353364
start = time.perf_counter()
354365
# Add timeout to call consumers a minimum amount of times per second

src/hhd/device/legion_go/slim/const.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@
7272
"touchpad_y": [B("ABS_Y")], # also ABS_MT_POSITION_Y
7373
}
7474
)
75+
76+
GOS_TOUCHPAD_AXIS_MAP_HID: dict[int | None, dict[Axis, AM]] = {
77+
None: {
78+
"touchpad_x": AM(2 << 3, "i16", scale=1/400),
79+
"touchpad_y": AM(4 << 3, "i16", scale=1/400),
80+
}
81+
}
82+
GOS_TOUCHPAD_BUTTON_MAP_HID: dict[int | None, dict[Button, BM]] = {
83+
None: {
84+
"touchpad_touch": BM((8 << 3) + 7),
85+
"touchpad_left": BM((9 << 3) + 7),
86+
}
87+
}

0 commit comments

Comments
 (0)