Skip to content

fix(input): use nanoseconds for device sensor intervals - #123

Merged
qiin2333 merged 1 commit into
masterfrom
codex/fix-sensor-report-interval
Aug 24, 2026
Merged

fix(input): use nanoseconds for device sensor intervals#123
qiin2333 merged 1 commit into
masterfrom
codex/fix-sensor-report-interval

Conversation

@qiin2333

@qiin2333 qiin2333 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 把设备陀螺仪和加速度计订阅的 interval 按纳秒计算
  • 保留 200 Hz 上限,对应 Sensor Service Kit 支持的 5 ms 最小间隔
  • 日志字段同步改成 ns,省得以后又被这个杂鱼单位骗到啦

为啥要改

HarmonyOS Sensor Service Kit 的数值型 interval 单位是纳秒;原实现却按微秒计算。比如请求 100 Hz 时,原来传入的是 10,000 ns,而正确值应为 10,000,000 ns,差了 1000 倍。

官方示例也以 100,000,000 ns 表示 100 ms,并说明常见支持范围为 5,000,000–200,000,000 ns:
https://gitee.com/openharmony/docs/blob/30904d2051d468bd681b08da17cbc6e87a77dbf1/en/application-dev/device/sensor-guidelines.md

本 PR 不改运动数据协议单位:陀螺仪仍从 rad/s 转成 deg/s,加速度计仍以 m/s² 发送。也不偷偷加死区或自动校准,免得把真实的慢速动作一起吃掉,哼。

验证

  • npm run check
  • node hvigorw.js assembleApp --mode project -p product=default -p buildMode=debug --no-daemon --stacktrace(unsigned,BUILD SUCCESSFUL)

Summary by CodeRabbit

  • 改进
    • 优化陀螺仪和加速度计的传感器采样间隔计算,提升高频采样场景下的计时精度。
    • 统一使用纳秒(ns)作为采样间隔单位,并同步更新相关状态日志。
    • 保持传感器数据转换、去重、方向校正及事件分发行为不变。

@coderabbitai

coderabbitai Bot commented Aug 24, 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 Plus

Run ID: 9827f23f-f0a7-4847-9c6d-350592de667b

📥 Commits

Reviewing files that changed from the base of the PR and between 1b2d5ae and a754e44.

📒 Files selected for processing (1)
  • entry/src/main/ets/service/input/DeviceSensorService.ets

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

DeviceSensorService 将陀螺仪和加速度计的采样间隔单位从微秒改为纳秒。间隔计算继续限制为最高 200 Hz。订阅参数和启用日志同步使用纳秒单位。

Changes

传感器采样间隔更新

Layer / File(s) Summary
纳秒间隔计算
entry/src/main/ets/service/input/DeviceSensorService.ets
新增纳秒换算常量和 200 Hz 上限。陀螺仪与加速度计按纳秒计算采样间隔。
传感器订阅应用
entry/src/main/ets/service/input/DeviceSensorService.ets
陀螺仪与加速度计的 sensor.on 使用纳秒间隔。启用日志将单位从 us 改为 ns

Estimated code review effort: 1 (简单) | ~5 分钟

Merge Risk: ⚪ Minimal · up to a754e

This localized change updates sensor interval calculations and related logging; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了将设备传感器采样间隔改为纳秒的主要变更,内容清晰且具体。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-sensor-report-interval

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.

@qiin2333
qiin2333 merged commit 1e110f6 into master Aug 24, 2026
2 checks passed
@qiin2333
qiin2333 deleted the codex/fix-sensor-report-interval branch August 24, 2026 15:44
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