Skip to content

Repository files navigation

InertialKit

InertialKit 是一个面向 macOS 的 Swift SDK 项目,用于读取兼容 Mac 笔记本的内置加速度计和陀螺仪,并获取线性加速度、角速度与机身姿态

Important

Mac 运动传感器不是公开、稳定的系统能力,兼容性可能因机型和系统版本而异。 使用时需要具备 root 权限,且不支持 App Sandbox 运行模式

使用

Xcode

  1. 选择 File > Add Package Dependencies…

  2. 输入仓库地址

    https://github.com/bob-zebedy/InertialKit.git
    
  3. Dependency Rule 选择 Exact Version 填写对应的 Tag 版本

  4. InertialKit 添加到对应的 macOS target

Package.swift

Package.swift 的依赖列表中添加以下包

dependencies: [
    .package(
        url: "https://github.com/bob-zebedy/InertialKit.git",
        exact: "x.x.x"
    )
]

然后在对应的 target 中引用

dependencies: [
    .product(name: "InertialKit", package: "InertialKit")
]

快速使用

在支持 async throws 的上下文中读取当前运动数据

import InertialKit

let monitor = MotionMonitor()
let sample = try await monitor.sample()

print(sample.linearAcceleration)
print(sample.rotationRate)
print(sample.attitude)

使用指南

使用、兼容性、配置、完整 API 及错误处理请参阅 使用指南

About

用于读取兼容 Mac 的加速度计、陀螺仪、姿态与采样频率数据的 Swift SDK。

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages