import sensor from '@ohos.sensor'
let lastTime: number = 0
let lastX: number = 0
let lastY: number = 0
let lastZ: number = 0
@Entry
@Component
struct Index {
aboutToAppear(): void {
//监听加速度传感器
sensor.on(sensor.SensorId.ACCELEROMETER, (data) => {
let currentTime = new Date().getTime()
let time = currentTime - lastTime
// xyz轴加速度值
let x = data.x
let y = data.y
let z = data.z
// 计算加速度变化
let accel = Math.abs(x + y + z - lastX - lastY - lastZ) / time * 10000
}, { interval: 100000000 })
}
build() {
Column() {
}.width("100%")
.height("100%")
}
}