Skip to content

Commit d50e59a

Browse files
committed
update gpd win 4 gyro matrix
1 parent 2a6ee8a commit d50e59a

File tree

4 files changed

+50
-29
lines changed

4 files changed

+50
-29
lines changed

src/hhd/device/gpd/win/__init__.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,35 @@
1212
)
1313
from hhd.plugins.settings import HHDSettings
1414

15-
GPD_WMIS = {
16-
"G1618-04": "GPD Win 4",
17-
"G1617-01": "GPD Win Mini",
18-
"G1619-05": "GPD Win Max 2 2023",
15+
from .const import GPD_WIN_MAX_2_2023_MAPPINGS
16+
17+
GPD_CONFS = {
18+
"G1618-04": {"name": "GPD Win 4", "hrtimer": True},
19+
"G1617-01": {"name": "GPD Win Mini", "touchpad": True},
20+
"G1619-05": {
21+
"name": "GPD Win Max 2 2023",
22+
"hrtimer": True,
23+
"touchpad": True,
24+
"mapping": GPD_WIN_MAX_2_2023_MAPPINGS,
25+
},
1926
}
2027

21-
GPD_CONFS = {"G1619-05": {"hrtimer": True}, "G1618-04": {"hrtimer": True}}
22-
23-
GPD_TOUCHPAD = ["G1617-01", "G1619-05"]
24-
2528

2629
class GpdWinControllersPlugin(HHDPlugin):
2730
name = "gpd_win_controllers"
2831
priority = 18
2932
log = "gpdw"
3033

31-
def __init__(self, dmi: str, name: str) -> None:
34+
def __init__(self, dmi: str, dconf: dict) -> None:
3235
self.t = None
3336
self.should_exit = None
3437
self.updated = Event()
3538
self.started = False
3639
self.t = None
3740

3841
self.dmi = dmi
39-
self.name = f"gpd_win_controllers@'{name}'"
42+
self.dconf = dconf
43+
self.name = f"gpd_win_controllers@'{dconf.get('name', 'ukn')}'"
4044

4145
def open(
4246
self,
@@ -53,7 +57,7 @@ def settings(self) -> HHDSettings:
5357
get_outputs_config(can_disable=False, has_leds=False)
5458
)
5559

56-
if self.dmi in GPD_TOUCHPAD:
60+
if self.dconf.get("touchpad", False):
5761
base["controllers"]["gpd_win"]["children"][
5862
"touchpad"
5963
] = get_touchpad_config()
@@ -91,7 +95,7 @@ def start(self, conf):
9195
self.context,
9296
self.should_exit,
9397
self.updated,
94-
GPD_CONFS.get(self.dmi, {}),
98+
self.dconf,
9599
),
96100
)
97101
self.t.start()
@@ -112,8 +116,8 @@ def autodetect(existing: Sequence[HHDPlugin]) -> Sequence[HHDPlugin]:
112116
# Match just product number, should be enough for now
113117
with open("/sys/devices/virtual/dmi/id/product_name") as f:
114118
dmi = f.read().strip()
115-
name = GPD_WMIS.get(dmi)
116-
if not name:
119+
dconf = GPD_CONFS.get(dmi, None)
120+
if not dconf:
117121
return []
118122

119-
return [GpdWinControllersPlugin(dmi, name)]
123+
return [GpdWinControllersPlugin(dmi, dconf)]

src/hhd/device/gpd/win/base.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
from hhd.controller.physical.imu import CombinedImu, HrtimerTrigger
1616
from hhd.plugins import Config, Context, Emitter, get_outputs
1717

18-
from .const import GPD_TOUCHPAD_AXIS_MAP, GPD_TOUCHPAD_BUTTON_MAP
18+
from .const import (
19+
GPD_TOUCHPAD_AXIS_MAP,
20+
GPD_TOUCHPAD_BUTTON_MAP,
21+
GPD_WIN_DEFAULT_MAPPINGS,
22+
)
1923

