Skip to main content
版本:v2

Stress

API_LEVEL 2.0 开始支持,API 兼容性请参考 API_LEVEL

压力传感器。

信息

权限代码: data:user.hd.stress

方法

getCurrent

获取当前压力测量值

getCurrent(): Result

Result

属性类型说明API_LEVEL
valuenumber压力测量值2.0
timenumber得出测量值的时间2.0

onChange

注册压力测量值变化事件监听回调函数

onChange(callback: () => void): void

offChange

取消压力测量值变化事件监听回调函数

offChange(callback: () => void): void

代码示例

import { Stress } from '@zos/sensor'

const stress = new Stress()
const { value } = stress.getCurrent()

const callback = () => {
console.log(stress.getCurrent())
}

stress.onChange(callback)

// When not needed for use
stress.offChange(callback)