Skip to content

Commit 27f6b73

Browse files
committed
add touchpad emulation alpha for the go s
1 parent 6a34342 commit 27f6b73

File tree

5 files changed

+54
-57
lines changed

5 files changed

+54
-57
lines changed

src/hhd/controller/virtual/sd/__init__.py

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
from collections import defaultdict
44
from typing import Sequence, cast
55

6-
from hhd.controller import Consumer, Event, Producer
6+
from hhd.controller import (
7+
Consumer,
8+
Event,
9+
Producer,
10+
)
711
from hhd.controller.lib.uhid import UhidDevice, BUS_USB
812
from hhd.controller.lib.common import encode_axis, set_button
913
from hhd.controller.lib.ccache import ControllerCache
@@ -100,6 +104,7 @@ def open(self) -> Sequence[int]:
100104
self.state: dict = defaultdict(lambda: 0)
101105
self.rumble = False
102106
self.touchpad_touch = False
107+
self.touchpad_left = False
103108
curr = time.perf_counter()
104109
self.start = curr
105110
self.touchpad_down = curr
@@ -229,7 +234,7 @@ def produce(self, fds: Sequence[int]) -> Sequence[Event]:
229234
"weak_magnitude": right / (2**16 - 1),
230235
}
231236
)
232-
case 0x8f:
237+
case 0x8F:
233238
pass
234239
case _:
235240
logger.info(
@@ -270,57 +275,42 @@ def consume(self, events: Sequence[Event]):
270275
logger.warning(
271276
f"Encoding '{ev['code']}' with {ev['value']} overflowed."
272277
)
273-
# DPAD is weird
274278
match code:
275-
case "hat_x":
276-
self.state["hat_x"] = ev["value"]
277-
# patch_dpad_val(
278-
# new_rep,
279-
# self.ofs,
280-
# self.state["hat_x"],
281-
# self.state["hat_y"],
282-
# )
283-
case "hat_y":
284-
self.state["hat_y"] = ev["value"]
285-
# patch_dpad_val(
286-
# new_rep,
287-
# self.ofs,
288-
# self.state["hat_x"],
289-
# self.state["hat_y"],
290-
# )
291279
case "gyro_ts" | "accel_ts" | "imu_ts":
292280
send = True
293281
self.last_imu = time.perf_counter()
294282
self.last_imu_ts = ev["value"]
295-
# new_rep[self.ofs + 27 : self.ofs + 31] = int(
296-
# ev["value"] / DS5_EDGE_DELTA_TIME_NS
297-
# ).to_bytes(8, byteorder="little", signed=False)[:4]
298283
case "button":
299-
if code in SD_BTN_MAP:
284+
if not self.enable_touchpad and code.startswith("touchpad"):
285+
continue
286+
if code == "touchpad_touch":
287+
self.touchpad_touch = ev["value"]
288+
if not self.touchpad_left:
289+
set_button(
290+
new_rep,
291+
SD_BTN_MAP["touchpad_touch"],
292+
ev["value"] or self.touchpad_touch,
293+
)
294+
elif code == "touchpad_left":
295+
set_button(
296+
new_rep,
297+
SD_BTN_MAP["touchpad_touch"],
298+
ev["value"] or self.touchpad_touch,
299+
)
300+
set_button(
301+
new_rep,
302+
SD_BTN_MAP["touchpad_left"],
303+
ev["value"],
304+
)
305+
encode_axis(
306+
new_rep,
307+
SD_AXIS_MAP["touchpad_force"],
308+
ev["value"],
309+
)
310+
self.touchpad_left = ev["value"]
311+
elif code in SD_BTN_MAP:
300312
set_button(new_rep, SD_BTN_MAP[code], ev["value"])
301313

302-
# # Fix touchpad click requiring touch
303-
# if code == "touchpad_touch":
304-
# self.touchpad_touch = ev["value"]
305-
# if code == "touchpad_left":
306-
# set_button(
307-
# new_rep,
308-
# SD_BTN_MAP["touchpad_touch"],
309-
# ev["value"] or self.touchpad_touch,
310-
# )
311-
# # Also add right click
312-
# if code == "touchpad_right":
313-
# set_button(
314-
# new_rep,
315-
# SD_BTN_MAP["touchpad_touch"],
316-
# ev["value"] or self.touchpad_touch,
317-
# )
318-
# set_button(
319-
# new_rep,
320-
# SD_BTN_MAP["touchpad_touch2"],
321-
# ev["value"],
322-
# )
323-
324314
# If the IMU breaks, smoothly re-enable the controller
325315
failover = self.last_imu + MAX_IMU_SYNC_DELAY < curr
326316
if self.sync_gyro and failover and not self.imu_failed:

src/hhd/controller/virtual/sd/const.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
)
4949

