|
3 | 3 | from collections import defaultdict |
4 | 4 | from typing import Sequence, cast |
5 | 5 |
|
6 | | -from hhd.controller import Consumer, Event, Producer |
| 6 | +from hhd.controller import ( |
| 7 | + Consumer, |
| 8 | + Event, |
| 9 | + Producer, |
| 10 | +) |
7 | 11 | from hhd.controller.lib.uhid import UhidDevice, BUS_USB |
8 | 12 | from hhd.controller.lib.common import encode_axis, set_button |
9 | 13 | from hhd.controller.lib.ccache import ControllerCache |
@@ -100,6 +104,7 @@ def open(self) -> Sequence[int]: |
100 | 104 | self.state: dict = defaultdict(lambda: 0) |
101 | 105 | self.rumble = False |
102 | 106 | self.touchpad_touch = False |
| 107 | + self.touchpad_left = False |
103 | 108 | curr = time.perf_counter() |
104 | 109 | self.start = curr |
105 | 110 | self.touchpad_down = curr |
@@ -229,7 +234,7 @@ def produce(self, fds: Sequence[int]) -> Sequence[Event]: |
229 | 234 | "weak_magnitude": right / (2**16 - 1), |
230 | 235 | } |
231 | 236 | ) |
232 | | - case 0x8f: |
| 237 | + case 0x8F: |
233 | 238 | pass |
234 | 239 | case _: |
235 | 240 | logger.info( |
@@ -270,57 +275,42 @@ def consume(self, events: Sequence[Event]): |
270 | 275 | logger.warning( |
271 | 276 | f"Encoding '{ev['code']}' with {ev['value']} overflowed." |
272 | 277 | ) |
273 | | - # DPAD is weird |
274 | 278 | 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 | | - # ) |
291 | 279 | case "gyro_ts" | "accel_ts" | "imu_ts": |
292 | 280 | send = True |
293 | 281 | self.last_imu = time.perf_counter() |
294 | 282 | 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] |
298 | 283 | 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: |
300 | 312 | set_button(new_rep, SD_BTN_MAP[code], ev["value"]) |
301 | 313 |
|
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 | | - |
324 | 314 | # If the IMU breaks, smoothly re-enable the controller |
325 | 315 | failover = self.last_imu + MAX_IMU_SYNC_DELAY < curr |
326 | 316 | if self.sync_gyro and failover and not self.imu_failed: |
|
0 commit comments