Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CDL_LuFei
Docs
提交
25aedacc
D
Docs
项目概览
CDL_LuFei
/
Docs
与 Fork 源项目一致
Fork自
OpenHarmony / Docs
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
25aedacc
编写于
11月 08, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 08, 2022
浏览文件
操作
浏览文件
下载
差异文件
!11298 update docs
Merge pull request !11298 from HYH/master
上级
2167df99
81f22a2f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
1051 addition
and
819 deletion
+1051
-819
zh-cn/application-dev/reference/apis/js-apis-sensor.md
zh-cn/application-dev/reference/apis/js-apis-sensor.md
+1051
-819
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-sensor.md
浏览文件 @
25aedacc
# 传感器
sensor模块提供订阅传感器数据基本能力,包括订阅、取消订阅传感器数据,获取传感器列表,以及通用的传感器算法接口如通过气压值计算海拔高度、通过旋转矩阵计算设备方向等。
传感器是指用于侦测环境中所发生事件或变化,并将此消息发送至其他电子设备(如中央处理器)的设备,通常由敏感组件和转换组件组成。传感器是实现物联网智能化的重要基石,为实现全场景智慧化战略,支撑“1+8+N”产品需求,需要构筑统一的传感器管理框架,达到为各产品/业务提供低时延、低功耗的感知数据的目的。根据用途可分为以下六大类:
-
运动类:加速度、陀螺仪、重力、线性加速度传感器等
-
姿态类:旋转矢量、方向传感器等
-
环境类:磁力计、气压、湿度传感器等
-
光线类:环境光、接近光、色温传感器等
-
健康类:心率、心跳传感器等
-
其它:霍尔传感器、手握传感器等
sensor模块提供了获取传感器数据的能力,包括获取传感器属性列表,订阅传感器数据,以及一些通用的传感器算法。
> **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
...
...
@@ -27,9 +18,9 @@ import sensor from '@ohos.sensor';
on(type: SensorId.ACCELEROMETER, callback: Callback
<
AccelerometerResponse
>
,options?: Options): void
订阅加速度
计
传感器数据。
订阅加速度传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER
**需要权限**
:ohos.permission.ACCELEROMETER
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -37,9 +28,9 @@ on(type: SensorId.ACCELEROMETER, callback: Callback<AccelerometerResponse>
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的加速度传感器类型为 ACCELEROMETER。
|
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 |
注册加速度传感器的回调函数,上报的数据类型
为AccelerometerResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.ACCELEROMETER。
|
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为AccelerometerResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -53,13 +44,13 @@ on(type: SensorId.ACCELEROMETER, callback: Callback<AccelerometerResponse>
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER
,
function
(
data
)
{
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -67,7 +58,7 @@ try {
on(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback
<
AccelerometerUncalibratedResponse
>
,options?: Options): void
订阅未校准
的加速度计
传感器数据。
订阅未校准
加速度
传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER
...
...
@@ -77,9 +68,9 @@ on(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback<Acceleromete
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的未校准加速度传感器类型为
ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 |
注册未校准加速度计传感器的回调函数,上报的数据类型
为AccelerometerUncalibratedResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为AccelerometerUncalibratedResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -93,16 +84,16 @@ on(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback<Acceleromete
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER_UNCALIBRATED
,
function
(
data
)
{
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -118,9 +109,9 @@ on(type: SensorId.AMBIENT_LIGHT, callback: Callback<LightResponse>, option
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ----------------------------------------------------------- |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的环境光传感器类型为
AMBIENT_LIGHT。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 |
注册环境光传感器的回调函数,上报的数据类型
为LightResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
AMBIENT_LIGHT。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为LightResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -134,11 +125,11 @@ on(type: SensorId.AMBIENT_LIGHT, callback: Callback<LightResponse>, option
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
AMBIENT_LIGHT
,
function
(
data
)
{
console
.
info
(
'
Illumination
:
'
+
data
.
intensity
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
AMBIENT_LIGHT
,
function
(
data
)
{
console
.
info
(
'
The ambient light intensity
:
'
+
data
.
intensity
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -146,7 +137,7 @@ try {
on(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback
<
AmbientTemperatureResponse
>
,options?: Options): void
订阅
环境
温度传感器数据。
订阅温度传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -154,9 +145,9 @@ on(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback<AmbientTemperatureR
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的环境温度传感器类型为
AMBIENT_TEMPERATURE。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 |
注册环境温度传感器的回调函数,上报的数据类型
为AmbientTemperatureResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
AMBIENT_TEMPERATURE。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为AmbientTemperatureResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -170,11 +161,11 @@ on(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback<AmbientTemperatureR
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
AMBIENT_TEMPERATURE
,
function
(
data
)
{
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
AMBIENT_TEMPERATURE
,
function
(
data
)
{
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -190,9 +181,9 @@ on(type: SensorId.BAROMETER, callback: Callback<BarometerResponse>, option
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的气压计传感器类型为
BAROMETER。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 |
注册气压计传感器的回调函数,上报的数据类型
为BarometerResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
BAROMETER。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为BarometerResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -206,11 +197,11 @@ on(type: SensorId.BAROMETER, callback: Callback<BarometerResponse>, option
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
BAROMETER
,
function
(
data
)
{
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
BAROMETER
,
function
(
data
)
{
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -226,9 +217,9 @@ on(type: SensorId.GRAVITY, callback: Callback<GravityResponse>,options?: O
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的重力传感器类型为
GRAVITY。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 |
注册重力传感器的回调函数,上报的数据类型
为GravityResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
GRAVITY。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为GravityResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -242,13 +233,13 @@ on(type: SensorId.GRAVITY, callback: Callback<GravityResponse>,options?: O
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
GRAVITY
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
GRAVITY
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -266,9 +257,9 @@ on(type: SensorId.GYROSCOPE, callback: Callback<GyroscopeResponse>,options
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的陀螺仪传感器类型为
GYROSCOPE。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 |
返回注册陀螺仪传感器的回调函数,上报的数据类型
为GyroscopeResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
GYROSCOPE。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为GyroscopeResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -282,13 +273,13 @@ on(type: SensorId.GYROSCOPE, callback: Callback<GyroscopeResponse>,options
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
GYROSCOPE
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
GYROSCOPE
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -297,7 +288,7 @@ try {
on(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback
<
GyroscopeUncalibratedResponse
>
,
options?: Options): void
订阅未
经校准的
陀螺仪传感器数据
订阅未
校准
陀螺仪传感器数据
**需要权限**
:ohos.permission.GYROSCOPE
...
...
@@ -307,9 +298,9 @@ on(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback<GyroscopeUncalib
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的未校准陀螺仪传感器类型为
GYROSCOPE_UNCALIBRATED。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 |
注册未校准陀螺仪传感器的回调函数,上报的数据类型
为GyroscopeUncalibratedResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
GYROSCOPE_UNCALIBRATED。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为GyroscopeUncalibratedResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -323,16 +314,16 @@ on(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback<GyroscopeUncalib
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
GYROSCOPE_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
GYROSCOPE_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -348,9 +339,9 @@ on(type: SensorId.HALL, callback: Callback<HallResponse>, options?: Option
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的霍尔传感器类型为
HALL。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 |
注册霍尔传感器的回调函数,上报的数据类型为
HallResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
HALL。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定为
HallResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -364,11 +355,11 @@ on(type: SensorId.HALL, callback: Callback<HallResponse>, options?: Option
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
HALL
,
function
(
data
)
{
console
.
info
(
'
S
tatus:
'
+
data
.
status
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
HALL
,
function
(
data
)
{
console
.
info
(
'
Hall s
tatus:
'
+
data
.
status
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -386,9 +377,9 @@ on(type: SensorId.HEART_RATE, callback: Callback<HeartRateResponse>,option
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的心率传感器类型为
HEART_RATE。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 |
注册一次心率传感器的回调函数,上报的数据类型
为HeartRateResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
HEART_RATE。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为HeartRateResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -402,11 +393,11 @@ on(type: SensorId.HEART_RATE, callback: Callback<HeartRateResponse>,option
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
HEART_RATE
,
function
(
data
)
{
sensor
.
on
(
sensor
.
SensorId
.
HEART_RATE
,
function
(
data
)
{
console
.
info
(
'
Heart rate:
'
+
data
.
heartRate
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -422,9 +413,9 @@ on(type: SensorId.HUMIDITY, callback: Callback<HumidityResponse>,options?:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的湿度传感器类型为
HUMIDITY。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 |
注册湿度传感器的回调函数,上报的数据类型
为HumidityResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
HUMIDITY。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为HumidityResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -438,11 +429,11 @@ on(type: SensorId.HUMIDITY, callback: Callback<HumidityResponse>,options?:
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
HUMIDITY
,
function
(
data
)
{
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
HUMIDITY
,
function
(
data
)
{
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -461,9 +452,9 @@ on(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback<LinearAcceleromete
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的线性加速度传感器类型为
LINEAR_ACCELEROMETER。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 |
注册线性加速度传感器的回调函数,上报的数据类型
为LinearAccelerometerResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
LINEAR_ACCELEROMETER。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为LinearAccelerometerResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -477,13 +468,13 @@ on(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback<LinearAcceleromete
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
LINEAR_ACCELEROMETER
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
LINEAR_ACCELEROMETER
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -491,7 +482,7 @@ try {
on(type: SensorId.MAGNETIC_FIELD, callback: Callback
<
MagneticFieldResponse
>
,options?: Options): void
订阅
磁场
传感器数据。
订阅
地磁
传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -499,9 +490,9 @@ on(type: SensorId.MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的磁场传感器类型为
MAGNETIC_FIELD。 |
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 |
注册磁场传感器的回调函数,上报的数据类型
为MagneticFieldResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
MAGNETIC_FIELD。 |
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为MagneticFieldResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -515,13 +506,13 @@ on(type: SensorId.MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
MAGNETIC_FIELD
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
MAGNETIC_FIELD
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -529,7 +520,7 @@ try {
on(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback
<
MagneticFieldUncalibratedResponse
>
, options?: Options): void
订阅未校准
的磁场
传感器数据
订阅未校准
地磁
传感器数据
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -537,9 +528,9 @@ on(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback<MagneticFie
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的未校准磁场传感器类型为
MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 |
注册未校准磁场传感器的回调函数,上报的数据类型
为MagneticFieldUncalibratedResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为MagneticFieldUncalibratedResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -553,16 +544,16 @@ on(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback<MagneticFie
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
MAGNETIC_FIELD_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
MAGNETIC_FIELD_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -570,7 +561,7 @@ try {
on(type: SensorId.ORIENTATION, callback: Callback
<
OrientationResponse
>
,options?: Options): void
订阅
定
向传感器数据。
订阅
方
向传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -586,21 +577,21 @@ on(type: SensorId.ORIENTATION, callback: Callback<OrientationResponse>,opt
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的方向传感器类型为
ORIENTATION。 |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 |
注册方向传感器的回调函数,上报的数据类型
为OrientationResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ORIENTATION。 |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为OrientationResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**示例:**
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
ORIENTATION
,
function
(
data
)
{
console
.
info
(
'
The device rotates at an angle around the X axis:
'
+
data
.
bet
a
);
console
.
info
(
'
The device rotates at an angle around the Y axis:
'
+
data
.
gamm
a
);
console
.
info
(
'
The device rotates at an angle around the Z axis:
'
+
data
.
alph
a
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
ORIENTATION
,
function
(
data
)
{
console
.
info
(
'
The device rotates at an angle around the Z axis:
'
+
data
.
alph
a
);
console
.
info
(
'
The device rotates at an angle around the X axis:
'
+
data
.
bet
a
);
console
.
info
(
'
The device rotates at an angle around the Y axis:
'
+
data
.
gamm
a
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -626,19 +617,19 @@ on(type: SensorId.PEDOMETER, callback: Callback<PedometerResponse>, option
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的计步传感器类型为
PEDOMETER。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 |
注册计步传感器的回调函数,上报的数据类型
为PedometerResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
PEDOMETER。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为PedometerResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**示例:**
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
PEDOMETER
,
function
(
data
)
{
console
.
info
(
'
Steps
:
'
+
data
.
steps
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
PEDOMETER
,
function
(
data
)
{
console
.
info
(
'
Step count
:
'
+
data
.
steps
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -647,7 +638,7 @@ try {
on(type: SensorId.PEDOMETER_DETECTION, callback: Callback
<
PedometerDetectionResponse
>
,
options?: Options): void
订阅计步
器检测
传感器数据。
订阅计步
检测器
传感器数据。
**需要权限**
:ohos.permission.ACTIVITY_MOTION
...
...
@@ -657,9 +648,9 @@ on(type: SensorId.PEDOMETER_DETECTION, callback: Callback<PedometerDetectionR
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的计步检测传感器类型为
PEDOMETER_DETECTION。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 |
注册计步检测传感器的回调函数,上报的数据类型
为PedometerDetectionResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
PEDOMETER_DETECTION。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为PedometerDetectionResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -673,11 +664,11 @@ on(type: SensorId.PEDOMETER_DETECTION, callback: Callback<PedometerDetectionR
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
PEDOMETER_DETECTION
,
function
(
data
)
{
console
.
info
(
'
Scalar data
:
'
+
data
.
scalar
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
PEDOMETER_DETECTION
,
function
(
data
)
{
console
.
info
(
'
Pedometer scalar
:
'
+
data
.
scalar
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -685,7 +676,7 @@ try {
on(type: SensorId.PROXIMITY, callback: Callback
<
ProximityResponse
>
, options?: Options): void
订阅接近传感器数据。
订阅接近
光
传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -693,9 +684,9 @@ on(type: SensorId.PROXIMITY, callback: Callback<ProximityResponse>, option
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的接近光传感器类型为
PROXIMITY。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 |
注册接近光传感器的回调函数,上报的数据类型
为ProximityResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
PROXIMITY。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为ProximityResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -709,11 +700,11 @@ on(type: SensorId.PROXIMITY, callback: Callback<ProximityResponse>, option
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
PROXIMITY
,
function
(
data
)
{
console
.
info
(
'
Distance:
'
+
data
.
distance
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
PROXIMITY
,
function
(
data
)
{
console
.
info
(
'
Distance:
'
+
data
.
distance
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -730,9 +721,9 @@ on(type: SensorId.ROTATION_VECTOR, callback: Callback<RotationVectorResponse&
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的旋转矢量传感器类型为
ROTATION_VECTOR。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 |
注册旋转矢量传感器的回调函数,上报的数据类型
为RotationVectorResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ROTATION_VECTOR。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为RotationVectorResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -746,14 +737,14 @@ on(type: SensorId.ROTATION_VECTOR, callback: Callback<RotationVectorResponse&
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
ROTATION_VECTOR
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
Scalar quantity:
'
+
data
.
w
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
ROTATION_VECTOR
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
Scalar quantity:
'
+
data
.
w
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -762,7 +753,7 @@ try {
on(type: SensorId.SIGNIFICANT_MOTION, callback: Callback
<
SignificantMotionResponse
>
,
options?: Options): void
订阅
重要的运动
传感器数据。
订阅
大幅动作检测
传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -770,9 +761,9 @@ on(type: SensorId.SIGNIFICANT_MOTION, callback: Callback<SignificantMotionRes
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的大幅动作传感器类型为
SIGNIFICANT_MOTION。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 |
注册有效运动传感器的回调函数,上报的数据类型
为SignificantMotionResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
SIGNIFICANT_MOTION。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为SignificantMotionResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -786,11 +777,11 @@ on(type: SensorId.SIGNIFICANT_MOTION, callback: Callback<SignificantMotionRes
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
SIGNIFICANT_MOTION
,
function
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
SIGNIFICANT_MOTION
,
function
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -807,9 +798,9 @@ on(type: SensorId.WEAR_DETECTION, callback: Callback<WearDetectionResponse>
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要订阅的佩戴检测传感器类型为
WEAR_DETECTION。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 |
注册佩戴检测传感器的回调函数,上报的数据类型
为WearDetectionResponse。 |
| options |
[
Options
](
#options
)
| 否 |
可选参数列表,
设置上报频率,默认值为200000000ns。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
WEAR_DETECTION。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为WearDetectionResponse。 |
| options |
[
Options
](
#options
)
| 否 | 设置上报频率,默认值为200000000ns。 |
**错误码**
:
...
...
@@ -823,11 +814,11 @@ on(type: SensorId.WEAR_DETECTION, callback: Callback<WearDetectionResponse>
```
js
try
{
sensor
.
on
(
sensor
.
SensorId
.
WEAR_DETECTION
,
function
(
data
)
{
console
.
info
(
'
Wear status:
'
+
data
.
value
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
info
(
'
o
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
WEAR_DETECTION
,
function
(
data
)
{
console
.
info
(
'
Wear status:
'
+
data
.
value
);
},
{
interval
:
10000000
}
);
}
catch
(
err
)
{
console
.
error
(
'
O
n fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -837,7 +828,7 @@ try {
once(type: SensorId.ACCELEROMETER, callback: Callback
<
AccelerometerResponse
>
): void
订阅一次加速度计
传感器数据。
获取一次加速度
传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER
...
...
@@ -847,8 +838,8 @@ once(type: SensorId.ACCELEROMETER, callback: Callback<AccelerometerResponse&g
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
加速度传感器类型为
ACCELEROMETER。 |
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 |
注册一次加速度传感器的回调函数,上报的数据类型
为AccelerometerResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ACCELEROMETER。 |
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为AccelerometerResponse。 |
**错误码**
:
...
...
@@ -862,14 +853,13 @@ once(type: SensorId.ACCELEROMETER, callback: Callback<AccelerometerResponse&g
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
ACCELEROMETER
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
ACCELEROMETER
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -877,7 +867,7 @@ try {
once(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback
<
AccelerometerUncalibratedResponse
>
): void
订阅一次未校准的加速度计
传感器数据。
获取一次未校准加速度
传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER
...
...
@@ -887,8 +877,8 @@ once(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback<Accelerome
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
未校准加速度传感器类型为
ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 |
注册一次未校准加速度传感器的回调函数,上报的数据类型
为AccelerometerUncalibratedResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为AccelerometerUncalibratedResponse。 |
**错误码**
:
...
...
@@ -902,17 +892,16 @@ once(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback<Accelerome
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
ACCELEROMETER_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
ACCELEROMETER_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -920,7 +909,7 @@ try {
once(type: SensorId.AMBIENT_LIGHT, callback: Callback
<
LightResponse
>
): void
订阅环境光传感器数据一次
。
获取一次环境光传感器数据
。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -928,8 +917,8 @@ once(type: SensorId.AMBIENT_LIGHT, callback: Callback<LightResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
环境光传感器类型为
AMBIENT_LIGHT。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 |
注册一次环境光传感器的回调函数,上报的数据类型
为LightResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
AMBIENT_LIGHT。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为LightResponse。 |
**错误码**
:
...
...
@@ -943,12 +932,11 @@ once(type: SensorId.AMBIENT_LIGHT, callback: Callback<LightResponse>): voi
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
AMBIENT_LIGHT
,
function
(
data
)
{
console
.
info
(
'
Illumination:
'
+
data
.
intensity
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
AMBIENT_LIGHT
,
function
(
data
)
{
console
.
info
(
'
The ambient light intensity:
'
+
data
.
intensity
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -956,7 +944,7 @@ try {
once(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback
<
AmbientTemperatureResponse
>
): void
一次订阅环境
温度传感器数据。
获取一次
温度传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -964,8 +952,8 @@ once(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback<AmbientTemperatur
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
环境温度传感器类型为
AMBIENT_TEMPERATURE。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 |
注册一次环境温度传感器的回调函数,上报的数据类型
为AmbientTemperatureResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
AMBIENT_TEMPERATURE。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为AmbientTemperatureResponse。 |
**错误码**
:
...
...
@@ -979,12 +967,11 @@ once(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback<AmbientTemperatur
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
AMBIENT_TEMPERATURE
,
function
(
data
)
{
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
AMBIENT_TEMPERATURE
,
function
(
data
)
{
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -992,7 +979,7 @@ try {
once(type: SensorId.BAROMETER, callback: Callback
<
BarometerResponse
>
): void
订阅
一次气压计传感器数据。
获取
一次气压计传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1000,8 +987,8 @@ once(type: SensorId.BAROMETER, callback: Callback<BarometerResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
气压计传感器类型为
BAROMETER。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 |
注册一次气压计传感器的回调函数,上报的数据类型
为BarometerResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
BAROMETER。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为BarometerResponse。 |
**错误码**
:
...
...
@@ -1015,12 +1002,11 @@ once(type: SensorId.BAROMETER, callback: Callback<BarometerResponse>): voi
```
js
try
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_BAROMETER
,
function
(
data
)
{
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_BAROMETER
,
function
(
data
)
{
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1028,7 +1014,7 @@ try {
once(type: SensorId.GRAVITY, callback: Callback
<
GravityResponse
>
): void
订阅
一次重力传感器数据。
获取
一次重力传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1036,8 +1022,8 @@ once(type: SensorId.GRAVITY, callback: Callback<GravityResponse>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
重力传感器类型为
GRAVITY。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 |
注册一次重力传感器的回调函数,上报的数据类型
为GravityResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
GRAVITY。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为GravityResponse。 |
**错误码**
:
...
...
@@ -1051,14 +1037,13 @@ once(type: SensorId.GRAVITY, callback: Callback<GravityResponse>): void
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
GRAVITY
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
GRAVITY
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1066,7 +1051,7 @@ try {
once(type: SensorId.GYROSCOPE, callback: Callback
<
GyroscopeResponse
>
): void
订阅
一次陀螺仪传感器数据。
获取
一次陀螺仪传感器数据。
**需要权限**
:ohos.permission.GYROSCOPE
...
...
@@ -1076,8 +1061,8 @@ once(type: SensorId.GYROSCOPE, callback: Callback<GyroscopeResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
陀螺仪传感器类型为
GYROSCOPE。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 |
注册一次陀螺仪传感器的回调函数,上报的数据类型
为GyroscopeResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
GYROSCOPE。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为GyroscopeResponse。 |
**错误码**
:
...
...
@@ -1091,14 +1076,13 @@ once(type: SensorId.GYROSCOPE, callback: Callback<GyroscopeResponse>): voi
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
GYROSCOPE
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
GYROSCOPE
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1106,7 +1090,7 @@ try {
once(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback
<
GyroscopeUncalibratedResponse
>
): void
一次订阅未校准的
陀螺仪传感器数据。
获取一次未校准
陀螺仪传感器数据。
**需要权限**
:ohos.permission.GYROSCOPE
...
...
@@ -1116,8 +1100,8 @@ once(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback<GyroscopeUncal
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
未校准陀螺仪传感器类型为
GYROSCOPE_UNCALIBRATED。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 |
注册一次未校准陀螺仪传感器的回调函数,上报的数据类型
为GyroscopeUncalibratedResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
GYROSCOPE_UNCALIBRATED。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为GyroscopeUncalibratedResponse。 |
**错误码**
:
...
...
@@ -1131,17 +1115,16 @@ once(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback<GyroscopeUncal
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
GYROSCOPE_UNCALIBRATED
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorId
.
GYROSCOPE_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1149,7 +1132,7 @@ try {
once(type: SensorId.HALL, callback: Callback
<
HallResponse
>
): void
订阅一次
霍尔传感器数据。
获取
霍尔传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1157,8 +1140,8 @@ once(type: SensorId.HALL, callback: Callback<HallResponse>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
霍尔传感器类型为
HALL。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 |
注册一次霍尔传感器的回调函数,上报的数据类型
为HallResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
HALL。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为HallResponse。 |
**错误码**
:
...
...
@@ -1172,12 +1155,11 @@ once(type: SensorId.HALL, callback: Callback<HallResponse>): void
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
HALL
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorId
.
HALL
,
function
(
data
)
{
console
.
info
(
'
Status:
'
+
data
.
status
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1185,7 +1167,7 @@ try {
once(type: SensorId.HEART_RATE, callback: Callback
<
HeartRateResponse
>
): void
订阅
一次心率传感器数据。
获取
一次心率传感器数据。
**需要权限**
:ohos.permission.READ_HEALTH_DATA
...
...
@@ -1195,8 +1177,8 @@ once(type: SensorId.HEART_RATE, callback: Callback<HeartRateResponse>): vo
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
心率传感器类型为
HEART_RATE。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 |
注册一次心率传感器的回调函数,上报的数据类型
为HeartRateResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
HEART_RATE。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为HeartRateResponse。 |
**错误码**
:
...
...
@@ -1210,12 +1192,11 @@ once(type: SensorId.HEART_RATE, callback: Callback<HeartRateResponse>): vo
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
HEART_BEAT_RATE
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorId
.
HEART_BEAT_RATE
,
function
(
data
)
{
console
.
info
(
'
Heart rate:
'
+
data
.
heartRate
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1223,7 +1204,7 @@ try {
once(type: SensorId.HUMIDITY, callback: Callback
<
HumidityResponse
>
): void
订阅
一次湿度传感器数据。
获取
一次湿度传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1231,8 +1212,8 @@ once(type: SensorId.HUMIDITY, callback: Callback<HumidityResponse>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
湿度传感器类型为
HUMIDITY。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 |
注册一次湿度传感器的回调函数,上报的数据类型
为HumidityResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
HUMIDITY。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为HumidityResponse。 |
**错误码**
:
...
...
@@ -1246,12 +1227,11 @@ once(type: SensorId.HUMIDITY, callback: Callback<HumidityResponse>): void
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
HUMIDITY
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorId
.
HUMIDITY
,
function
(
data
)
{
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1259,7 +1239,7 @@ try {
once(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback
<
LinearAccelerometerResponse
>
): void
订阅
一次线性加速度传感器数据。
获取
一次线性加速度传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER
...
...
@@ -1269,8 +1249,8 @@ once(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback<LinearAccelerome
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
线性加速度传感器类型为
LINEAR_ACCELEROMETER。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 |
注册一次线性加速度传感器的回调函数,上报的数据类型
为LinearAccelerometerResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
LINEAR_ACCELEROMETER。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为LinearAccelerometerResponse。 |
**错误码**
:
...
...
@@ -1284,14 +1264,13 @@ once(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback<LinearAccelerome
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
LINEAR_ACCELEROMETER
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorId
.
LINEAR_ACCELEROMETER
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1299,7 +1278,7 @@ try {
once(type: SensorId.MAGNETIC_FIELD, callback: Callback
<
MagneticFieldResponse
>
): void
订阅
一次磁场传感器数据。
获取
一次磁场传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1307,8 +1286,8 @@ once(type: SensorId.MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse&
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
磁场传感器类型为
MAGNETIC_FIELD。 |
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 |
注册一次磁场传感器的回调函数,上报的数据类型
为MagneticFieldResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
MAGNETIC_FIELD。 |
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为MagneticFieldResponse。 |
**错误码**
:
...
...
@@ -1322,14 +1301,13 @@ once(type: SensorId.MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse&
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
MAGNETIC_FIELD
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
MAGNETIC_FIELD
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1337,7 +1315,7 @@ try {
once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback
<
MagneticFieldUncalibratedResponse
>
): void
订阅
一次未经校准的磁场传感器数据。
获取
一次未经校准的磁场传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1345,8 +1323,8 @@ once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback<MagneticF
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
未校准磁场传感器类型为
MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 |
注册一次未校准磁场传感器的回调函数,上报的数据类型
为MagneticFieldUncalibratedResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为MagneticFieldUncalibratedResponse。 |
**错误码**
:
...
...
@@ -1360,17 +1338,16 @@ once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback<MagneticF
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
MAGNETIC_FIELD_UNCALIBRATED
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorId
.
MAGNETIC_FIELD_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1378,7 +1355,7 @@ try {
once(type: SensorId.ORIENTATION, callback: Callback
<
OrientationResponse
>
): void
订阅一次定
向传感器数据。
获取一次方
向传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1386,8 +1363,8 @@ once(type: SensorId.ORIENTATION, callback: Callback<OrientationResponse>):
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
方向传感器类型为
ORIENTATION。 |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 |
注册一次方向传感器的回调函数,上报的数据类型
为OrientationResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ORIENTATION。 |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为OrientationResponse。 |
**错误码**
:
...
...
@@ -1401,14 +1378,13 @@ once(type: SensorId.ORIENTATION, callback: Callback<OrientationResponse>):
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
ORIENTATION
,
function
(
data
)
{
console
.
info
(
'
The device rotates at an angle around the X axis:
'
+
data
.
beta
);
console
.
info
(
'
The device rotates at an angle around the Y axis:
'
+
data
.
gamma
);
console
.
info
(
'
The device rotates at an angle around the Z axis:
'
+
data
.
alpha
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
ORIENTATION
,
function
(
data
)
{
console
.
info
(
'
The device rotates at an angle around the X axis:
'
+
data
.
beta
);
console
.
info
(
'
The device rotates at an angle around the Y axis:
'
+
data
.
gamma
);
console
.
info
(
'
The device rotates at an angle around the Z axis:
'
+
data
.
alpha
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1416,7 +1392,7 @@ try {
once(type: SensorId.PEDOMETER, callback: Callback
<
PedometerResponse
>
): void
订阅
一次计步器传感器数据。
获取
一次计步器传感器数据。
**需要权限**
:ohos.permission.ACTIVITY_MOTION
...
...
@@ -1426,8 +1402,8 @@ once(type: SensorId.PEDOMETER, callback: Callback<PedometerResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
计步传感器类型为
PEDOMETER。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 |
注册一次计步传感器的回调函数,上报的数据类型
为PedometerResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
PEDOMETER。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为PedometerResponse。 |
**错误码**
:
...
...
@@ -1441,20 +1417,18 @@ once(type: SensorId.PEDOMETER, callback: Callback<PedometerResponse>): voi
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
PEDOMETER
,
function
(
data
)
{
console
.
info
(
'
Steps:
'
+
data
.
steps
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
PEDOMETER
,
function
(
data
)
{
console
.
info
(
'
Step count:
'
+
data
.
steps
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
### PEDOMETER_DETECTION<sup>9+</sup>
once(type: SensorId.PEDOMETER_DETECTION, callback: Callback
<
PedometerDetectionResponse
>
): void
订阅一次计步器检测传感器数据。
获取一次计步检测器传感器数据。
**需要权限**
:ohos.permission.ACTIVITY_MOTION
...
...
@@ -1464,8 +1438,8 @@ once(type: SensorId.PEDOMETER_DETECTION, callback: Callback<PedometerDetectio
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
计步检测传感器类型为
PEDOMETER_DETECTION。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 |
注册一次计步检测传感器的回调函数,上报的数据类型
为PedometerDetectionResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
PEDOMETER_DETECTION。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为PedometerDetectionResponse。 |
**错误码**
:
...
...
@@ -1479,12 +1453,11 @@ once(type: SensorId.PEDOMETER_DETECTION, callback: Callback<PedometerDetectio
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
PEDOMETER_DETECTION
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorId
.
PEDOMETER_DETECTION
,
function
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1492,7 +1465,7 @@ try {
once(type: SensorId.PROXIMITY, callback: Callback
<
ProximityResponse
>
): void
订阅一次接近
传感器数据。
获取一次接近光
传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1500,8 +1473,8 @@ once(type: SensorId.PROXIMITY, callback: Callback<ProximityResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
接近光传感器类型为
PROXIMITY。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 |
注册一次接近光传感器的回调函数,上报的数据类型
为ProximityResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
PROXIMITY。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为ProximityResponse。 |
**错误码**
:
...
...
@@ -1515,12 +1488,11 @@ once(type: SensorId.PROXIMITY, callback: Callback<ProximityResponse>): voi
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
PROXIMITY
,
function
(
data
)
{
console
.
info
(
'
Distance:
'
+
data
.
distance
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
PROXIMITY
,
function
(
data
)
{
console
.
info
(
'
Distance:
'
+
data
.
distance
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1528,7 +1500,7 @@ try {
once(type: SensorId.ROTATION_VECTOR, callback: Callback
<
RotationVectorResponse
>
): void
订阅
一次旋转矢量传感器数据。
获取
一次旋转矢量传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1536,8 +1508,8 @@ once(type: SensorId.ROTATION_VECTOR, callback: Callback<RotationVectorRespons
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
旋转矢量传感器类型为
ROTATION_VECTOR。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 |
注册一次旋转矢量传感器的回调函数,上报的数据类型
为RotationVectorResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ROTATION_VECTOR。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为RotationVectorResponse。 |
**错误码**
:
...
...
@@ -1551,15 +1523,14 @@ once(type: SensorId.ROTATION_VECTOR, callback: Callback<RotationVectorRespons
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
ROTATION_VECTOR
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
Scalar quantity:
'
+
data
.
w
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
ROTATION_VECTOR
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
Scalar quantity:
'
+
data
.
w
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1567,7 +1538,7 @@ try {
once(type: SensorId.SIGNIFICANT_MOTION, callback: Callback
<
SignificantMotionResponse
>
): void
订阅一次重要的运动
传感器数据。
获取一次大幅动作检测
传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1575,8 +1546,8 @@ once(type: SensorId.SIGNIFICANT_MOTION, callback: Callback<SignificantMotionR
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
有效运动传感器类型为
SIGNIFICANT_MOTION。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 |
注册一次有效运动传感器的回调函数,上报的数据类型
为SignificantMotionResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
SIGNIFICANT_MOTION。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为SignificantMotionResponse。 |
**错误码**
:
...
...
@@ -1590,12 +1561,11 @@ once(type: SensorId.SIGNIFICANT_MOTION, callback: Callback<SignificantMotionR
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
SIGNIFICANT_MOTION
,
function
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
SIGNIFICANT_MOTION
,
function
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1603,7 +1573,7 @@ try {
once(type: SensorId.WEAR_DETECTION, callback: Callback
<
WearDetectionResponse
>
): void
订阅
一次佩戴检测传感器数据。
获取
一次佩戴检测传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1611,8 +1581,8 @@ once(type: SensorId.WEAR_DETECTION, callback: Callback<WearDetectionResponse&
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
佩戴检测传感器类型为
WEAR_DETECTION。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 |
注册一次穿戴检测传感器的回调函数,上报的数据类型
为WearDetectionResponse。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
WEAR_DETECTION。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 |
回调函数,异步上报的传感器数据固定
为WearDetectionResponse。 |
**错误码**
:
...
...
@@ -1626,12 +1596,11 @@ once(type: SensorId.WEAR_DETECTION, callback: Callback<WearDetectionResponse&
```
js
try
{
sensor
.
once
(
sensor
.
SensorId
.
WEAR_DETECTION
,
function
(
data
)
{
console
.
info
(
"
Wear status:
"
+
data
.
value
);
}
);
}
catch
(
err
)
{
console
.
info
(
'
once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
once
(
sensor
.
SensorId
.
WEAR_DETECTION
,
function
(
data
)
{
console
.
info
(
"
Wear status:
"
+
data
.
value
);
});
}
catch
(
err
)
{
console
.
error
(
'
Once fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1641,7 +1610,7 @@ try {
off(type: SensorId.ACCELEROMETER, callback?: Callback
<
AccelerometerResponse
>
): void
取消订阅加速度
计
传感器数据。
取消订阅加速度传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER
...
...
@@ -1651,21 +1620,27 @@ off(type: SensorId.ACCELEROMETER, callback?: Callback<AccelerometerResponse&g
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的加速度传感器类型为
ACCELEROMETER。 |
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
|
是 | 取消注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ACCELEROMETER。 |
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
|
否 | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
x-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
sensor
.
off
(
sensor
.
SensorId
.
ACCELEROMETER
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
o
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
ACCELEROMETER
,
callback1
);
// 取消SensorId.ACCELEROMETER类型的所有回调
sensor
.
off
(
sensor
.
SensorId
.
ACCELEROMETER
);
}
catch
(
err
)
{
console
.
error
(
'
O
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1673,7 +1648,7 @@ try {
off(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback?: Callback
<
AccelerometerUncalibratedResponse
>
): void
取消订阅未校准
的加速度计
传感器数据。
取消订阅未校准
加速度
传感器数据。
**需要权限**
:ohos.permission.ACCELEROMETER
...
...
@@ -1683,24 +1658,27 @@ off(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback?: Callback<Accelerome
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的未校准加速度计传感器类型为
ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 |
取消注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback
<
[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
}
sensor
.
off
(
sensor
.
SensorId
.
ACCELEROMETER_UNCALIBRATED
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER_UNCALIBRATED
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
ACCELEROMETER_UNCALIBRATED
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
ACCELEROMETER_UNCALIBRATED
,
callback1
);
// 取消注册SensorId.ACCELEROMETER_UNCALIBRATED类型的所有回调
sensor
.
off
(
sensor
.
SensorId
.
ACCELEROMETER_UNCALIBRATED
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1716,27 +1694,35 @@ off(type: SensorId.AMBIENT_LIGHT, callback?: Callback<LightResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的环境光传感器类型为
AMBIENT_LIGHT。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 |
取消注册环境光传感器的回调函数,上报的数据类型为LightResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
AMBIENT_LIGHT。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
try
{
function
callback
(
data
)
{
console
.
info
(
'
Illumination:
'
+
data
.
intensity
);
}
sensor
.
off
(
sensor
.
SensorId
.
AMBIENT_LIGHT
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
sensor
.
on
(
sensor
.
SensorId
.
AMBIENT_LIGHT
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
AMBIENT_LIGHT
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
AMBIENT_LIGHT
,
callback1
);
// 取消注册SensorId.AMBIENT_LIGHT的所有回调
sensor
.
off
(
sensor
.
SensorId
.
AMBIENT_LIGHT
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
V
```
### AMBIENT_TEMPERATURE<sup>9+</sup>
off(type: SensorId.AMBIENT_TEMPERATURE, callback?: Callback
<
AmbientTemperatureResponse
>
): void
取消订阅
环境
温度传感器数据。
取消订阅温度传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -1744,19 +1730,27 @@ off(type: SensorId.AMBIENT_TEMPERATURE, callback?: Callback<AmbientTemperatur
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的环境温度传感器类型为
AMBIENT_TEMPERATURE。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 |
取消注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
AMBIENT_TEMPERATURE。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
}
sensor
.
off
(
sensor
.
SensorId
.
AMBIENT_TEMPERATURE
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
AMBIENT_TEMPERATURE
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
AMBIENT_TEMPERATURE
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
AMBIENT_TEMPERATURE
,
callback1
);
// 取消注册SensorId.AMBIENT_TEMPERATURE的所有回调
sensor
.
off
(
sensor
.
SensorId
.
AMBIENT_TEMPERATURE
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1772,19 +1766,27 @@ off(type: SensorId.BAROMETER, callback?: Callback<BarometerResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的气压计传感器类型为
BAROMETER。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 |
取消注册气压计传感器的回调函数,上报的数据类型为BarometerResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
BAROMETER。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
}
sensor
.
off
(
sensor
.
SensorId
.
BAROMETER
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
BAROMETER
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
BAROMETER
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
BAROMETER
,
callback1
);
// 取消注册SensorId.BAROMETER的所有回调
sensor
.
off
(
sensor
.
SensorId
.
BAROMETER
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1800,21 +1802,27 @@ off(type: SensorId.GRAVITY, callback?: Callback<GravityResponse>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的重力传感器类型为
GRAVITY。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 |
取消注册注册重力传感器的回调函数,上报的数据类型为GravityResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
GRAVITY。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
sensor
.
off
(
sensor
.
SensorId
.
GRAVITY
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
o
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
GRAVITY
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
GRAVITY
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
GRAVITY
,
callback1
);
// 取消注册SensorId.GRAVITY的所有回调
sensor
.
off
(
sensor
.
SensorId
.
GRAVITY
);
}
catch
(
err
)
{
console
.
error
(
'
O
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1832,21 +1840,27 @@ off(type: SensorId.GYROSCOPE, callback?: Callback<GyroscopeResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的陀螺仪传感器类型为
GYROSCOPE。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 |
取消注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
GYROSCOPE。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
sensor
.
off
(
sensor
.
SensorId
.
GYROSCOPE
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
o
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
GYROSCOPE
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
GYROSCOPE
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
GYROSCOPE
,
callback1
);
// 取消注册SensorId.GYROSCOPE的所有回调
sensor
.
off
(
sensor
.
SensorId
.
GYROSCOPE
);
}
catch
(
err
)
{
console
.
error
(
'
O
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1854,7 +1868,7 @@ try {
off(type: SensorId.GYROSCOPE_UNCALIBRATED, callback?: Callback
<
GyroscopeUncalibratedResponse
>
): void
取消订阅未校准
的
陀螺仪传感器数据。
取消订阅未校准陀螺仪传感器数据。
**需要权限**
:ohos.permission.GYROSCOPE
...
...
@@ -1864,21 +1878,27 @@ off(type: SensorId.GYROSCOPE_UNCALIBRATED, callback?: Callback<GyroscopeUncal
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的未校准陀螺仪传感器类型为
GYROSCOPE_UNCALIBRATED。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 |
取消注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
GYROSCOPE_UNCALIBRATED。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
sensor
.
off
(
sensor
.
SensorId
.
GYROSCOPE_UNCALIBRATED
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
o
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
GYROSCOPE_UNCALIBRATED
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
GYROSCOPE_UNCALIBRATED
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
GYROSCOPE_UNCALIBRATED
,
callback1
);
// 取消注册SensorId.GYROSCOPE_UNCALIBRATED的所有回调
sensor
.
off
(
sensor
.
SensorId
.
GYROSCOPE_UNCALIBRATED
);
}
catch
(
err
)
{
console
.
error
(
'
O
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1894,19 +1914,27 @@ off(type: SensorId.HALL, callback?: Callback<HallResponse>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的霍尔传感器类型为
HALL。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 |
取消注册霍尔传感器的回调函数,上报的数据类型为
HallResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
HALL。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
Status:
'
+
data
.
status
);
}
sensor
.
off
(
sensor
.
SensorId
.
HALL
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
HALL
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
HALL
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
HALL
,
callback1
);
// 取消注册SensorId.HALL的所有回调
sensor
.
off
(
sensor
.
SensorId
.
HALL
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1924,19 +1952,27 @@ off(type: SensorId.HEART_RATE, callback?: Callback<HeartRateResponse>): vo
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的心率传感器类型为
HEART_RATE。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 |
取消注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
HEART_RATE。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
"
Heart rate:
"
+
data
.
heartRate
);
}
sensor
.
off
(
sensor
.
SensorId
.
HEART_RATE
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
HEART_RATE
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
HEART_RATE
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
HEART_RATE
,
callback1
);
// 取消注册SensorId.HEART_RATE的所有回调
sensor
.
off
(
sensor
.
SensorId
.
HEART_RATE
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1952,19 +1988,27 @@ off(type: SensorId.HUMIDITY, callback?: Callback<HumidityResponse>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的湿度传感器类型为
HUMIDITY。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 |
取消注册湿度传感器的回调函数,上报的数据类型为HumidityResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
HUMIDITY。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
}
sensor
.
off
(
sensor
.
SensorId
.
HUMIDITY
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
HUMIDITY
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
HUMIDITY
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
HUMIDITY
,
callback1
);
// 取消注册SensorId.HUMIDITY的所有回调
sensor
.
off
(
sensor
.
SensorId
.
HUMIDITY
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -1982,21 +2026,27 @@ off(type: SensorId.LINEAR_ACCELEROMETER, callback?: Callback<LinearAccelerome
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的线性加速度传感器类型为
LINEAR_ACCELERATION。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 |
取消注册性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
LINEAR_ACCELERATION。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
sensor
.
off
(
sensor
.
SensorId
.
LINEAR_ACCELEROMETER
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
o
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
LINEAR_ACCELEROMETER
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
LINEAR_ACCELEROMETER
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
LINEAR_ACCELEROMETER
,
callback1
);
// 取消注册SensorId.LINEAR_ACCELEROMETER的所有回调
sensor
.
off
(
sensor
.
SensorId
.
LINEAR_ACCELEROMETER
);
}
catch
(
err
)
{
console
.
error
(
'
O
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2012,21 +2062,27 @@ off(type: SensorId.MAGNETIC_FIELD, callback?: Callback<MagneticFieldResponse&
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的磁场传感器类型为
MAGNETIC_FIELD。 |
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 |
取消注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
MAGNETIC_FIELD。 |
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
}
sensor
.
off
(
sensor
.
SensorId
.
MAGNETIC_FIELD
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
o
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
MAGNETIC_FIELD
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
MAGNETIC_FIELD
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
MAGNETIC_FIELD
,
callback1
);
// 取消注册SensorId.MAGNETIC_FIELD的所有回调
sensor
.
off
(
sensor
.
SensorId
.
MAGNETIC_FIELD
);
}
catch
(
err
)
{
console
.
error
(
'
O
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2042,24 +2098,27 @@ off(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback<MagneticF
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的未校准磁场传感器类型为
MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 |
取消注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
X-coordinate bias:
'
+
data
.
biasX
);
console
.
info
(
'
Y-coordinate bias:
'
+
data
.
biasY
);
console
.
info
(
'
Z-coordinate bias:
'
+
data
.
biasZ
);
}
sensor
.
off
(
sensor
.
SensorId
.
MAGNETIC_FIELD_UNCALIBRATED
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
MAGNETIC_FIELD_UNCALIBRATED
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
MAGNETIC_FIELD_UNCALIBRATED
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
MAGNETIC_FIELD_UNCALIBRATED
,
callback1
);
// 取消注册SensorId.MAGNETIC_FIELD_UNCALIBRATED的所有回调
sensor
.
off
(
sensor
.
SensorId
.
MAGNETIC_FIELD_UNCALIBRATED
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2075,21 +2134,27 @@ off(type: SensorId.ORIENTATION, callback?: Callback<OrientationResponse>):
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的方向传感器类型为
ORIENTATION。 |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 |
取消注册方向传感器的回调函数,上报的数据类型为OrientationResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ORIENTATION。 |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
The device rotates at an angle around the X axis:
'
+
data
.
beta
);
console
.
info
(
'
The device rotates at an angle around the Y axis:
'
+
data
.
gamma
);
console
.
info
(
'
The device rotates at an angle around the Z axis:
'
+
data
.
alpha
);
}
sensor
.
off
(
sensor
.
SensorId
.
ORIENTATION
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
o
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
ORIENTATION
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
ORIENTATION
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
ORIENTATION
,
callback1
);
// 取消注册SensorId.ORIENTATION的所有回调
sensor
.
off
(
sensor
.
SensorId
.
ORIENTATION
);
}
catch
(
err
)
{
console
.
error
(
'
O
ff fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2107,19 +2172,27 @@ off(type: SensorId.PEDOMETER, callback?: Callback<PedometerResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的计步传感器类型为
PEDOMETER。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 |
取消注册计步传感器的回调函数,上报的数据类型为PedometerResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
PEDOMETER。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
Steps:
'
+
data
.
steps
);
}
sensor
.
off
(
sensor
.
SensorId
.
PEDOMETER
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
PEDOMETER
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
PEDOMETER
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
PEDOMETER
,
callback1
);
// 取消注册SensorId.PEDOMETER的所有回调
sensor
.
off
(
sensor
.
SensorId
.
PEDOMETER
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2127,7 +2200,7 @@ try {
off(type: SensorId.PEDOMETER_DETECTION, callback?: Callback
<
PedometerDetectionResponse
>
): void
取消订阅计步
器检测
传感器数据。
取消订阅计步
检测器
传感器数据。
**需要权限**
:ohos.permission.ACTIVITY_MOTION
...
...
@@ -2137,19 +2210,27 @@ off(type: SensorId.PEDOMETER_DETECTION, callback?: Callback<PedometerDetectio
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的计步检测传感器类型为
PEDOMETER_DETECTION。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 |
取消注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
PEDOMETER_DETECTION。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
}
sensor
.
off
(
sensor
.
SensorId
.
PEDOMETER_DETECTION
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
PEDOMETER_DETECTION
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
PEDOMETER_DETECTION
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
PEDOMETER_DETECTION
,
callback1
);
// 取消注册SensorId.PEDOMETER_DETECTION的所有回调
sensor
.
off
(
sensor
.
SensorId
.
PEDOMETER_DETECTION
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2157,7 +2238,7 @@ try {
off(type: SensorId.PROXIMITY, callback?: Callback
<
ProximityResponse
>
): void
取消订阅接近传感器数据。
取消订阅接近
光
传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2165,19 +2246,27 @@ off(type: SensorId.PROXIMITY, callback?: Callback<ProximityResponse>): voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的接近光传感器类型为
PROXIMITY。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 |
取消注册接近光传感器的回调函数,上报的数据类型为ProximityResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
PROXIMITY。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
Distance:
'
+
data
.
distance
);
}
sensor
.
off
(
sensor
.
SensorId
.
PROXIMITY
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
PROXIMITY
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
PROXIMITY
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
PROXIMITY
,
callback1
);
// 取消注册SensorId.PROXIMITY的所有回调
sensor
.
off
(
sensor
.
SensorId
.
PROXIMITY
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2193,22 +2282,27 @@ off(type: SensorId.ROTATION_VECTOR, callback?: Callback<RotationVectorRespons
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的旋转矢量传感器类型为
ROTATION_VECTOR。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 |
取消注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
ROTATION_VECTOR。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Z-coordinate component:
'
+
data
.
z
);
console
.
info
(
'
Scalar quantity:
'
+
data
.
w
);
}
sensor
.
off
(
sensor
.
SensorId
.
ROTATION_VECTOR
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
ROTATION_VECTOR
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
ROTATION_VECTOR
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
ROTATION_VECTOR
,
callback1
);
// 取消注册SensorId.ROTATION_VECTOR的所有回调
sensor
.
off
(
sensor
.
SensorId
.
ROTATION_VECTOR
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2216,7 +2310,7 @@ try {
off(type: SensorId.SIGNIFICANT_MOTION, callback?: Callback
<
SignificantMotionResponse
>
): void
取消
订阅重要的运动
传感器数据。
取消
大幅动作检测
传感器数据。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2224,19 +2318,27 @@ off(type: SensorId.SIGNIFICANT_MOTION, callback?: Callback<SignificantMotionR
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的大幅动作传感器类型为
SIGNIFICANT_MOTION。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 |
取消注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
SIGNIFICANT_MOTION。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
callback
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
}
sensor
.
off
(
sensor
.
SensorId
.
SIGNIFICANT_MOTION
,
callback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
SIGNIFICANT_MOTION
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
SIGNIFICANT_MOTION
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
SIGNIFICANT_MOTION
,
callback1
);
// 取消注册SensorId.SIGNIFICANT_MOTION的所有回调
sensor
.
off
(
sensor
.
SensorId
.
SIGNIFICANT_MOTION
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2252,19 +2354,27 @@ off(type: SensorId.WEAR_DETECTION, callback?: Callback<WearDetectionResponse&
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
要取消订阅的佩戴检测传感器类型为
WEAR_DETECTION。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 |
取消注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse
。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
传感器类型,该值固定为SensorId.
WEAR_DETECTION。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 |
需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数
。 |
**示例:**
```
js
function
callback1
(
data
)
{
console
.
info
(
'
Callback1 data:
'
+
JSON
.
stringify
(
data
));
}
function
callback2
(
data
)
{
console
.
info
(
'
Callback2 data:
'
+
JSON
.
stringify
(
data
));
}
try
{
function
accCallback
(
data
)
{
console
.
info
(
'
Wear status:
'
+
data
.
value
);
}
sensor
.
off
(
sensor
.
SensorId
.
WEAR_DETECTION
,
accCallback
);
}
catch
(
err
)
{
console
.
info
(
'
off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
sensor
.
on
(
sensor
.
SensorId
.
WEAR_DETECTION
,
callback1
);
sensor
.
on
(
sensor
.
SensorId
.
WEAR_DETECTION
,
callback2
);
// 仅取消callback1的注册
sensor
.
off
(
sensor
.
SensorId
.
WEAR_DETECTION
,
callback1
);
// 取消注册SensorId.WEAR_DETECTION的所有回调
sensor
.
off
(
sensor
.
SensorId
.
WEAR_DETECTION
);
}
catch
(
err
)
{
console
.
error
(
'
Off fail, errCode:
'
+
err
.
code
+
'
,msg:
'
+
err
.
message
);
}
```
...
...
@@ -2272,7 +2382,7 @@ try {
getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback
<
GeomagneticResponse
>
): void
获取
地球上特定位置的地磁场
。
获取
某时刻地球上特定位置的地磁场信息
。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2280,9 +2390,9 @@ getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number, callbac
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
| locationOptions |
[
LocationOptions
](
#locationoptions
)
| 是 | 地理位置。 |
| timeMillis | number | 是 |
表示获取磁偏角的时间,单位为
毫秒。 |
| callback | AsyncCallback
<
[GeomagneticResponse](#geomagneticresponse)
>
| 是 |
返回
磁场信息。 |
| locationOptions |
[
LocationOptions
](
#locationoptions
)
| 是 | 地理位置
,包括经度、纬度和海拔高度
。 |
| timeMillis | number | 是 |
获取磁偏角的时间,unix时间戳,单位
毫秒。 |
| callback | AsyncCallback
<
[GeomagneticResponse](#geomagneticresponse)
>
| 是 |
回调函数,返回地
磁场信息。 |
**错误码**
:
...
...
@@ -2296,13 +2406,21 @@ getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number, callbac
```
js
try
{
sensor
.
getGeomagneticInfo
({
latitude
:
80
,
longitude
:
0
,
altitude
:
0
},
1580486400000
,
function
(
data
)
{
console
.
info
(
'
sensor_getGeomagneticInfo_callback x:
'
+
data
.
x
+
'
,y:
'
+
data
.
y
+
'
,z:
'
+
data
.
z
+
'
,geomagneticDip:
'
+
data
.
geomagneticDip
+
'
,deflectionAngle:
'
+
data
.
deflectionAngle
+
'
,levelIntensity:
'
+
data
.
levelIntensity
+
'
,totalIntensity:
'
+
data
.
totalIntensity
);
sensor
.
getGeomagneticInfo
({
latitude
:
80
,
longitude
:
0
,
altitude
:
0
},
1580486400000
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
error
(
'
Get geomagneticInfo failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
console
.
info
(
"
GeomagneticInfo x
"
+
data
.
x
);
console
.
info
(
"
GeomagneticInfo y
"
+
data
.
y
);
console
.
info
(
"
GeomagneticInfo z
"
+
data
.
z
);
console
.
info
(
"
GeomagneticInfo geomagneticDip
"
+
data
.
geomagneticDip
);
console
.
info
(
"
GeomagneticInfo deflectionAngle
"
+
data
.
deflectionAngle
);
console
.
info
(
"
GeomagneticInfo levelIntensity
"
+
data
.
levelIntensity
);
console
.
info
(
"
GeomagneticInfo totalIntensity
"
+
data
.
totalIntensity
);
});
}
catch
(
err
)
{
console
.
error
(
'
getG
eomagneticInfo failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get g
eomagneticInfo failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2310,7 +2428,7 @@ try {
getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number): Promise
<
GeomagneticResponse
>
获取
地球上特定位置的地磁场
。
获取
某时刻地球上特定位置的地磁场信息
。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2318,14 +2436,14 @@ getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number): Promis
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | ----------------------------------- | ---- | ---------------------------------- |
| locationOptions |
[
LocationOptions
](
#locationoptions
)
| 是 | 地理位置。 |
| timeMillis | number | 是 |
表示获取磁偏角的时间,单位为
毫秒。 |
| locationOptions |
[
LocationOptions
](
#locationoptions
)
| 是 | 地理位置
,包括经度、纬度和海拔高度
。 |
| timeMillis | number | 是 |
获取磁偏角的时间,unix时间戳,单位
毫秒。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------------------------------- | -------------- |
| Promise
<
[GeomagneticResponse](#geomagneticresponse)
>
|
返回
磁场信息。 |
| Promise
<
[GeomagneticResponse](#geomagneticresponse)
>
|
Promise对象,返回地
磁场信息。 |
**错误码**
:
...
...
@@ -2339,16 +2457,20 @@ getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number): Promis
```
js
try
{
const
promise
=
sensor
.
getGeomagneticInfo
({
latitude
:
80
,
longitude
:
0
,
altitude
:
0
},
1580486400000
);
promise
.
then
((
data
)
=>
{
console
.
info
(
'
sensor_getGeomagneticInfo_promise x:
'
+
data
.
x
+
'
,y:
'
+
data
.
y
+
'
,z:
'
+
data
.
z
+
'
,geomagneticDip:
'
+
data
.
geomagneticDip
+
'
,deflectionAngle:
'
+
data
.
deflectionAngle
+
'
,levelIntensity:
'
+
data
.
levelIntensity
+
'
,totalIntensity:
'
+
data
.
totalIntensity
);
}).
catch
((
reason
)
=>
{
console
.
info
(
'
Operation failed.
'
);
})
const
promise
=
sensor
.
getGeomagneticInfo
({
latitude
:
80
,
longitude
:
0
,
altitude
:
0
},
1580486400000
);
promise
.
then
((
data
)
=>
{
console
.
info
(
"
GeomagneticInfo x
"
+
data
.
x
);
console
.
info
(
"
GeomagneticInfo y
"
+
data
.
y
);
console
.
info
(
"
GeomagneticInfo z
"
+
data
.
z
);
console
.
info
(
"
GeomagneticInfo geomagneticDip
"
+
data
.
geomagneticDip
);
console
.
info
(
"
GeomagneticInfo deflectionAngle
"
+
data
.
deflectionAngle
);
console
.
info
(
"
GeomagneticInfo levelIntensity
"
+
data
.
levelIntensity
);
console
.
info
(
"
GeomagneticInfo totalIntensity
"
+
data
.
totalIntensity
);
},
(
err
)
=>
{
console
.
error
(
'
Get geomagneticInfo failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getGeomagneticInfo failed
. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get geomagneticInfo
. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2356,7 +2478,7 @@ try {
getDeviceAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback
<
number
>
): void
根据
当前气压获取设备所在的
海拔高度。
根据
气压值获取
海拔高度。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2364,9 +2486,9 @@ getDeviceAltitude(seaPressure: number, currentPressure: number, callback: AsyncC
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | --------------------------- | ---- | ------------------------------------- |
| seaPressure | number | 是 |
表示
海平面气压值,单位为hPa。 |
| currentPressure | number | 是 |
表示设备所在高度
的气压值,单位为hPa。 |
| callback | AsyncCallback
<
number
>
| 是 |
返回设备所在
的海拔高度,单位为米。 |
| seaPressure | number | 是 | 海平面气压值,单位为hPa。 |
| currentPressure | number | 是 |
指定
的气压值,单位为hPa。 |
| callback | AsyncCallback
<
number
>
| 是 |
回调函数,返回指定的气压值对应
的海拔高度,单位为米。 |
**错误码**
:
...
...
@@ -2380,11 +2502,17 @@ getDeviceAltitude(seaPressure: number, currentPressure: number, callback: AsyncC
```
js
try
{
sensor
.
getDeviceAltitude
(
0
,
200
,
function
(
data
)
{
console
.
info
(
'
Successed to get getDeviceAltitude interface get data:
'
+
data
);
});
let
seaPressure
=
1013.2
;
let
currentPressure
=
1500.0
;
sensor
.
getDeviceAltitude
(
seaPressure
,
currentPressure
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
error
(
'
Get altitude failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
console
.
info
(
'
altitude:
'
+
data
);
});
}
catch
(
err
)
{
console
.
error
(
'
getDeviceA
ltitude failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get a
ltitude failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2392,7 +2520,7 @@ try {
getDeviceAltitude(seaPressure: number, currentPressure: number): Promise
<
number
>
根据
当前气压获取设备所在的
海拔高度。
根据
气压值获取
海拔高度。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2400,14 +2528,14 @@ getDeviceAltitude(seaPressure: number, currentPressure: number): Promise<numb
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | ------ | ---- | ------------------------------------- |
| seaPressure | number | 是 |
表示
海平面气压值,单位为hPa。 |
| currentPressure | number | 是 |
表示设备所在高度
的气压值,单位为hPa。 |
| seaPressure | number | 是 | 海平面气压值,单位为hPa。 |
| currentPressure | number | 是 |
指定
的气压值,单位为hPa。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------------------ |
| Promise
<
number
>
|
返回设备所在的海拔高度(单位:米)
。 |
| Promise
<
number
>
|
Promise对象,返回指定的气压值对应的海拔高度,单位为米
。 |
**错误码**
:
...
...
@@ -2421,14 +2549,16 @@ getDeviceAltitude(seaPressure: number, currentPressure: number): Promise<numb
```
js
try
{
const
promise
=
sensor
.
getDeviceAltitude
(
0
,
200
);
promise
.
then
((
data
)
=>
{
console
.
info
(
'
sensor_getDeviceAltitude_Promise success
'
,
data
);
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation failed
"
);
})
let
seaPressure
=
1013.2
;
let
currentPressure
=
1500.0
;
const
promise
=
sensor
.
getDeviceAltitude
(
seaPressure
,
currentPressure
);
promise
.
then
((
data
)
=>
{
console
.
info
(
'
sensor_getDeviceAltitude_Promise success
'
,
data
);
},
(
err
)
=>
{
console
.
error
(
'
Get altitude failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getDeviceA
ltitude failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get a
ltitude failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2436,7 +2566,7 @@ try {
getInclination(inclinationMatrix: Array
<
number
>
, callback: AsyncCallback
<
number
>
): void
从倾角矩阵计算地磁倾角的弧度
。
根据倾斜矩阵计算地磁倾角
。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2444,8 +2574,8 @@ getInclination(inclinationMatrix: Array<number>, callback: AsyncCallback&l
| 参数名 | 类型 | 必填 | 说明 |
| ----------------- | --------------------------- | ---- | ---------------------------- |
| inclinationMatrix | Array
<
number
>
| 是 |
表示
倾斜矩阵。 |
| callback | AsyncCallback
<
number
>
| 是 |
返回地磁倾斜
角,单位为弧度。 |
| inclinationMatrix | Array
<
number
>
| 是 | 倾斜矩阵。 |
| callback | AsyncCallback
<
number
>
| 是 |
回调函数,返回地磁倾
角,单位为弧度。 |
**错误码**
:
...
...
@@ -2459,11 +2589,21 @@ getInclination(inclinationMatrix: Array<number>, callback: AsyncCallback&l
```
js
try
{
sensor
.
getInclination
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
function
(
data
)
{
console
.
info
(
'
Successed to get getInclination interface get data:
'
+
data
);
})
// inclinationMatrix可以为3*3,或者4*4
let
inclinationMatrix
=
[
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
]
sensor
.
getInclination
(
inclinationMatrix
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
error
(
'
Get inclination failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
console
.
info
(
'
Inclination:
'
+
data
);
})
}
catch
(
err
)
{
console
.
error
(
'
getI
nclination failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get i
nclination failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2471,7 +2611,7 @@ try {
getInclination(inclinationMatrix: Array
<
number
>
): Promise
<
number
>
从倾角矩阵计算地磁倾角的弧度
。
根据倾斜矩阵计算地磁倾角
。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2479,13 +2619,13 @@ try {
| 参数名 | 类型 | 必填 | 说明 |
| ----------------- | ------------------- | ---- | -------------- |
| inclinationMatrix | Array
<
number
>
| 是 |
表示
倾斜矩阵。 |
| inclinationMatrix | Array
<
number
>
| 是 | 倾斜矩阵。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ---------------------------- |
| Promise
<
number
>
| 返回地磁倾斜角,单位为弧度。 |
| Promise
<
number
>
|
Promise对象,
返回地磁倾斜角,单位为弧度。 |
**错误码**
:
...
...
@@ -2499,14 +2639,20 @@ try {
```
js
try
{
const
promise
=
sensor
.
getInclination
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
]);
promise
.
then
((
data
)
=>
{
console
.
info
(
'
getInclination_promise successed
'
,
data
);
}).
catch
((
err
)
=>
{
console
.
error
(
"
Operation failed
"
);
})
// inclinationMatrix可以为3*3,或者4*4
let
inclinationMatrix
=
[
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
]
const
promise
=
sensor
.
getInclination
(
inclinationMatrix
);
promise
.
then
((
data
)
=>
{
console
.
info
(
'
Inclination:
'
+
data
);
},
(
err
)
=>
{
console
.
error
(
'
Get inclination failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getI
nclination failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get i
nclination failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2515,7 +2661,7 @@ try {
getAngleVariation(currentRotationMatrix: Array
<
number
>
, preRotationMatrix: Array
<
number
>
,
callback: AsyncCallback
<Array
&
lt
;
number
&
gt
;
>
): void
得到
两个旋转矩阵之间的角度变化。
计算
两个旋转矩阵之间的角度变化。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2523,9 +2669,9 @@ try {
| 参数名 | 类型 | 必填 | 说明 |
| --------------------- | ---------------------------------------- | ---- | --------------------------------- |
| currentRotationMatrix | Array
<
number
>
| 是 |
表示
当前旋转矩阵。 |
| preRotationMatrix | Array
<
number
>
| 是 |
表示
旋转矩阵。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 |
返回z、x、y轴方向的旋转角度变化
。 |
| currentRotationMatrix | Array
<
number
>
| 是 | 当前旋转矩阵。 |
| preRotationMatrix | Array
<
number
>
| 是 |
相对
旋转矩阵。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 |
回调函数,返回绕z、x、y轴方向的旋转角度
。 |
**错误码**
:
...
...
@@ -2539,13 +2685,31 @@ try {
```
js
try
{
sensor
.
getAngleVariation
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
],
function
(
data
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
"
data[
"
+
i
+
"
]:
"
+
data
[
i
]);
}
})
// 旋转矩阵可以为3*3,或者4*4
let
currentRotationMatrix
=
[
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
];
let
preRotationMatrix
=
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
];
sensor
.
getAngleVariation
(
currentRotationMatrix
,
preRotationMatrix
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
error
(
'
Get angle variation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
if
(
data
.
length
<
3
)
{
console
.
error
(
"
Get angle variation failed, length
"
+
data
.
length
);
}
console
.
info
(
"
Z:
"
+
data
[
0
]);
console
.
info
(
"
X:
"
+
data
[
1
]);
console
.
info
(
"
Y :
"
+
data
[
2
]);
})
}
catch
(
err
)
{
console
.
error
(
'
getAngleV
ariation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get angle v
ariation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2561,14 +2725,14 @@ getAngleVariation(currentRotationMatrix: Array<number>, preRotationMatrix:
| 参数名 | 类型 | 必填 | 说明 |
| --------------------- | ------------------- | ---- | ------------------ |
| currentRotationMatrix | Array
<
number
>
| 是 |
表示
当前旋转矩阵。 |
| preRotationMatrix | Array
<
number
>
| 是 |
|
| currentRotationMatrix | Array
<
number
>
| 是 | 当前旋转矩阵。 |
| preRotationMatrix | Array
<
number
>
| 是 |
相对旋转矩阵
|
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | --------------------------------- |
| Promise
<
Array
<
number
>>
|
返回z、x、y轴方向的旋转角度变化
。 |
| Promise
<
Array
<
number
>>
|
Promise对象,返回绕z、x、y轴方向的旋转角度
。 |
**错误码**
:
...
...
@@ -2582,16 +2746,30 @@ getAngleVariation(currentRotationMatrix: Array<number>, preRotationMatrix:
```
js
try
{
const
promise
=
sensor
.
getAngleVariation
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
]);
promise
.
then
((
data
)
=>
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
}).
catch
((
reason
)
=>
{
console
.
info
(
'
promise::catch
'
,
reason
);
})
// 旋转矩阵可以为3*3,或者4*4
let
currentRotationMatrix
=
[
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
];
let
preRotationMatrix
=
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
];
const
promise
=
sensor
.
getAngleVariation
(
currentRotationMatrix
,
preRotationMatrix
);
promise
.
then
((
data
)
=>
{
if
(
data
.
length
<
3
)
{
console
.
error
(
"
Get angle variation failed, length
"
+
data
.
length
);
}
console
.
info
(
"
Z:
"
+
data
[
0
]);
console
.
info
(
"
X:
"
+
data
[
1
]);
console
.
info
(
"
Y :
"
+
data
[
2
]);
},
(
err
)
=>
{
console
.
error
(
'
Get angle variation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getAngleV
ariation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get angle v
ariation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2599,7 +2777,7 @@ try {
getRotationMatrix(rotationVector: Array
<
number
>
, callback: AsyncCallback
<Array
&
lt
;
number
&
gt
;
>
): void
将旋转向量转换为
旋转矩阵。
根据旋转矢量获取
旋转矩阵。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2607,8 +2785,8 @@ getRotationMatrix(rotationVector: Array<number>, callback: AsyncCallback<A
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ---------------------------------------- | ---- | -------------- |
| rotationVector | Array
<
number
>
| 是 |
表示
旋转矢量。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 |
返回
旋转矩阵。 |
| rotationVector | Array
<
number
>
| 是 | 旋转矢量。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 |
回调函数,返回3
*
3
旋转矩阵。 |
**错误码**
:
...
...
@@ -2622,13 +2800,18 @@ getRotationMatrix(rotationVector: Array<number>, callback: AsyncCallback<A
```
js
try
{
sensor
.
getRotationMatrix
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
],
function
(
data
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
})
let
rotationVector
=
[
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
];
sensor
.
getRotationMatrix
(
rotationVector
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
error
(
'
Get rotationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
})
}
catch
(
err
)
{
console
.
error
(
'
getR
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get r
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2636,7 +2819,7 @@ try {
getRotationMatrix(rotationVector: Array
<
number
>
): Promise
<Array
<
number
&
gt
;
>
将旋转向量转换为
旋转矩阵。
根据旋转矢量获取
旋转矩阵。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2644,13 +2827,13 @@ getRotationMatrix(rotationVector: Array<number>): Promise<Array<number>
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------------------- | ---- | -------------- |
| rotationVector | Array
<
number
>
| 是 |
表示
旋转矢量。 |
| rotationVector | Array
<
number
>
| 是 | 旋转矢量。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | -------------- |
| Promise
<
Array
<
number
>>
| 返回旋转矩阵。 |
| Promise
<
Array
<
number
>>
|
Promise对象,
返回旋转矩阵。 |
**错误码**
:
...
...
@@ -2664,16 +2847,17 @@ getRotationMatrix(rotationVector: Array<number>): Promise<Array<number>
```
js
try
{
const
promise
=
sensor
.
getRotationMatrix
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
]);
promise
.
then
((
data
)
=>
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
}).
catch
((
reason
)
=>
{
console
.
info
(
'
promise::catch
'
,
reason
);
})
let
rotationVector
=
[
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
];
const
promise
=
sensor
.
getRotationMatrix
(
rotationVector
);
promise
.
then
((
data
)
=>
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
},
(
err
)
=>
{
console
.
error
(
'
Get rotationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getR
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get r
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2682,7 +2866,7 @@ try {
transformRotationMatrix(inRotationVector: Array
<
number
>
, coordinates: CoordinatesOptions,
callback: AsyncCallback
<Array
&
lt
;
number
&
gt
;
>
): void
旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系
。
根据指定坐标系映射旋转矩阵
。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2690,11 +2874,11 @@ transformRotationMatrix(inRotationVector: Array<number>, coordinates: Coor
| 参数名 | 类型 | 必填 | 说明 |
| ---------------- | ----------------------------------------- | ---- | ---------------------- |
| inRotationVector | Array
<
number
>
| 是 |
表示
旋转矩阵。 |
| coordinates |
[
CoordinatesOptions
](
#coordinatesoptions
)
| 是 |
表示
坐标系方向。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 |
返回转换
后的旋转矩阵。 |
| inRotationVector | Array
<
number
>
| 是 | 旋转矩阵。 |
| coordinates |
[
CoordinatesOptions
](
#coordinatesoptions
)
| 是 |
指定
坐标系方向。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 |
回调函数,返回映射
后的旋转矩阵。 |
**错误码**
:
**错误码**
:
以下错误码的详细介绍请参见
[
sensor.transformRotationMatrix错误码
](
../errorcodes/errorcode-sensor.md
)
。
...
...
@@ -2706,13 +2890,22 @@ transformRotationMatrix(inRotationVector: Array<number>, coordinates: Coor
```
js
try
{
sensor
.
transformRotationMatrix
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
{
x
:
2
,
y
:
3
},
function
(
data
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
transformRotationMatrix data[
'
+
i
+
'
] =
'
+
data
[
i
]);
let
rotationMatrix
=
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
];
sensor
.
transformRotationMatrix
(
rotationMatrix
,
{
x
:
1
,
y
:
3
},
function
(
err
,
data
)
{
if
(
err
)
{
console
.
error
(
'
Transform rotationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
] =
'
+
data
[
i
]);
}
})
}
catch
(
err
)
{
console
.
error
(
'
transformR
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Transform r
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2720,7 +2913,7 @@ try {
transformRotationMatrix(inRotationVector: Array
<
number
>
, coordinates: CoordinatesOptions): Promise
<Array
&
lt
;
number
&
gt
;
>
旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系
。
根据指定坐标系映射旋转矩阵
。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2728,14 +2921,14 @@ transformRotationMatrix(inRotationVector: Array<number>, coordinates: Coor
| 参数名 | 类型 | 必填 | 说明 |
| ---------------- | ----------------------------------------- | ---- | ---------------- |
| inRotationVector | Array
<
number
>
| 是 |
表示
旋转矩阵。 |
| coordinates |
[
CoordinatesOptions
](
#coordinatesoptions
)
| 是 |
表示
坐标系方向。 |
| inRotationVector | Array
<
number
>
| 是 | 旋转矩阵。 |
| coordinates |
[
CoordinatesOptions
](
#coordinatesoptions
)
| 是 |
指定
坐标系方向。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | ---------------------- |
| Promise
<
Array
<
number
>>
| 返回转换后的旋转矩阵。 |
| Promise
<
Array
<
number
>>
|
Promise对象,
返回转换后的旋转矩阵。 |
**错误码**
:
...
...
@@ -2749,16 +2942,21 @@ transformRotationMatrix(inRotationVector: Array<number>, coordinates: Coor
```
js
try
{
const
promise
=
sensor
.
transformRotationMatrix
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
{
x
:
2
,
y
:
3
});
let
rotationMatrix
=
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
];
const
promise
=
sensor
.
transformRotationMatrix
(
rotationMatrix
,
{
x
:
1
,
y
:
3
});
promise
.
then
((
data
)
=>
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
transformRotationMatrix data[
'
+
i
+
'
] =
'
+
data
[
i
]);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
}
).
catch
(
(
err
)
=>
{
console
.
info
(
"
Operation failed
"
);
})
}
,
(
err
)
=>
{
console
.
error
(
'
Transform rotationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
transformR
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Transform r
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2766,7 +2964,7 @@ try {
getQuaternion(rotationVector: Array
<
number
>
, callback: AsyncCallback
<Array
&
lt
;
number
&
gt
;
>
): void
将旋转向量转换为
归一化四元数。
根据旋转向量计算
归一化四元数。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2774,8 +2972,8 @@ getQuaternion(rotationVector: Array<number>, callback: AsyncCallback<Array
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ---------------------------------------- | ---- | -------------- |
| rotationVector | Array
<
number
>
| 是 |
表示
旋转矢量。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 |
返回
四元数。 |
| rotationVector | Array
<
number
>
| 是 | 旋转矢量。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 |
回调函数,返回归一化
四元数。 |
**错误码**
:
...
...
@@ -2789,13 +2987,18 @@ getQuaternion(rotationVector: Array<number>, callback: AsyncCallback<Array
```
js
try
{
sensor
.
getQuaternion
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
],
function
(
data
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
})
let
rotationVector
=
[
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
];
sensor
.
getQuaternion
(
rotationVector
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
error
(
'
Get quaternion failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
})
}
catch
(
err
)
{
console
.
error
(
'
getQ
uaternion failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get q
uaternion failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2803,7 +3006,7 @@ try {
getQuaternion(rotationVector: Array
<
number
>
): Promise
<Array
&
lt
;
number
&
gt
;
>
将旋转向量转换为
归一化四元数。
根据旋转向量计算
归一化四元数。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2811,13 +3014,13 @@ getQuaternion(rotationVector: Array<number>): Promise<Array<number>>
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------------------- | ---- | -------------- |
| rotationVector | Array
<
number
>
| 是 |
表示
旋转矢量。 |
| rotationVector | Array
<
number
>
| 是 | 旋转矢量。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | ------------ |
| Promise
<
Array
<
number
>>
|
返
回四元数。 |
| Promise
<
Array
<
number
>>
|
Promise,对象返归一化
回四元数。 |
**错误码**
:
...
...
@@ -2831,17 +3034,17 @@ getQuaternion(rotationVector: Array<number>): Promise<Array<number>>
```
js
try
{
const
promise
=
sensor
.
getQuaternion
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
])
;
promise
.
then
((
data
)
=>
{
console
.
info
(
'
getQuaternionn_promise successed
'
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
}).
catch
(
(
err
)
=>
{
console
.
info
(
'
promise failed
'
);
})
let
rotationVector
=
[
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
]
;
const
promise
=
sensor
.
getQuaternion
(
rotationVector
);
promise
.
then
((
data
)
=>
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
},
(
err
)
=>
{
console
.
error
(
'
Get quaternion failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getQ
uaternion failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get q
uaternion failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2849,7 +3052,7 @@ try {
getOrientation(rotationMatrix: Array
<
number
>
, callback: AsyncCallback
<Array
&
lt
;
number
&
gt
;
>
): void
根据旋转矩阵计算设备
的
方向。
根据旋转矩阵计算设备方向。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -2857,8 +3060,8 @@ getOrientation(rotationMatrix: Array<number>, callback: AsyncCallback<Arra
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ---------------------------------------- | ---- | --------------------------------- |
| rotationMatrix | Array
<
number
>
| 是 |
表示
旋转矩阵。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 | 返回围绕z、x、y轴方向的旋转角度。 |
| rotationMatrix | Array
<
number
>
| 是 | 旋转矩阵。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 |
回调函数,
返回围绕z、x、y轴方向的旋转角度。 |
**错误码**
:
...
...
@@ -2872,14 +3075,25 @@ getOrientation(rotationMatrix: Array<number>, callback: AsyncCallback<Arra
```
js
try
{
sensor
.
getOrientation
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
function
(
data
)
{
console
.
info
(
"
SensorJsAPI--->Successed to get getOrientation interface get data:
"
+
data
);
for
(
var
i
=
1
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
sensor_getOrientation_callback
'
+
data
[
i
]);
}
})
let
preRotationMatrix
=
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
];
sensor
.
getOrientation
(
preRotationMatrix
,
function
(
err
,
data
)
{
if
(
err
)
{
console
.
error
(
'
Get orientation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
if
(
data
.
length
<
3
)
{
console
.
error
(
"
Get orientation failed, length
"
+
data
.
length
);
}
console
.
info
(
"
Z:
"
+
data
[
0
]);
console
.
info
(
"
X:
"
+
data
[
1
]);
console
.
info
(
"
Y :
"
+
data
[
2
]);
})
}
catch
(
err
)
{
console
.
error
(
'
getO
rientation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get o
rientation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2895,13 +3109,13 @@ getOrientation(rotationMatrix: Array<number>): Promise<Array<number>
| 参数名 | 类型 | 必填 | 说明 |
| -------------- | ------------------- | ---- | -------------- |
| rotationMatrix | Array
<
number
>
| 是 |
表示
旋转矩阵。 |
| rotationMatrix | Array
<
number
>
| 是 | 旋转矩阵。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | --------------------------------- |
| Promise
<
Array
<
number
>>
| 返回围绕z、x、y轴方向的旋转角度。 |
| Promise
<
Array
<
number
>>
|
Promise对象,
返回围绕z、x、y轴方向的旋转角度。 |
**错误码**
:
...
...
@@ -2915,17 +3129,21 @@ getOrientation(rotationMatrix: Array<number>): Promise<Array<number>
```
js
try
{
const
promise
=
sensor
.
getOrientation
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
]);
promise
.
then
((
data
)
=>
{
console
.
info
(
'
sensor_getOrientation_Promise success
'
,
data
);
for
(
var
i
=
1
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
sensor_getOrientation_promise
'
+
data
[
i
]);
}
}).
catch
((
err
)
=>
{
console
.
info
(
'
promise failed
'
);
})
}
catch
(
err
)
{
let
preRotationMatrix
=
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
];
const
promise
=
sensor
.
getOrientation
(
preRotationMatrix
);
promise
.
then
((
data
)
=>
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
data
[
i
]);
}
},
(
err
)
=>
{
console
.
error
(
'
getOrientation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getOrientation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2941,9 +3159,9 @@ getRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------------------------------------------------------------ | ---- | -------------- |
| gravity | Array
<
number
>
| 是 |
表示重力向
量。 |
| geomagnetic | Array
<
number
>
| 是 |
表示
地磁矢量。 |
| callback | AsyncCallback
<
[RotationMatrixResponse](#rotationmatrixresponse)
>
| 是 | 返回旋转矩阵。 |
| gravity | Array
<
number
>
| 是 |
重力矢
量。 |
| geomagnetic | Array
<
number
>
| 是 | 地磁矢量。 |
| callback | AsyncCallback
<
[RotationMatrixResponse](#rotationmatrixresponse)
>
| 是 |
回调函数,
返回旋转矩阵。 |
**错误码**
:
...
...
@@ -2957,11 +3175,17 @@ getRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>
```
js
try
{
sensor
.
getRotationMatrix
([
-
0.27775216
,
0.5351276
,
9.788099
],
[
210.87253
,
-
78.6096
,
-
111.44444
],
function
(
data
)
{
console
.
info
(
'
sensor_getRotationMatrix_callback
'
+
JSON
.
stringify
(
data
));
})
let
gravity
=
[
-
0.27775216
,
0.5351276
,
9.788099
];
let
geomagnetic
=
[
210.87253
,
-
78.6096
,
-
111.44444
];
sensor
.
getRotationMatrix
(
gravity
,
geomagnetic
,
function
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
Get rotationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
console
.
info
(
'
RotationMatrix
'
+
JSON
.
stringify
(
data
));
})
}
catch
(
err
)
{
console
.
error
(
'
getR
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get r
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -2977,14 +3201,14 @@ getRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>
| 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------------------- | ---- | -------------- |
| gravity | Array
<
number
>
| 是 |
表示
重力向量。 |
| geomagnetic | Array
<
number
>
| 是 |
表示
地磁矢量。 |
| gravity | Array
<
number
>
| 是 | 重力向量。 |
| geomagnetic | Array
<
number
>
| 是 | 地磁矢量。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------------ | -------------- |
| Promise
<
[RotationMatrixResponse](#rotationmatrixresponse)
>
| 返回旋转矩阵。 |
| Promise
<
[RotationMatrixResponse](#rotationmatrixresponse)
>
|
Promise对象,
返回旋转矩阵。 |
**错误码**
:
...
...
@@ -2998,20 +3222,22 @@ getRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>
```
js
try
{
const
promise
=
sensor
.
getRotationMatrix
([
-
0.27775216
,
0.5351276
,
9.788099
],
[
210.87253
,
-
78.6096
,
-
111.44444
]);
promise
.
then
((
data
)
=>
{
console
.
info
(
'
sensor_getRotationMatrix_callback
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
console
.
info
(
'
promise failed
'
);
})
let
gravity
=
[
-
0.27775216
,
0.5351276
,
9.788099
];
let
geomagnetic
=
[
210.87253
,
-
78.6096
,
-
111.44444
];
const
promise
=
sensor
.
getRotationMatrix
(
gravity
,
geomagnetic
);
promise
.
then
((
data
)
=>
{
console
.
info
(
'
RotationMatrix
'
+
JSON
.
stringify
(
data
));
},
(
err
)
=>
{
console
.
error
(
'
Get rotationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getR
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get r
otationMatrix failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
## sensor.getSensorList<sup>9+</sup>
getSensorList(callback: AsyncCallback
<Array
&
lt
;
Sensor
&
gt
;
>
): void
getSensorList(callback: AsyncCallback
<Array
&
lt
;
Sensor
&
gt
;
>
): void
获取设备上的所有传感器信息。
...
...
@@ -3021,7 +3247,7 @@ try {
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback
<Array
&
lt
;[
Sensor
](
#sensor9
)&
gt
;
>
| 是 |
返回传感器
列表。 |
| callback | AsyncCallback
<Array
&
lt
;[
Sensor
](
#sensor9
)&
gt
;
>
| 是 |
回调函数,返回传感器属性
列表。 |
**错误码**
:
...
...
@@ -3035,14 +3261,17 @@ try {
```
js
try
{
sensor
.
getSensorList
((
data
)
=>
{
console
.
info
(
'
getSensorList callback in
'
+
data
.
length
);
sensor
.
getSensorList
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
Get sensorList failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
"
getSensorList
"
+
JSON
.
stringify
(
data
[
i
]));
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
JSON
.
stringify
(
data
[
i
]));
}
});
}
catch
(
err
)
{
console
.
error
(
'
getS
ensorList failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get s
ensorList failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -3058,7 +3287,7 @@ try {
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ---------------------------------------- | ---- | ---------------- |
| promise | Promise
<Array
&
lt
;[
Sensor
](
#sensor9
)&
gt
;
>
| 是 |
返回传感器
列表。 |
| promise | Promise
<Array
&
lt
;[
Sensor
](
#sensor9
)&
gt
;
>
| 是 |
Promise对象,返回传感器属性
列表。 |
**错误码**
:
...
...
@@ -3073,15 +3302,14 @@ try {
```
js
try
{
sensor
.
getSensorList
().
then
((
data
)
=>
{
console
.
info
(
'
getSensorList promise in
'
+
data
.
length
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
"
getSensorList
"
+
JSON
.
stringify
(
data
[
i
]));
console
.
info
(
'
data[
'
+
i
+
'
]:
'
+
JSON
.
stringify
(
data
[
i
]));
}
},
(
err
or
)
=>
{
console
.
error
(
'
getSensorList failed
'
);
},
(
err
)
=>
{
console
.
error
(
'
Get sensorList failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getS
ensorList failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get s
ensorList failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -3089,7 +3317,7 @@ try {
getSingleSensor(type: SensorId, callback: AsyncCallback
<
Sensor
>
): void
获取指定
类型的传感器
信息。
获取指定
传感器类型的属性
信息。
**系统能力**
:SystemCapability.Sensors.Sensor
...
...
@@ -3097,8 +3325,8 @@ getSingleSensor(type: SensorId, callback: AsyncCallback<Sensor>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------- |
| type |
[
SensorId
](
#sensorid9
)
| 是 | 传感器类型。 |
| callback | AsyncCallback
<
[Sensor](#sensor9)
>
| 是 |
返回传感器
信息。 |
| type |
[
SensorId
](
#sensorid9
)
| 是 |
指定
传感器类型。 |
| callback | AsyncCallback
<
[Sensor](#sensor9)
>
| 是 |
回调函数,返回指定传感器的属性
信息。 |
**错误码**
:
...
...
@@ -3112,11 +3340,15 @@ getSingleSensor(type: SensorId, callback: AsyncCallback<Sensor>): void
```
js
try
{
sensor
.
getSingleSensor
(
sensor
.
SensorId
.
SENSOR_TYPE_ID_ACCELEROMETER
,
(
error
,
data
)
=>
{
console
.
info
(
'
getSingleSensor
'
+
JSON
.
stringify
(
data
));
sensor
.
getSingleSensor
(
sensor
.
SensorId
.
SENSOR_TYPE_ID_ACCELEROMETER
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
Get singleSensor failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
}
console
.
info
(
'
Sensor:
'
+
JSON
.
stringify
(
data
));
});
}
catch
(
err
)
{
console
.
error
(
'
getS
ingleSensor failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get s
ingleSensor failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -3153,12 +3385,12 @@ try {
```
js
try
{
sensor
.
getSingleSensor
(
sensor
.
SensorId
.
SENSOR_TYPE_ID_ACCELEROMETER
).
then
((
data
)
=>
{
console
.
info
(
'
getSingleSensor
'
+
JSON
.
stringify
(
data
));
},
(
err
or
)
=>
{
console
.
error
(
'
getSingleSensor failed
'
);
console
.
info
(
'
Sensor:
'
+
JSON
.
stringify
(
data
));
},
(
err
)
=>
{
console
.
error
(
'
Get singleSensor failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
});
}
catch
(
err
)
{
console
.
error
(
'
getS
ingleSensor failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Get s
ingleSensor failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
}
```
...
...
@@ -3247,11 +3479,11 @@ try {
| firmwareVersion | string | 传感器固件版本。 |
| hardwareVersion | string | 传感器硬件版本。 |
| sensorId | number | 传感器类型id。 |
| maxRange | number | 传感器
的最大测量范围
。 |
| maxRange | number | 传感器
测量范围的最大值
。 |
| minSamplePeriod | number | 允许的最小采样周期。 |
| maxSamplePeriod | number | 允许的最大采样周期。 |
| precision | number | 传感器精度。 |
| power | number | 传感器
电源
。 |
| power | number | 传感器
功率
。 |
## AccelerometerResponse
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录