Skip to content

Commit d56bf6a

Browse files
committed
multiplexer: add left touchpad short/long press support
1 parent 732a4d4 commit d56bf6a

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

src/hhd/controller/base.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ def __init__(
627627
self.touchpad_x = 0
628628
self.touchpad_y = 0
629629
self.touchpad_down = None
630+
self.left_touchpad_x = 0
631+
self.left_touchpad_y = 0
632+
self.left_touchpad_down = None
630633
self.queue: list[tuple[Event | Literal["reboot"], float]] = []
631634
self.reboot_pressed = None
632635
self.select_is_held = False
@@ -685,6 +688,7 @@ def process(self, events: Sequence[Event]) -> Sequence[Event]:
685688
out: list[Event] = []
686689
status_events = set()
687690
touched = False
691+
left_touched = False
688692
send_steam_qam = False
689693
send_steam_expand = False
690694

@@ -789,6 +793,45 @@ def process(self, events: Sequence[Event]) -> Sequence[Event]:
789793
):
790794
self.touchpad_down[3] = False
791795

796+
# Left touchpad hold detection
797+
if (
798+
self.touchpad_hold != "disabled"
799+
and self.left_touchpad_down
800+
and self.left_touchpad_down[3]
801+
and curr - self.left_touchpad_down[0] > 0.8
802+
):
803+
action = (
804+
"touchpad_left"
805+
if self.touchpad_hold == "left_click"
806+
else "touchpad_right"
807+
)
808+
self.queue.append(
809+
(
810+
{
811+
"type": "button",
812+
"code": action,
813+
"value": True,
814+
},
815+
curr,
816+
)
817+
)
818+
self.queue.append(
819+
(
820+
{
821+
"type": "button",
822+
"code": action,
823+
"value": False,
824+
},
825+
curr + self.QAM_DELAY,
826+
)
827+
)
828+
self.left_touchpad_down = None
829+
elif self.left_touchpad_down and (
830+
abs(self.left_touchpad_down[1] - self.left_touchpad_x) > 0.13
831+
or abs(self.left_touchpad_down[2] - self.left_touchpad_y) > 0.13
832+
):
833+
self.left_touchpad_down[3] = False
834+
792835
for ev in events:
793836
match ev["type"]:
794837
case "axis":
@@ -923,6 +966,10 @@ def process(self, events: Sequence[Event]) -> Sequence[Event]:
923966
self.touchpad_x = ev["value"]
924967
if ev["code"] == "touchpad_y":
925968
self.touchpad_y = ev["value"]
969+
if ev["code"] == "left_touchpad_x":
970+
self.left_touchpad_x = ev["value"]
971+
if ev["code"] == "left_touchpad_y":
972+
self.left_touchpad_y = ev["value"]
926973
case "button":
927974
if self.trigger == "discrete_to_analog" and ev["code"] in (
928975
"lt",
@@ -1284,6 +1331,47 @@ def process(self, events: Sequence[Event]) -> Sequence[Event]:
12841331
self.touchpad_down = None
12851332
# append A after QAM_DELAY s
12861333

1334+
# Left touchpad short press detection
1335+
if ev["code"] == "left_touchpad_touch":
1336+
if (
1337+
self.touchpad_short != "disabled"
1338+
and not ev["value"]
1339+
and self.left_touchpad_down
1340+
and curr - self.left_touchpad_down[0] < 0.2
1341+
and abs(self.left_touchpad_down[1] - self.left_touchpad_x) < 0.04
1342+
and abs(self.left_touchpad_down[2] - self.left_touchpad_y) < 0.04
1343+
):
1344+
action = (
1345+
"touchpad_left"
1346+
if self.touchpad_short == "left_click"
1347+
else "touchpad_right"
1348+
)
1349+
self.queue.append(
1350+
(
1351+
{
1352+
"type": "button",
1353+
"code": action,
1354+
"value": True,
1355+
},
1356+
curr,
1357+
)
1358+
)
1359+
self.queue.append(
1360+
(
1361+
{
1362+
"type": "button",
1363+
"code": action,
1364+
"value": False,
1365+
},
1366+
curr + self.QAM_DELAY,
1367+
)
1368+
)
1369+
1370+
if ev["value"]:
1371+
left_touched = True
1372+
else:
1373+
self.left_touchpad_down = None
1374+
12871375
if self.r3_to_share and ev["code"] == "extra_r3":
12881376
ev["code"] = "share"
12891377

@@ -1372,6 +1460,14 @@ def process(self, events: Sequence[Event]) -> Sequence[Event]:
13721460
bool(True),
13731461
]
13741462

1463+
if left_touched:
1464+
self.left_touchpad_down = [
1465+
curr,
1466+
self.left_touchpad_x,
1467+
self.left_touchpad_y,
1468+
bool(True),
1469+
]
1470+
13751471
for s in status_events:
13761472
match s:
13771473
case "battery":

0 commit comments

Comments
 (0)