Skip to content

feat(input): auto-detect Betop Zeus NS mode on macOS with calibrated HID stick fallback - #2393

Open
Ting2024 wants to merge 1 commit into
ly05010419:mainfrom
Ting2024:feat/betop-ns-mode-mac
Open

Ting2024 wants to merge 1 commit into
ly05010419:mainfrom
Ting2024:feat/betop-ns-mode-mac

Conversation

@Ting2024

Copy link
Copy Markdown
## Summary
在 macOS 上自动识别蓝牙 NS 模式的北通宙斯手柄(`057E:2009`,`Transport=Bluetooth`,蓝牙 MAC 前缀
`00:90:E0`),并通过其 HID `0x30` 完整报告与 SPI
摇杆校准参数直接补齐左摇杆输入,无需改动设置面板或按键映射,也不依赖用户开启陀螺仪或 HID 震动。

Auto-detects Betop Zeus controllers in Nintendo Switch mode on macOS (`057E:2009`,
`Transport=Bluetooth`, Bluetooth MAC prefix `00:90:E0`) and supplies calibrated left-stick input
from HID `0x30` reports without changing controller settings UI or requiring gyro/HID rumble to
be enabled.

## Problem
在 macOS 上通过蓝牙连接的北通宙斯 NS 模式手柄虽然能被 `GameController` 枚举为 `Switch Pro
Controller`,但其 `leftThumbstick` 轴输出长期为 0(实测采自 macOS 27.2.1,详见实机 HID
读数:三只手柄均上报 `057E:2009`、蓝牙地址前缀 `00:90:E0`、无厂商字段,但原始 `0x30`
报告中带有完整 12-bit 摇杆读数及出厂摇杆校准)。
此前已有的 `SwitchLeftFallback` 仅在开启 HID 体感流时挂载,且需要推杆超过 `0.5` 并持续 `200 ms`
才接管,导致轻推或菜单短拨失效,同时按 `2048` 名义中心/行程换算未读取手柄校准数据。

## Changes
- **`shared/runtime/switch_left_fallback.h`**
  - 新增纯 C 辅助函数 `betop_ns_match()`(匹配 `057E:2009` + `Bluetooth` + `00:90:E0`
  地址前缀)、`SwitchStickCal` 及 Switch Pro 9 字节左右摇杆 SPI
  校准解析(`switch_stick_cal_parse_left` / `switch_stick_cal_parse_right` /
  `switch_stick_cal_axis`)。
  - 为 `SwitchLeftFallback` 增加可选校准与 `immediate` 标志(零初始化保持与原有 200 ms
  兜底逻辑完全兼容;启用 `immediate` 且系统原生左摇杆仍为 0
  时首帧即生效,一旦原生摇杆有非零输入即立即退让)。
- **`shared/runtime/gamepad_core.h`**
  - 新增 `runtime_gamepad_switch_left_config` / `runtime_gamepad_switch_right_config`,供 HID
  反馈层配置 `immediate` 与 SPI 校准参数。
- **`shared/runtime/gamepad_feedback.m`**(仅 `#if TARGET_OS_OSX`,iOS 为空桩)
  - 通过 `GCHIDInformation` / `IOHIDServiceClient` 反查 `GCController` 对应的物理 `IOHIDDevice`
  IORegistry ID,避免匹配到 `GCSyntheticDevice` 并在连接多个手柄时精准绑定物理设备。
  - 在 `runtime_feedback_attach` 独立挂载 `hid_betop_attach`(不受 `TOTK_GYRO=0` /
  `TOTK_RUMBLE=0` 影响),按间隔发送 `0x03 0x30` 与 SPI 校准读取请求(出厂 `0x603D` / 用户
  `0x8010`),并将 `0x30` 摇杆与截屏键事件喂给 `runtime_gamepad_switch_*`。
- **`tests/test_betop_ns.c` & `Makefile` & `games/totk/tests/dsu/native_motion.m`**
  - 新增 `betop_ns` C 单元测试(含真实采集的北通宙斯校准参数用例)并加入 `make check-c`。

## How this was tested
- **macOS(代码检查与单测,尚未接实体手柄在游戏内试玩)**:
  - `make check-c`(`-fsanitize=undefined`):全部 15 项 C 单元测试通过(含新增 `betop_ns`)。
  - `python3.14 -m unittest discover -s tests -p 'test_switch_left_fallback.py' -v`:2/2 通过。
  - `python3.14 -m unittest discover -s tests -p 'test_dsu.py' -v`:5/5 通过(含
  `test_native_motion_coexistence`、`test_settings_ui`、`test_udp_and_gamepad`)。
  - `xcrun clang -fsyntax-only`(`-Wall -Wextra -Werror`):通过链接 `shared/runtime/` 的 9 款
  macOS
  目标(`totk`、`oot`、`odyssey`、`acnh`、`eow`、`mk8dx`、`p5r`、`aocx`、`w3`)语法编译检查。
  - 待测:需要在接有实体北通宙斯 NS 模式手柄的 Mac
  上进游戏确认左摇杆行程、零偏校准与双人热插拔表现(前序硬件 HID 读数采集于 macOS 27.2.1)。
- **iOS(仅编译语法检查,功能不涉及 iOS)**:
  - `test_dsu.py::test_shared_sources_build_for_ios` 及 `xcrun --sdk iphoneos / iphonesimulator
  clang -fsyntax-only` 检查 `totk` 与 `oot` 的 `gamepad.m` / `gamepad_feedback.m` 通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant