Skip to content

fix(controller): align device events and hvigor version#42

Merged
qiin2333 merged 3 commits into
masterfrom
codex/fix-controller-hvigor-build
Jun 18, 2026
Merged

fix(controller): align device events and hvigor version#42
qiin2333 merged 3 commits into
masterfrom
codex/fix-controller-hvigor-build

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 补齐控制器初始枚举事件里的 product/version/physicalAddress/deviceType,和刷新、热插拔路径保持一致
  • 控制器测试页识别 axisType=2 的 D-pad 轴事件,避免测试页和串流页显示/行为对不上
  • 将 Hvigor 依赖从 6.24.1 对齐到 DevEco 当前 6.24.2,别再让旧缓存小菜鸡混进来了

为啥要改

  • 初始枚举少字段会让同一只蓝牙控制器在测试页和 stream 路径中看起来像不同设备状态
  • D-pad 轴类事件之前只在部分路径被处理,测试页观察结果容易偏差
  • 本机 DevEco/Hvigor 是 6.24.2,项目锁 6.24.1 会触发 Hvigor 插件/根节点加载不一致

验证

  • git diff --check
  • clang++ --target=aarch64-linux-ohos --sysroot=/Applications/DevEco-Studio.app/Contents/sdk/default/openharmony/native/sysroot -D__OHOS__ -std=c++17 -I nativelib/src/main/cpp -fsyntax-only nativelib/src/main/cpp/game_controller_native.cpp
  • NODE_PATH="$PWD/node_modules" DEVECO_SDK_HOME="/Applications/DevEco-Studio.app/Contents/sdk" OHOS_BASE_SDK_HOME="/Applications/DevEco-Studio.app/Contents/sdk/default/openharmony" JAVA_HOME="/Applications/DevEco-Studio.app/Contents/jbr/Contents/Home" PATH="/Applications/DevEco-Studio.app/Contents/jbr/Contents/Home/bin:$PATH" bash hvigorw --stacktrace --mode module -p module=entry assembleHap --no-daemon

备注:没有把本机路径写进 hvigorw,这些只是本机验证环境变量。

Summary by CodeRabbit

发行说明

  • Bug Fixes
    • 改进游戏手柄 D-Pad 的按钮位映射:根据手柄方向输入更准确更新上/下/左/右状态。
    • 完善设备连接初始化流程:在设备首次登记时补充并同步产品、版本、物理地址与设备类型等元数据,避免设备信息不完整或异常。

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f24fc1bf-90c2-4668-926b-bc99bd7d3ad1

📥 Commits

Reviewing files that changed from the base of the PR and between 41189f4 and 935b344.

📒 Files selected for processing (1)
  • nativelib/src/main/cpp/game_controller_native.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • nativelib/src/main/cpp/game_controller_native.cpp

📝 Walkthrough

Walkthrough

ArkTS 测试视图新增 MoonlightButton 导入,在 D-Pad 轴事件分支中补充位运算逻辑(清除掩码后按阈值设置方向位)。C++ 层在 GameController_StartMonitor 模拟设备上线时补全 productversionphysicalAddressdeviceType 等元数据的采集与写入,并在 OnDeviceChangedGameController_RefreshDevices 中对 deviceType 变量进行显式初始化。

Changes

手柄 D-Pad 状态与设备信息初始化

Layer / File(s) Summary
D-Pad 轴事件到按钮位映射
entry/src/main/ets/components/test/GameControllerTestView.ets
新增 MoonlightButton 导入;在 handleAxisEventaxisType === 2 分支中,先清除 DPAD_MASK,再依据 x/y 轴阈值(±0.5)设置对应方向按钮位。
设备元数据采集与初始化安全
nativelib/src/main/cpp/game_controller_native.cpp
GameController_StartMonitor 模拟设备上线时补全 productversionphysicalAddressdeviceType 字段的采集与赋值;在 OnDeviceChangedGameController_RefreshDevices 中补充 deviceType 变量的显式初始化为 0。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确概括了主要改动:修复设备事件对齐问题和更新Hvigor版本。标题清晰具体,符合单句简洁的要求。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-controller-hvigor-build

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nativelib/src/main/cpp/game_controller_native.cpp`:
- Around line 1024-1026: The variable deviceType is declared without
initialization before being passed to OH_GameDevice_DeviceInfo_GetDeviceType. If
the API call fails or behaves unexpectedly, this uninitialized variable would
result in undefined values being assigned to info.deviceType. Initialize the
deviceType variable to a default value (such as 0) at the point of declaration
to ensure a known state. Apply this fix in all three locations where this
pattern occurs: around line 1024 in the primary location, and also at the
similar code sections around lines 458 and 1190.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f61c2592-76de-4bdd-bfec-ad55dad09738

📥 Commits

Reviewing files that changed from the base of the PR and between bcbe26f and 41189f4.

⛔ Files ignored due to path filters (2)
  • hvigor/hvigor-config.json5 is excluded by !hvigor/**
  • hvigor/package.json is excluded by !hvigor/**
📒 Files selected for processing (2)
  • entry/src/main/ets/components/test/GameControllerTestView.ets
  • nativelib/src/main/cpp/game_controller_native.cpp

Comment thread nativelib/src/main/cpp/game_controller_native.cpp Outdated
@qiin2333 qiin2333 merged commit 8babf16 into master Jun 18, 2026
2 checks passed
@qiin2333 qiin2333 deleted the codex/fix-controller-hvigor-build branch June 18, 2026 06:20
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