5050
SD_AXIS_MAP = {
51+
"touchpad_x": AM((20 << 3), "u16", scale=2**14 - 2, offset=2**14),
52+
"touchpad_y": AM((22 << 3), "u16", scale=2**14 - 2, offset=2**14),
53+
"touchpad_force": AM((58 << 3), "u16", scale=2**14 - 2),
5154
"accel_x": AM((24 << 3), "i16", scale=1600, bounds=(-(2**15) + 2, 2**15 - 1)),
5255
"accel_y": AM((26 << 3), "i16", scale=-1600, bounds=(-(2**15) + 2, 2**15 - 1)),
5356
"accel_z": AM((28 << 3), "i16", scale=1600, bounds=(-(2**15) + 2, 2**15 - 1)),
@@ -89,6 +92,8 @@
8992
"dpad_right": BM((9 << 3) + 6),
9093
"dpad_up": BM((9 << 3) + 7),
9194
"ls": BM((10 << 3) + 1),
95+
"touchpad_touch": BM((10 << 3) + 3),
96+
"touchpad_left": BM((10 << 3) + 5),
9297
"extra_r2": BM((10 << 3) + 7),
9398
"rs": BM((11 << 3) + 5),
9499
"extra_r1": BM((13 << 3) + 5),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def controller_loop_xinput(
227227
debug = DEBUG_MODE
228228

229229
# Output
230-
touchpad_enable = "disabled" # conf.get("touchpad", "disabled")
230+
touchpad_enable = conf.get("touchpad", "disabled")
231231
d_producers, d_outs, d_params = get_outputs(
232232
conf["xinput"],
233233
None,

src/hhd/device/legion_go/slim/controller.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ children:
5757
hint: >-
5858
SteamOS style mapping.
5959
60-
# touchpad:
61-
# type: multiple
62-
# title: Touchpad Emulation
63-
# default: disabled
64-
# tags: [ non-essential, ordinal ]
65-
# hint: >-
66-
# Passthrough the touchpad to the controller (Dualsense only).
67-
# options:
68-
# disabled: Disabled
69-
# gamemode: Gamemode
70-
# always: Always
60+
touchpad:
61+
type: multiple
62+
title: Touchpad Emulation [ALPHA]
63+
default: disabled
64+
tags: [ non-essential, ordinal ]
65+
hint: >-
66+
Passthrough the touchpad to the controller.
67+
options:
68+
disabled: Disabled
69+
gamemode: Gamemode
70+
always: Always
7171

7272
freq:
7373
type: multiple

src/hhd/plugins/outputs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,11 @@ def get_outputs(
128128
case "sd":
129129
UInputDevice.close_cached()
130130
Dualsense.close_cached()
131+
uses_touch = touchpad == "controller" and steam_check is not False
131132
d = SteamdeckController(
132133
name="Steam Controller (HHD)",
133134
pid=0x12FF,
135+
touchpad=uses_touch
134136
)
135137
producers.append(d)
136138
consumers.append(d)

0 commit comments

Comments
 (0)