2024
ERROR_DELAY = 1
2125
SELECT_TIMEOUT = 1
@@ -32,16 +36,6 @@
3236
TOUCHPAD_VID_2 = 0x0911
3337
TOUCHPAD_PID_2 = 0x5288
3438

35-
GPD_WIN_MAPPINGS: dict[str, tuple[Axis, str | None, float, float | None]] = {
36-
"accel_x": ("accel_z", "accel", 1, 3),
37-
"accel_y": ("accel_x", "accel", 1, 3),
38-
"accel_z": ("accel_y", "accel", 1, 3),
39-
"anglvel_x": ("gyro_x", "anglvel", 1, None),
40-
"anglvel_y": ("gyro_z", "anglvel", -1, None),
41-
"anglvel_z": ("gyro_y", "anglvel", -1, None),
42-
"timestamp": ("gyro_ts", None, 1, None),
43-
}
44-
4539
BACK_BUTTON_DELAY = 0.1
4640

4741
# /dev/input/event17 Microsoft X-Box 360 pad usb-0000:73:00.3-4.1/input0
@@ -174,7 +168,7 @@ def plugin_run(
174168
if not found_gamepad:
175169
time.sleep(ERROR_DELAY)
176170
if first:
177-
logger.warning("Controller in Mouse mode. Waiting...")
171+
logger.info("Controller in Mouse mode. Waiting...")
178172
first = False
179173
continue
180174

@@ -206,7 +200,11 @@ def controller_loop(conf: Config, should_exit: TEvent, updated: TEvent, dconf: d
206200
)
207201

208202
# Imu
209-
d_imu = CombinedImu(conf["imu_hz"].to(int), GPD_WIN_MAPPINGS, gyro_scale="0.000266")
203+
d_imu = CombinedImu(
204+
conf["imu_hz"].to(int),
205+
dconf.get("mapping", GPD_WIN_DEFAULT_MAPPINGS),
206+
# gyro_scale="0.000266", #TODO: Find what this affects
207+
)
210208
d_timer = HrtimerTrigger(conf["imu_hz"].to(int), [HrtimerTrigger.IMU_NAMES])
211209

212210
# Inputs

src/hhd/device/gpd/win/const.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,23 @@
1515
"touchpad_y": [B("ABS_Y")], # also ABS_MT_POSITION_Y
1616
}
1717
)
18+
19+
GPD_WIN_DEFAULT_MAPPINGS: dict[str, tuple[Axis, str | None, float, float | None]] = {
20+
"accel_x": ("accel_z", "accel", 1, 3),
21+
"accel_y": ("accel_x", "accel", 1, 3),
22+
"accel_z": ("accel_y", "accel", 1, 3),
23+
"anglvel_x": ("gyro_x", "anglvel", 1, None),
24+
"anglvel_y": ("gyro_z", "anglvel", -1, None),
25+
"anglvel_z": ("gyro_y", "anglvel", -1, None),
26+
"timestamp": ("gyro_ts", None, 1, None),
27+
}
28+
29+
GPD_WIN_MAX_2_2023_MAPPINGS: dict[str, tuple[Axis, str | None, float, float | None]] = {
30+
"accel_x": ("accel_z", "accel", 1, 3),
31+
"accel_y": ("accel_x", "accel", 1, 3),
32+
"accel_z": ("accel_y", "accel", 1, 3),
33+
"anglvel_x": ("gyro_z", "anglvel", 1, None),
34+
"anglvel_y": ("gyro_x", "anglvel", -1, None),
35+
"anglvel_z": ("gyro_y", "anglvel", -1, None),
36+
"timestamp": ("gyro_ts", None, 1, None),
37+
}

src/hhd/device/rog_ally/hid.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def __call__(self, dev: Device, events: Sequence[Event]):
173173
]
174174

175175
for r in cmds:
176-
logger.warning(r.hex())
177176
dev.write(r)
178177

179178

0 commit comments

Comments
 (0)