Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
0b399738
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
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看板
提交
0b399738
编写于
6月 08, 2022
作者:
H
HelloCrease
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update docs
Signed-off-by:
N
HelloCrease
<
lian15@huawei.com
>
上级
fcfa5ea7
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
116 addition
and
115 deletion
+116
-115
zh-cn/application-dev/reference/apis/js-apis-sensor.md
zh-cn/application-dev/reference/apis/js-apis-sensor.md
+107
-107
zh-cn/application-dev/reference/apis/js-apis-vibrator.md
zh-cn/application-dev/reference/apis/js-apis-vibrator.md
+9
-8
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-sensor.md
浏览文件 @
0b399738
# 传感器
# 传感器
>

**说明:**
> **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
## 导入模块
```
```
js
import
sensor
from
'
@ohos.sensor
'
;
import
sensor
from
'
@ohos.sensor
'
;
```
```
...
@@ -30,7 +30,7 @@ on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<Acceler
...
@@ -30,7 +30,7 @@ on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<Acceler
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ACCELEROMETER
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ACCELEROMETER
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -59,7 +59,7 @@ on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<Line
...
@@ -59,7 +59,7 @@ on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<Line
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_LINEAR_ACCELERATION
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_LINEAR_ACCELERATION
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -88,7 +88,7 @@ on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback
...
@@ -88,7 +88,7 @@ on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -118,7 +118,7 @@ on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityRespons
...
@@ -118,7 +118,7 @@ on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityRespons
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GRAVITY
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GRAVITY
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -147,7 +147,7 @@ on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeRes
...
@@ -147,7 +147,7 @@ on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeRes
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -176,7 +176,7 @@ on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback<G
...
@@ -176,7 +176,7 @@ on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback<G
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -206,7 +206,7 @@ on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback<Sig
...
@@ -206,7 +206,7 @@ on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback<Sig
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_SIGNIFICANT_MOTION
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_SIGNIFICANT_MOTION
,
function
(
data
){
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
},
},
...
@@ -233,7 +233,7 @@ on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback<Pe
...
@@ -233,7 +233,7 @@ on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback<Pe
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PEDOMETER_DETECTION
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PEDOMETER_DETECTION
,
function
(
data
){
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
},
},
...
@@ -260,7 +260,7 @@ on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerRes
...
@@ -260,7 +260,7 @@ on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerRes
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PEDOMETER
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PEDOMETER
,
function
(
data
){
console
.
info
(
'
Steps:
'
+
data
.
steps
);
console
.
info
(
'
Steps:
'
+
data
.
steps
);
},
},
...
@@ -285,7 +285,7 @@ on(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback<Ambie
...
@@ -285,7 +285,7 @@ on(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback<Ambie
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_TEMPERATURE
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_TEMPERATURE
,
function
(
data
){
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
},
},
...
@@ -310,7 +310,7 @@ on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<Magneti
...
@@ -310,7 +310,7 @@ on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<Magneti
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -337,7 +337,7 @@ on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callbac
...
@@ -337,7 +337,7 @@ on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callbac
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -367,7 +367,7 @@ on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityRes
...
@@ -367,7 +367,7 @@ on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityRes
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PROXIMITY
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PROXIMITY
,
function
(
data
){
console
.
info
(
'
Distance:
'
+
data
.
distance
);
console
.
info
(
'
Distance:
'
+
data
.
distance
);
},
},
...
@@ -392,7 +392,7 @@ on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityRespo
...
@@ -392,7 +392,7 @@ on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityRespo
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HUMIDITY
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HUMIDITY
,
function
(
data
){
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
},
},
...
@@ -417,7 +417,7 @@ on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerRes
...
@@ -417,7 +417,7 @@ on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerRes
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_BAROMETER
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_BAROMETER
,
function
(
data
){
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
},
},
...
@@ -442,7 +442,7 @@ on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>,
...
@@ -442,7 +442,7 @@ on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>,
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HALL
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HALL
,
function
(
data
){
console
.
info
(
'
Status:
'
+
data
.
status
);
console
.
info
(
'
Status:
'
+
data
.
status
);
},
},
...
@@ -467,7 +467,7 @@ on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightRes
...
@@ -467,7 +467,7 @@ on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightRes
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_LIGHT
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_LIGHT
,
function
(
data
){
console
.
info
(
'
Illumination:
'
+
data
.
intensity
);
console
.
info
(
'
Illumination:
'
+
data
.
intensity
);
},
},
...
@@ -492,7 +492,7 @@ on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<Orientatio
...
@@ -492,7 +492,7 @@ on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<Orientatio
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ORIENTATION
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_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 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 Y axis:
'
+
data
.
gamma
);
...
@@ -521,7 +521,7 @@ on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateRe
...
@@ -521,7 +521,7 @@ on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateRe
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HEART_RATE
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HEART_RATE
,
function
(
data
){
console
.
info
(
"
Heart rate:
"
+
data
.
heartRate
);
console
.
info
(
"
Heart rate:
"
+
data
.
heartRate
);
},
},
...
@@ -545,7 +545,7 @@ on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback<Rotatio
...
@@ -545,7 +545,7 @@ on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback<Rotatio
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ROTATION_VECTOR
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ROTATION_VECTOR
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -573,7 +573,7 @@ on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDet
...
@@ -573,7 +573,7 @@ on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDet
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
| options |
[
Options
](
#options
)
| 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
**示例:**
**示例:**
```
```
js
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_WEAR_DETECTION
,
function
(
data
){
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_WEAR_DETECTION
,
function
(
data
){
console
.
info
(
'
Wear status:
'
+
data
.
value
);
console
.
info
(
'
Wear status:
'
+
data
.
value
);
},
},
...
@@ -599,7 +599,7 @@ once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<Accele
...
@@ -599,7 +599,7 @@ once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<Accele
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
| callback | Callback
<
[AccelerometerResponse](#accelerometerresponse)
>
| 是 | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ACCELEROMETER
,
function
(
data
){
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ACCELEROMETER
,
function
(
data
){
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -626,7 +626,7 @@ once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<Li
...
@@ -626,7 +626,7 @@ once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<Li
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
| callback | Callback
<
[LinearAccelerometerResponse](#linearaccelerometerresponse)
>
| 是 | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_LINEAR_ACCELERATION
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_LINEAR_ACCELERATION
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -681,7 +681,7 @@ once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityRespo
...
@@ -681,7 +681,7 @@ once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityRespo
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
| callback | Callback
<
[GravityResponse](#gravityresponse)
>
| 是 | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GRAVITY
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GRAVITY
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -708,7 +708,7 @@ once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeR
...
@@ -708,7 +708,7 @@ once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeR
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
| callback | Callback
<
[GyroscopeResponse](#gyroscoperesponse)
>
| 是 | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -735,7 +735,7 @@ once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback&l
...
@@ -735,7 +735,7 @@ once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback&l
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
| callback | Callback
<
[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)
>
| 是 | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -763,7 +763,7 @@ once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback<Si
...
@@ -763,7 +763,7 @@ once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback<Si
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
| callback | Callback
<
[SignificantMotionResponse](#significantmotionresponse)
>
| 是 | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_SIGNIFICANT_MOTION
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_SIGNIFICANT_MOTION
,
function
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
}
}
...
@@ -788,7 +788,7 @@ once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback<P
...
@@ -788,7 +788,7 @@ once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback<P
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
| callback | Callback
<
[PedometerDetectionResponse](#pedometerdetectionresponse)
>
| 是 | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PEDOMETER_DETECTION
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PEDOMETER_DETECTION
,
function
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
}
}
...
@@ -813,7 +813,7 @@ once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerR
...
@@ -813,7 +813,7 @@ once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerR
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
| callback | Callback
<
[PedometerResponse](#pedometerresponse)
>
| 是 | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PEDOMETER
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PEDOMETER
,
function
(
data
)
{
console
.
info
(
'
Steps:
'
+
data
.
steps
);
console
.
info
(
'
Steps:
'
+
data
.
steps
);
}
}
...
@@ -836,7 +836,7 @@ once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback<A
...
@@ -836,7 +836,7 @@ once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback<A
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
| callback | Callback
<
[AmbientTemperatureResponse](#ambienttemperatureresponse)
>
| 是 | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_TEMPERATURE
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_TEMPERATURE
,
function
(
data
)
{
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
}
}
...
@@ -859,7 +859,7 @@ once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<Magne
...
@@ -859,7 +859,7 @@ once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<Magne
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
| callback | Callback
<
[MagneticFieldResponse](#magneticfieldresponse)
>
| 是 | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -884,7 +884,7 @@ once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callb
...
@@ -884,7 +884,7 @@ once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callb
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
| callback | Callback
<
[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)
>
| 是 | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -912,7 +912,7 @@ once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityR
...
@@ -912,7 +912,7 @@ once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityR
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
| callback | Callback
<
[ProximityResponse](#proximityresponse)
>
| 是 | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PROXIMITY
,
function
(
error
,
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_PROXIMITY
,
function
(
error
,
data
)
{
if
(
error
)
{
if
(
error
)
{
console
.
error
(
"
Subscription failed. Error code:
"
+
error
.
code
+
"
; message:
"
+
error
.
message
);
console
.
error
(
"
Subscription failed. Error code:
"
+
error
.
code
+
"
; message:
"
+
error
.
message
);
...
@@ -939,7 +939,7 @@ once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityRes
...
@@ -939,7 +939,7 @@ once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityRes
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
| callback | Callback
<
[HumidityResponse](#humidityresponse)
>
| 是 | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HUMIDITY
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HUMIDITY
,
function
(
data
)
{
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
}
}
...
@@ -962,7 +962,7 @@ once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerR
...
@@ -962,7 +962,7 @@ once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerR
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
| callback | Callback
<
[BarometerResponse](#barometerresponse)
>
| 是 | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_BAROMETER
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_BAROMETER
,
function
(
data
)
{
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
}
}
...
@@ -985,7 +985,7 @@ once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>
...
@@ -985,7 +985,7 @@ once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
| callback | Callback
<
[HallResponse](#hallresponse)
>
| 是 | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HALL
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HALL
,
function
(
data
)
{
console
.
info
(
'
Status:
'
+
data
.
status
);
console
.
info
(
'
Status:
'
+
data
.
status
);
}
}
...
@@ -1008,7 +1008,7 @@ once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightR
...
@@ -1008,7 +1008,7 @@ once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightR
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |
| callback | Callback
<
[LightResponse](#lightresponse)
>
| 是 | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_LIGHT
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_LIGHT
,
function
(
data
)
{
console
.
info
(
'
Illumination:
'
+
data
.
intensity
);
console
.
info
(
'
Illumination:
'
+
data
.
intensity
);
}
}
...
@@ -1031,7 +1031,7 @@ once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<Orientat
...
@@ -1031,7 +1031,7 @@ once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<Orientat
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
| callback | Callback
<
[OrientationResponse](#orientationresponse)
>
| 是 | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ORIENTATION
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_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 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 Y axis:
'
+
data
.
gamma
);
...
@@ -1056,7 +1056,7 @@ once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback<Rota
...
@@ -1056,7 +1056,7 @@ once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback<Rota
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
| callback | Callback
<
[RotationVectorResponse](#rotationvectorresponse)
>
| 是 | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ROTATION_VECTOR
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ROTATION_VECTOR
,
function
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1084,7 +1084,7 @@ once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRate
...
@@ -1084,7 +1084,7 @@ once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRate
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
| callback | Callback
<
[HeartRateResponse](#heartrateresponse)
>
| 是 | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HEART_RATE
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_HEART_RATE
,
function
(
data
)
{
console
.
info
(
"
Heart rate:
"
+
data
.
heartRate
);
console
.
info
(
"
Heart rate:
"
+
data
.
heartRate
);
}
}
...
@@ -1107,7 +1107,7 @@ once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearD
...
@@ -1107,7 +1107,7 @@ once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearD
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
| callback | Callback
<
[WearDetectionResponse](#weardetectionresponse)
>
| 是 | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
**示例:**
**示例:**
```
```
js
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_WEAR_DETECTION
,
function
(
data
)
{
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_WEAR_DETECTION
,
function
(
data
)
{
console
.
info
(
"
Wear status:
"
+
data
.
value
);
console
.
info
(
"
Wear status:
"
+
data
.
value
);
}
}
...
@@ -1133,7 +1133,7 @@ off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback<Accele
...
@@ -1133,7 +1133,7 @@ off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback<Accele
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
x-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
x-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1161,7 +1161,7 @@ off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callb
...
@@ -1161,7 +1161,7 @@ off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callb
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1190,7 +1190,7 @@ off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback<LightR
...
@@ -1190,7 +1190,7 @@ off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback<LightR
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
Illumination:
'
+
data
.
intensity
);
console
.
info
(
'
Illumination:
'
+
data
.
intensity
);
}
}
...
@@ -1214,7 +1214,7 @@ off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback<
...
@@ -1214,7 +1214,7 @@ off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback<
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
console
.
info
(
'
Temperature:
'
+
data
.
temperature
);
}
}
...
@@ -1238,7 +1238,7 @@ off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback<BarometerR
...
@@ -1238,7 +1238,7 @@ off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback<BarometerR
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
console
.
info
(
'
Atmospheric pressure:
'
+
data
.
pressure
);
}
}
...
@@ -1262,7 +1262,7 @@ off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback<GravityRespo
...
@@ -1262,7 +1262,7 @@ off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback<GravityRespo
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1290,7 +1290,7 @@ off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback<GyroscopeR
...
@@ -1290,7 +1290,7 @@ off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback<GyroscopeR
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1318,7 +1318,7 @@ off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&
...
@@ -1318,7 +1318,7 @@ off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1344,7 +1344,7 @@ off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback<HallResponse>
...
@@ -1344,7 +1344,7 @@ off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback<HallResponse>
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
Status:
'
+
data
.
status
);
console
.
info
(
'
Status:
'
+
data
.
status
);
}
}
...
@@ -1370,7 +1370,7 @@ off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback<HeartRate
...
@@ -1370,7 +1370,7 @@ off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback<HeartRate
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
"
Heart rate:
"
+
data
.
heartRate
);
console
.
info
(
"
Heart rate:
"
+
data
.
heartRate
);
}
}
...
@@ -1396,7 +1396,7 @@ off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback<HumidityRes
...
@@ -1396,7 +1396,7 @@ off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback<HumidityRes
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
console
.
info
(
'
Humidity:
'
+
data
.
humidity
);
}
}
...
@@ -1422,7 +1422,7 @@ off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback<
...
@@ -1422,7 +1422,7 @@ off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback<
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1450,7 +1450,7 @@ sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback);
...
@@ -1450,7 +1450,7 @@ sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback);
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1476,7 +1476,7 @@ sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
...
@@ -1476,7 +1476,7 @@ sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1505,7 +1505,7 @@ sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callbac
...
@@ -1505,7 +1505,7 @@ sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callbac
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
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 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 Y axis:
'
+
data
.
gamma
);
...
@@ -1531,7 +1531,7 @@ off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback<PedometerR
...
@@ -1531,7 +1531,7 @@ off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback<PedometerR
**返回值:**
;
**返回值:**
;
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
Steps:
'
+
data
.
steps
);
console
.
info
(
'
Steps:
'
+
data
.
steps
);
}
}
...
@@ -1557,7 +1557,7 @@ off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback<
...
@@ -1557,7 +1557,7 @@ off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback<
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
}
}
...
@@ -1581,7 +1581,7 @@ off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback<ProximityR
...
@@ -1581,7 +1581,7 @@ off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback<ProximityR
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
Distance:
'
+
data
.
distance
);
console
.
info
(
'
Distance:
'
+
data
.
distance
);
}
}
...
@@ -1605,7 +1605,7 @@ off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback<Rota
...
@@ -1605,7 +1605,7 @@ off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback<Rota
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
X-coordinate component:
'
+
data
.
x
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
console
.
info
(
'
Y-coordinate component:
'
+
data
.
y
);
...
@@ -1632,7 +1632,7 @@ off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback<S
...
@@ -1632,7 +1632,7 @@ off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback<S
**示例:**
**示例:**
```
```
js
function
callback
(
data
)
{
function
callback
(
data
)
{
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
console
.
info
(
'
Scalar data:
'
+
data
.
scalar
);
}
}
...
@@ -1656,7 +1656,7 @@ off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback<WearD
...
@@ -1656,7 +1656,7 @@ off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback<WearD
**示例:**
**示例:**
```
```
js
function
accCallback
(
data
)
{
function
accCallback
(
data
)
{
console
.
info
(
'
Wear status:
'
+
data
.
value
);
console
.
info
(
'
Wear status:
'
+
data
.
value
);
}
}
...
@@ -1681,13 +1681,13 @@ transformCoordinateSystem(inRotationVector: Array<number>, coordinates: Co
...
@@ -1681,13 +1681,13 @@ transformCoordinateSystem(inRotationVector: Array<number>, coordinates: Co
**示例:**
**示例:**
```
```
js
sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {
'axisX':2, 'axisY'
:3}, function(err, data) {
sensor
.
transformCoordinateSystem
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
{
x
:
2
,
y
:
3
},
function
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
"
Operation failed. Error code:
"
+
err
.
code
+
"
, message:
"
+
err
.
message
);
console
.
error
(
"
Operation failed. Error code:
"
+
err
.
code
+
"
, message:
"
+
err
.
message
);
return
;
return
;
}
}
console.info("Operation successed. Data obtained: " + data
.x
);
console
.
info
(
"
Operation successed. Data obtained:
"
+
data
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
"
transformCoordinateSystem data[
"
+
i
+
"
] =
"
+
data
[
i
]);
console
.
info
(
"
transformCoordinateSystem data[
"
+
i
+
"
] =
"
+
data
[
i
]);
}
}
...
@@ -1716,8 +1716,8 @@ transformCoordinateSystem(inRotationVector: Array<number>, coordinates: Co
...
@@ -1716,8 +1716,8 @@ transformCoordinateSystem(inRotationVector: Array<number>, coordinates: Co
**示例:**
**示例:**
```
```
js
const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {
'axisX':2, 'axisY'
:3});
const
promise
=
sensor
.
transformCoordinateSystem
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
{
x
:
2
,
y
:
3
});
promise
.
then
((
data
)
=>
{
promise
.
then
((
data
)
=>
{
console
.
info
(
"
Operation successed.
"
);
console
.
info
(
"
Operation successed.
"
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
...
@@ -1744,8 +1744,8 @@ getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callba
...
@@ -1744,8 +1744,8 @@ getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callba
| callback | AsyncCallback
<
[GeomagneticResponse](#geomagneticresponse)
>
| 是 | 返回磁场信息。 |
| callback | AsyncCallback
<
[GeomagneticResponse](#geomagneticresponse)
>
| 是 | 返回磁场信息。 |
**示例:**
**示例:**
```
```
js
sensor.getGeomagneticField(
[80, 0, 0]
, 1580486400000, function(err, data) {
sensor
.
getGeomagneticField
(
{
latitude
:
80
,
longitude
:
0
,
altitude
:
0
}
,
1580486400000
,
function
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Operation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
console
.
error
(
'
Operation failed. Error code:
'
+
err
.
code
+
'
; message:
'
+
err
.
message
);
return
;
return
;
...
@@ -1775,8 +1775,8 @@ getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promi
...
@@ -1775,8 +1775,8 @@ getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promi
| Promise
<
[GeomagneticResponse](#geomagneticresponse)
>
| 返回磁场信息。 |
| Promise
<
[GeomagneticResponse](#geomagneticresponse)
>
| 返回磁场信息。 |
**返回值:**
**返回值:**
```
```
js
const promise = sensor.getGeomagneticField(
[80, 0, 0]
, 1580486400000);
const
promise
=
sensor
.
getGeomagneticField
(
{
latitude
:
80
,
longitude
:
0
,
altitude
:
0
}
,
1580486400000
);
promise
.
then
((
data
)
=>
{
promise
.
then
((
data
)
=>
{
console
.
info
(
'
sensor_getGeomagneticField_promise x:
'
+
data
.
x
+
'
,y:
'
+
data
.
y
+
'
,z:
'
+
console
.
info
(
'
sensor_getGeomagneticField_promise x:
'
+
data
.
x
+
'
,y:
'
+
data
.
y
+
'
,z:
'
+
data
.
z
+
'
,geomagneticDip:
'
+
data
.
geomagneticDip
+
'
,deflectionAngle:
'
+
data
.
deflectionAngle
+
data
.
z
+
'
,geomagneticDip:
'
+
data
.
geomagneticDip
+
'
,deflectionAngle:
'
+
data
.
deflectionAngle
+
...
@@ -1804,7 +1804,7 @@ getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallbac
...
@@ -1804,7 +1804,7 @@ getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallbac
**返回值:**
**返回值:**
```
```
js
sensor
.
getAltitude
(
0
,
200
,
function
(
err
,
data
)
{
sensor
.
getAltitude
(
0
,
200
,
function
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
console
.
error
(
...
@@ -1838,7 +1838,7 @@ getAltitude(seaPressure: number, currentPressure: number): Promise<number>
...
@@ -1838,7 +1838,7 @@ getAltitude(seaPressure: number, currentPressure: number): Promise<number>
**返回值:**
**返回值:**
```
```
js
const
promise
=
sensor
.
getAltitude
(
0
,
200
);
const
promise
=
sensor
.
getAltitude
(
0
,
200
);
promise
.
then
((
data
)
=>
{
promise
.
then
((
data
)
=>
{
console
.
info
(
'
sensor_getAltitude_Promise success
'
,
data
);
console
.
info
(
'
sensor_getAltitude_Promise success
'
,
data
);
...
@@ -1865,10 +1865,10 @@ getGeomagneticDip(inclinationMatrix: Array<number>, callback: AsyncCallbac
...
@@ -1865,10 +1865,10 @@ getGeomagneticDip(inclinationMatrix: Array<number>, callback: AsyncCallbac
**返回值:**
**返回值:**
```
```
js
sensor
.
getGeomagneticDip
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
function
(
err
,
data
)
{
sensor
.
getGeomagneticDip
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
function
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console.error(
LABEL +
'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
console
.
error
(
'
SensorJsAPI--->Failed to register data, error code is:
'
+
err
.
code
+
'
, message:
'
+
err
.
message
);
err
.
message
);
return
;
return
;
}
}
...
@@ -1898,7 +1898,7 @@ getGeomagneticDip(inclinationMatrix: Array<number>): Promise<number>
...
@@ -1898,7 +1898,7 @@ getGeomagneticDip(inclinationMatrix: Array<number>): Promise<number>
**返回值:**
**返回值:**
```
```
js
const
promise
=
sensor
.
getGeomagneticDip
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
]);
const
promise
=
sensor
.
getGeomagneticDip
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
]);
promise
.
then
((
data
)
=>
{
promise
.
then
((
data
)
=>
{
console
.
info
(
'
getGeomagneticDip_promise successed
'
,
data
);
console
.
info
(
'
getGeomagneticDip_promise successed
'
,
data
);
...
@@ -1925,10 +1925,10 @@ getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Ar
...
@@ -1925,10 +1925,10 @@ getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Ar
**返回值:**
**返回值:**
```
```
js
sensor
.
getAngleModify
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
],
function
(
err
,
data
)
{
sensor
.
getAngleModify
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
],
function
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console.error(
LABEL +
'Failed to register data, error code is: ' + err.code + ', message: ' +
console
.
error
(
'
Failed to register data, error code is:
'
+
err
.
code
+
'
, message:
'
+
err
.
message
);
err
.
message
);
return
;
return
;
}
}
...
@@ -1963,10 +1963,10 @@ getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Ar
...
@@ -1963,10 +1963,10 @@ getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Ar
**返回值:**
**返回值:**
```
```
js
const
promise
=
sensor
.
getAngleModify
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
[
1
,
0
,
0
,
0
,
0.87
,
-
0.50
,
0
,
0.50
,
0.87
]);
const
promise
=
sensor
.
getAngleModify
([
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
)
=>
{
promise
.
then
((
data
)
=>
{
console.info(
LABEL +
'getAngleModifiy_promise success');
console
.
info
(
'
getAngleModifiy_promise success
'
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
LABEL
+
"
data[
"
+
i
+
"
]:
"
+
data
[
i
]);
console
.
info
(
LABEL
+
"
data[
"
+
i
+
"
]:
"
+
data
[
i
]);
}
}
...
@@ -1993,10 +1993,10 @@ createRotationMatrix(rotationVector: Array<number>, callback: AsyncCallbac
...
@@ -1993,10 +1993,10 @@ createRotationMatrix(rotationVector: Array<number>, callback: AsyncCallbac
**返回值:**
**返回值:**
```
```
js
sensor
.
createRotationMatrix
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
],
function
(
err
,
data
)
{
sensor
.
createRotationMatrix
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
],
function
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console.error(
LABEL +
'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
console
.
error
(
'
SensorJsAPI--->Failed to register data, error code is:
'
+
err
.
code
+
'
, message:
'
+
err
.
message
);
err
.
message
);
return
;
return
;
}
}
...
@@ -2030,10 +2030,10 @@ createRotationMatrix(rotationVector: Array<number>): Promise<Array<n
...
@@ -2030,10 +2030,10 @@ createRotationMatrix(rotationVector: Array<number>): Promise<Array<n
**返回值:**
**返回值:**
```
```
js
const
promise
=
sensor
.
createRotationMatrix
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
]);
const
promise
=
sensor
.
createRotationMatrix
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
]);
promise
.
then
((
data
)
=>
{
promise
.
then
((
data
)
=>
{
console.info(
LABEL +
'createRotationMatrix_promise success');
console
.
info
(
'
createRotationMatrix_promise success
'
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
LABEL
+
"
data[
"
+
i
+
"
]:
"
+
data
[
i
]);
console
.
info
(
LABEL
+
"
data[
"
+
i
+
"
]:
"
+
data
[
i
]);
}
}
...
@@ -2060,10 +2060,10 @@ createQuaternion(rotationVector: Array<number>, callback: AsyncCallback<
...
@@ -2060,10 +2060,10 @@ createQuaternion(rotationVector: Array<number>, callback: AsyncCallback<
**返回值:**
**返回值:**
```
```
js
sensor
.
createQuaternion
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
],
function
(
err
,
data
)
{
sensor
.
createQuaternion
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
],
function
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console.error(
LABEL +
'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
console
.
error
(
'
SensorJsAPI--->Failed to register data, error code is:
'
+
err
.
code
+
'
, message:
'
+
err
.
message
);
err
.
message
);
return
;
return
;
}
}
...
@@ -2097,12 +2097,12 @@ createQuaternion(rotationVector: Array<number>): Promise<Array<numbe
...
@@ -2097,12 +2097,12 @@ createQuaternion(rotationVector: Array<number>): Promise<Array<numbe
**返回值:**
**返回值:**
```
```
js
const
promise
=
sensor
.
createQuaternion
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
]);
const
promise
=
sensor
.
createQuaternion
([
0.20046076
,
0.21907
,
0.73978853
,
0.60376877
]);
promise
.
then
((
data
)
=>
{
promise
.
then
((
data
)
=>
{
console
.
info
(
'
createQuaternion_promise successed
'
);
console
.
info
(
'
createQuaternion_promise successed
'
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console.info(
LABEL +
"data[" + i + "]: " + data[i]);
console
.
info
(
"
data[
"
+
i
+
"
]:
"
+
data
[
i
]);
}
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
'
promise failed
'
);
console
.
info
(
'
promise failed
'
);
...
@@ -2127,16 +2127,16 @@ getDirection(rotationMatrix: Array<number>, callback: AsyncCallback<Arr
...
@@ -2127,16 +2127,16 @@ getDirection(rotationMatrix: Array<number>, callback: AsyncCallback<Arr
**返回值:**
**返回值:**
```
```
js
sensor
.
getDirection
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
function
(
err
,
data
)
{
sensor
.
getDirection
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
function
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console.error(
LABEL +
'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
console
.
error
(
'
SensorJsAPI--->Failed to register data, error code is:
'
+
err
.
code
+
'
, message:
'
+
err
.
message
);
err
.
message
);
return
;
return
;
}
}
console.info(
LABEL +
"SensorJsAPI--->Successed to get getDirection interface get data: " + data.x);
console
.
info
(
"
SensorJsAPI--->Successed to get getDirection interface get data:
"
+
data
.
x
);
for
(
var
i
=
1
;
i
<
data
.
length
;
i
++
)
{
for
(
var
i
=
1
;
i
<
data
.
length
;
i
++
)
{
console.info(
TAG +
"sensor_getDirection_callback" + data[i]);
console
.
info
(
"
sensor_getDirection_callback
"
+
data
[
i
]);
}
}
})
})
```
```
...
@@ -2164,12 +2164,12 @@ getDirection(rotationMatrix: Array<number>): Promise<Array<number>
...
@@ -2164,12 +2164,12 @@ getDirection(rotationMatrix: Array<number>): Promise<Array<number>
**返回值:**
**返回值:**
```
```
js
const
promise
=
sensor
.
getDirection
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
]);
const
promise
=
sensor
.
getDirection
([
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
]);
promise
.
then
((
data
)
=>
{
promise
.
then
((
data
)
=>
{
console.info('
sensor_getAltitude_Promise success', data.x);
console
.
info
(
'
sensor_getAltitude_Promise success
'
,
data
.
x
);
for
(
var
i
=
1
;
i
<
data
.
length
;
i
++
)
{
for
(
var
i
=
1
;
i
<
data
.
length
;
i
++
)
{
console.info(
TAG +
"sensor_getDirection_promise" + data[i]);
console
.
info
(
"
sensor_getDirection_promise
"
+
data
[
i
]);
}
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
'
promise failed
'
);
console
.
info
(
'
promise failed
'
);
...
@@ -2195,16 +2195,16 @@ createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number&
...
@@ -2195,16 +2195,16 @@ createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number&
**返回值:**
**返回值:**
```
```
js
sensor
.
createRotationMatrix
([
-
0.27775216
,
0.5351276
,
9.788099
],
[
210.87253
,
-
78.6096
,
-
111.44444
],
function
(
err
,
data
)
{
sensor
.
createRotationMatrix
([
-
0.27775216
,
0.5351276
,
9.788099
],
[
210.87253
,
-
78.6096
,
-
111.44444
],
function
(
err
,
data
)
{
if
(
err
)
{
if
(
err
)
{
console.error(
LABEL +
'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
console
.
error
(
'
SensorJsAPI--->Failed to register data, error code is:
'
+
err
.
code
+
'
, message:
'
+
err
.
message
);
err
.
message
);
return
;
return
;
}
}
console
.
info
(
"
SensorJsAPI--->Successed to get createRotationMatrix interface get data:
"
+
data
.
x
);
console
.
info
(
"
SensorJsAPI--->Successed to get createRotationMatrix interface get data:
"
+
data
.
x
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console.info(
LABEL +
"data[" + i + "]: " + data[i])
console
.
info
(
"
data[
"
+
i
+
"
]:
"
+
data
[
i
])
}
}
})
})
```
```
...
@@ -2233,15 +2233,15 @@ createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number&
...
@@ -2233,15 +2233,15 @@ createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number&
**返回值:**
**返回值:**
```
```
js
const
promise
=
sensor
.
createRotationMatrix
([
-
0.27775216
,
0.5351276
,
9.788099
],
[
210.87253
,
-
78.6096
,
-
111.44444
]);
const
promise
=
sensor
.
createRotationMatrix
([
-
0.27775216
,
0.5351276
,
9.788099
],
[
210.87253
,
-
78.6096
,
-
111.44444
]);
promise
.
then
((
data
)
=>
{
promise
.
then
((
data
)
=>
{
console.info(
LABEL +
'createRotationMatrix_promise successed');
console
.
info
(
'
createRotationMatrix_promise successed
'
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
info
(
LABEL
+
"
data[
"
+
i
+
"
]:
"
+
data
[
i
]);
console
.
info
(
LABEL
+
"
data[
"
+
i
+
"
]:
"
+
data
[
i
]);
}
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console.info(
LABEL +
'promise failed');
console
.
info
(
'
promise failed
'
);
})
})
```
```
...
@@ -2356,7 +2356,7 @@ createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number&
...
@@ -2356,7 +2356,7 @@ createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number&
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ----- | ------ | ---- | ---- | -----------------
-------
|
| ----- | ------ | ---- | ---- | ----------------- |
| alpha | number | 是 | 是 | 设备围绕Z轴的旋转角度,单位:度。 |
| alpha | number | 是 | 是 | 设备围绕Z轴的旋转角度,单位:度。 |
| beta | number | 是 | 是 | 设备围绕X轴的旋转角度,单位:度。 |
| beta | number | 是 | 是 | 设备围绕X轴的旋转角度,单位:度。 |
| gamma | number | 是 | 是 | 设备围绕Y轴的旋转角度,单位:度。 |
| gamma | number | 是 | 是 | 设备围绕Y轴的旋转角度,单位:度。 |
...
...
zh-cn/application-dev/reference/apis/js-apis-vibrator.md
浏览文件 @
0b399738
# 振动
# 振动
>  **说明:**
> **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
## 导入模块
```
```
js
import
vibrator
from
'
@ohos.vibrator
'
;
import
vibrator
from
'
@ohos.vibrator
'
;
```
```
...
@@ -34,7 +35,7 @@ vibrate(duration: number): Promise<void>
...
@@ -34,7 +35,7 @@ vibrate(duration: number): Promise<void>
**示例:**
**示例:**
```
```
js
vibrator
.
vibrate
(
1000
).
then
(()
=>
{
vibrator
.
vibrate
(
1000
).
then
(()
=>
{
console
.
log
(
"
Promise returned to indicate a successful vibration.
"
);
console
.
log
(
"
Promise returned to indicate a successful vibration.
"
);
},
(
error
)
=>
{
},
(
error
)
=>
{
...
@@ -60,7 +61,7 @@ vibrate(duration: number, callback?: AsyncCallback<void>): void
...
@@ -60,7 +61,7 @@ vibrate(duration: number, callback?: AsyncCallback<void>): void
| callback | AsyncCallback
<
void
>
| 否 | 马达执行振动的回调函数,指示触发振动是否成功。 |
| callback | AsyncCallback
<
void
>
| 否 | 马达执行振动的回调函数,指示触发振动是否成功。 |
**示例:**
**示例:**
```
```
js
vibrator
.
vibrate
(
1000
,
function
(
error
){
vibrator
.
vibrate
(
1000
,
function
(
error
){
if
(
error
){
if
(
error
){
console
.
log
(
"
error.code
"
+
error
.
code
+
"
error.message
"
+
error
.
message
);
console
.
log
(
"
error.code
"
+
error
.
code
+
"
error.message
"
+
error
.
message
);
...
@@ -92,7 +93,7 @@ vibrate(effectId: EffectId): Promise<void>
...
@@ -92,7 +93,7 @@ vibrate(effectId: EffectId): Promise<void>
| Promise
<
void
>
| 指示触发振动是否成功。 |
| Promise
<
void
>
| 指示触发振动是否成功。 |
**示例:**
**示例:**
```
```
js
vibrator
.
vibrate
(
vibrator
.
EffectId
.
EFFECT_CLOCK_TIMER
).
then
(()
=>
{
vibrator
.
vibrate
(
vibrator
.
EffectId
.
EFFECT_CLOCK_TIMER
).
then
(()
=>
{
console
.
log
(
"
Promise returned to indicate a successful vibration.
"
);
console
.
log
(
"
Promise returned to indicate a successful vibration.
"
);
},
(
error
)
=>
{
},
(
error
)
=>
{
...
@@ -118,7 +119,7 @@ vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void
...
@@ -118,7 +119,7 @@ vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void
| callback | AsyncCallback
<
void
>
| 否 | 马达执行振动的回调函数,指示触发振动是否成功。 |
| callback | AsyncCallback
<
void
>
| 否 | 马达执行振动的回调函数,指示触发振动是否成功。 |
**示例:**
**示例:**
```
```
js
vibrator
.
vibrate
(
vibrator
.
EffectId
.
EFFECT_CLOCK_TIMER
,
function
(
error
){
vibrator
.
vibrate
(
vibrator
.
EffectId
.
EFFECT_CLOCK_TIMER
,
function
(
error
){
if
(
error
){
if
(
error
){
console
.
log
(
"
error.code
"
+
error
.
code
+
"
error.message
"
+
error
.
message
);
console
.
log
(
"
error.code
"
+
error
.
code
+
"
error.message
"
+
error
.
message
);
...
@@ -150,7 +151,7 @@ stop(stopMode: VibratorStopMode): Promise<void>
...
@@ -150,7 +151,7 @@ stop(stopMode: VibratorStopMode): Promise<void>
| Promise
<
void
>
| 指示停止振动是否成功。 |
| Promise
<
void
>
| 指示停止振动是否成功。 |
**示例:**
**示例:**
```
```
js
vibrator
.
stop
(
vibrator
.
VibratorStopMode
.
VIBRATOR_STOP_MODE_PRESET
).
then
(()
=>
{
vibrator
.
stop
(
vibrator
.
VibratorStopMode
.
VIBRATOR_STOP_MODE_PRESET
).
then
(()
=>
{
console
.
log
(
"
Promise returned to indicate a successful vibration.
"
);
console
.
log
(
"
Promise returned to indicate a successful vibration.
"
);
},
(
error
)
=>
{
},
(
error
)
=>
{
...
@@ -176,7 +177,7 @@ stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void;
...
@@ -176,7 +177,7 @@ stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void;
| callback | AsyncCallback
<
void
>
| 否 | 马达停止振动的回调函数,指示停止振动是否成功。 |
| callback | AsyncCallback
<
void
>
| 否 | 马达停止振动的回调函数,指示停止振动是否成功。 |
**示例:**
**示例:**
```
```
js
vibrator
.
stop
(
vibrator
.
VibratorStopMode
.
VIBRATOR_STOP_MODE_PRESET
,
function
(
error
){
vibrator
.
stop
(
vibrator
.
VibratorStopMode
.
VIBRATOR_STOP_MODE_PRESET
,
function
(
error
){
if
(
error
){
if
(
error
){
console
.
log
(
"
error.code
"
+
error
.
code
+
"
error.message
"
+
error
.
message
);
console
.
log
(
"
error.code
"
+
error
.
code
+
"
error.message
"
+
error
.
message
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录