Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@vmosedge/sensor-simulator

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vmosedge/sensor-simulator

Android Sensor Simulator SDK - Accelerometer, Gyroscope, Magnetometer calculation based on official Android formulas

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

@vmosedge/sensor-simulator

Android 传感器模拟器 SDK,用于在浏览器或 Node 环境中根据旋转/位移输入计算传感器数据。

安装

npm install @vmosedge/sensor-simulator
# or
pnpm add @vmosedge/sensor-simulator

快速使用

import { SensorSimulator, DeviceOrientation } from '@vmosedge/sensor-simulator'

const simulator = new SensorSimulator()

// 监听数据变化
simulator.on('change', (sensors) => {
  console.log('accelerometer', sensors.accelerometer)
  console.log('gyroscope', sensors.gyroscope)
  console.log('magnetometer', sensors.magnetometer)
})

// 设置旋转角度 (度)
simulator.setRotation({ x: 10, y: 20, z: 30 })

// 设置设备方向 (0/90/180/270)
simulator.setDeviceOrientation(DeviceOrientation.LANDSCAPE_LEFT)

旋转模式 (Rotate)

// X: Pitch, Y: Roll, Z: Yaw (单位: 度)
simulator.setRotation({
  x: 15,
  y: -10,
  z: 45
})

移动模式 (Move)

// 位移 (单位: m)
simulator.setPosition({
  x: 1.5,
  y: 0.5,
  z: -0.3
})

// 需要在动画循环中调用 update 处理线性加速度衰减
let last = performance.now()
const animate = () => {
  const now = performance.now()
  const deltaSeconds = (now - last) / 1000
  last = now
  simulator.update(deltaSeconds)
  requestAnimationFrame(animate)
}

animate()

设备方向

simulator.setDeviceOrientation(DeviceOrientation.PORTRAIT)
simulator.setDeviceOrientation(DeviceOrientation.LANDSCAPE_LEFT)
simulator.setDeviceOrientation(DeviceOrientation.PORTRAIT_REVERSE)
simulator.setDeviceOrientation(DeviceOrientation.LANDSCAPE_RIGHT)

数据单位

  • rotation: 度 (deg)
  • position: 米 (m)
  • accelerometer: m/s^2
  • gyroscope: rad/s
  • magnetometer: uT
  • rotationVector: 四元数

可选配置

const simulator = new SensorSimulator({
  gravity: 9.80665,
  magneticField: { x: 0, y: 5.9, z: -48.4 },
  linearDecaySeconds: 0.08,
  maxLinearAccel: 34.3,
  linearEpsilon: 0.01
})

说明

SDK 仅负责传感器数值计算,不包含网络请求与 UI 渲染。

Keywords

sensor

FAQs

Package last updated on 23 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts