Skip to content

Commit

Permalink
fix legion go dpad passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
antheas committed May 5, 2024
1 parent ce3f4cc commit 673434a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
49 changes: 45 additions & 4 deletions src/hhd/controller/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,12 @@ def __init__(
None | Literal["guide_is_start", "guide_is_select", "select_is_guide"]
) = None,
trigger: None | Literal["analog_to_discrete", "discrete_to_analogue"] = None,
dpad: None | Literal["analog_to_discrete"] = None,
dpad: (
None
| Literal["analog_to_discrete"]
| Literal["discrete_to_analog"]
| Literal["both"]
) = None,
led: None | Literal["left_to_main", "right_to_main", "main_to_sides"] = None,
touchpad: (
None | Literal["left_to_main", "right_to_main", "main_to_sides"]
Expand Down Expand Up @@ -610,15 +615,17 @@ def process(self, events: Sequence[Event]):
}
)

if self.dpad == "analog_to_discrete" and ev["code"] in (
if (
self.dpad == "analog_to_discrete" or self.dpad == "both"
) and ev["code"] in (
"hat_x",
"hat_y",
):
out.append(
{
"type": "button",
"code": (
"dpad_up" if ev["code"] == "hat_y" else "dpad_right"
"dpad_down" if ev["code"] == "hat_y" else "dpad_right"
),
"value": ev["value"] > 0.5,
}
Expand All @@ -627,7 +634,7 @@ def process(self, events: Sequence[Event]):
{
"type": "button",
"code": (
"dpad_down"
"dpad_up"
if ev["code"] == "hat_y"
else "dpad_left"
),
Expand Down Expand Up @@ -695,6 +702,40 @@ def process(self, events: Sequence[Event]):
self.guide_pressed = ev["value"]
if ev["value"]:
self.emit({"type": "special", "event": "guide"})

if (
self.dpad == "discrete_to_analog" or self.dpad == "both"
) and ev["code"] in (
"dpad_up",
"dpad_down",
"dpad_left",
"dpad_right",
):
# FIXME: To be done properly you'd need to save the previous
# state so that if going from -1 to 1 in one go it would be
# preserved. Since this is only used for the legion go
# passthrough that is not an issue.
match ev["code"]:
case "dpad_up":
code = "hat_y"
val = -1
case "dpad_down":
code = "hat_y"
val = 1
case "dpad_right":
code = "hat_x"
val = 1
case "dpad_left":
code = "hat_x"
val = -1

out.append(
{
"type": "axis",
"code": code,
"value": ev["value"] * val,
}
)

if self.qam_button is not None and ev["code"] == self.qam_button:
ev["code"] = "" # type: ignore
Expand Down
4 changes: 2 additions & 2 deletions src/hhd/device/legion_go/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def controller_loop_rest(
)

multiplexer = Multiplexer(
dpad="analog_to_discrete",
dpad="both",
trigger="analog_to_discrete",
share_to_qam=conf["share_to_qam"].to(bool),
nintendo_mode=conf["nintendo_mode"].to(bool),
Expand Down Expand Up @@ -343,7 +343,7 @@ def controller_loop_xinput(
multiplexer = Multiplexer(
swap_guide=swap_guide,
trigger="analog_to_discrete",
dpad="analog_to_discrete",
dpad="both",
led="main_to_sides",
status="both_to_main",
share_to_qam=conf["share_to_qam"].to(bool),
Expand Down

0 comments on commit 673434a

Please sign in to comment.