js-apis-sensor.md 85.9 KB
Newer Older
Z
zengyawen 已提交
1
# 传感器
Z
zengyawen 已提交
2

Z
zengyawen 已提交
3 4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Z
zengyawen 已提交
5

Z
zengyawen 已提交
6 7

## 导入模块
Z
zengyawen 已提交
8 9 10 11 12

```
import sensor from '@ohos.sensor';
```

Z
zengyawen 已提交
13

14
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER)
Z
zengyawen 已提交
15

16
on(type:  sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback<AccelerometerResponse>,options?: Options): void
Z
zengyawen 已提交
17 18 19

监听加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。

C
cff-gite 已提交
20 21 22 23
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
24

Z
zengyawen 已提交
25 26 27 28 29 30
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
  | callback | AsyncCallback<[AccelerometerResponse](#accelerometerresponse)> | 是 | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |
Z
zengyawen 已提交
31

Z
zengyawen 已提交
32 33
- 示例:
  ```
34
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){
Z
zengyawen 已提交
35 36 37 38
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
39
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
40 41
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
42 43
  },
      {interval: 10000000}
Z
zengyawen 已提交
44 45
  );
  ```
Z
zengyawen 已提交
46 47


48
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
Z
zengyawen 已提交
49

50
on(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback<LinearAccelerometerResponse>, options?: Options): void
Z
zengyawen 已提交
51

Z
zengyawen 已提交
52 53
监听线性加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。

C
cff-gite 已提交
54 55 56 57
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
58 59 60 61 62 63 64 65 66
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
  | callback | AsyncCallback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | 是 | 注册线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
67 68
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(error,data){
      if (error) {
Z
zengyawen 已提交
69 70 71 72 73 74
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
75 76
  },
      {interval: 10000000}
Z
zengyawen 已提交
77 78
  );
  ```
Z
zengyawen 已提交
79 80


81
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)
Z
zengyawen 已提交
82

83
on(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback<AccelerometerUncalibratedResponse>, options?: Options): void
Z
zengyawen 已提交
84

Z
zengyawen 已提交
85
监听未校准加速度计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
86

C
cff-gite 已提交
87 88 89 90
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
91 92 93 94 95 96 97 98 99
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的未校准加速度计传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
  | callback | AsyncCallback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | 是 | 注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
100
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(error,data){
Z
zengyawen 已提交
101 102 103 104 105 106 107 108 109 110
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      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);
111 112
  },
      {interval: 10000000}
Z
zengyawen 已提交
113 114
  );
  ```
Z
zengyawen 已提交
115 116


117
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY)
Z
zengyawen 已提交
118

119
on(type: sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<GravityResponse>,options?: Options): void
Z
zengyawen 已提交
120

Z
zengyawen 已提交
121
监听重力传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
122

C
cff-gite 已提交
123 124
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
125 126 127 128 129 130 131 132 133
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。 |
  | callback | AsyncCallback<[GravityResponse](#gravityresponse)> | 是 | 注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
134
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(error,data){
Z
zengyawen 已提交
135 136 137 138
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
139
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
140 141
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
142 143
  },
      {interval: 10000000}
Z
zengyawen 已提交
144 145
  );
  ```
Z
zengyawen 已提交
146 147


148
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE)
Z
zengyawen 已提交
149

150
on(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<GyroscopeResponse>, options?: Options): void
Z
zengyawen 已提交
151

Z
zengyawen 已提交
152
监听陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
153

C
cff-gite 已提交
154
**需要权限**:ohos.permission.GYROSCOPE ,该权限为系统权限
C
cff-gite 已提交
155 156 157

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
158 159 160 161 162 163 164 165 166
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。 |
  | callback | AsyncCallback<[GyroscopeResponse](#gyroscoperesponse)> | 是 | 注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
167
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(error,data){
Z
zengyawen 已提交
168 169 170 171
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
172
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
173 174
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
175 176
  },
      {interval: 10000000}
Z
zengyawen 已提交
177 178
  );
  ```
Z
zengyawen 已提交
179 180


181
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)
Z
zengyawen 已提交
182

183
on(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback<GyroscopeUncalibratedResponse>, options?: Options): void
Z
zengyawen 已提交
184

Z
zengyawen 已提交
185
监听未校准陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
186

C
cff-gite 已提交
187
**需要权限**:ohos.permission.GYROSCOPE ,该权限为系统权限
C
cff-gite 已提交
188 189 190

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
191 192 193 194 195 196 197 198 199
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
  | callback | AsyncCallback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | 是 | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率。 |

- 示例:
  ```
200
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(error,data){
Z
zengyawen 已提交
201 202 203 204
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
205
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
206 207
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
208
      console.info('X-coordinate bias: ' + data.biasX);
Z
zengyawen 已提交
209 210
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
211 212
  },
      {interval: 10000000}
Z
zengyawen 已提交
213 214
  );
  ```
Z
zengyawen 已提交
215 216


217
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
Z
zengyawen 已提交
218

219
on(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: AsyncCallback<SignificantMotionResponse>, options?: Options): void
Z
zengyawen 已提交
220

Z
zengyawen 已提交
221
监听大幅动作传感器数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
222

C
cff-gite 已提交
223 224
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
225 226 227
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
228
  | type | [SensorType](#sensortype) | 是 | 要订阅的大幅动作传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
Z
zengyawen 已提交
229 230 231 232 233
  | callback | AsyncCallback<[SignificantMotionResponse](#significantmotionresponse)> | 是 | 注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
234
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(error,data){
Z
zengyawen 已提交
235 236 237 238 239
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Scalar data: ' + data.scalar);
240 241
  },
      {interval: 10000000}
Z
zengyawen 已提交
242 243
  );
  ```
Z
zengyawen 已提交
244 245


246
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)
Z
zengyawen 已提交
247

C
cff-gite 已提交
248
on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: AsyncCallback<PedometerDetectionResponse>, options?: Options): void
Z
zengyawen 已提交
249

Z
zengyawen 已提交
250
监听计步检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
251

C
cff-gite 已提交
252
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
253 254 255

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
256 257 258 259
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
C
cff-gite 已提交
260
  | callback | AsyncCallback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | 是 | 注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
Z
zengyawen 已提交
261 262 263 264
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
265
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(error,data){
Z
zengyawen 已提交
266
      if (error) {
267
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
Z
zengyawen 已提交
268 269 270
          return;
      }
      console.info('Scalar data: ' + data.scalar);
271 272
  },
      {interval: 10000000}
Z
zengyawen 已提交
273 274
  );
  ```
Z
zengyawen 已提交
275 276


277
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER)
Z
zengyawen 已提交
278

279
on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<PedometerResponse>, options?: Options): void
Z
zengyawen 已提交
280

Z
zengyawen 已提交
281
监听计步传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
282

C
cff-gite 已提交
283
**需要权限**:ohos.permission.ACTIVITY_MOTION 
C
cff-gite 已提交
284 285 286

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
287 288 289 290 291 292 293 294 295
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。 |
  | callback | AsyncCallback<[PedometerResponse](#pedometerresponse)> | 是 | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
296
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(error,data){
Z
zengyawen 已提交
297 298 299 300 301
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Steps: ' + data.steps);
302 303
  },
      {interval: 10000000}
Z
zengyawen 已提交
304 305
  );
  ```
Z
zengyawen 已提交
306 307


308
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
Z
zengyawen 已提交
309

310
on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback<AmbientTemperatureResponse>,  options?: Options): void
Z
zengyawen 已提交
311

Z
zengyawen 已提交
312
监听环境温度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
313

C
cff-gite 已提交
314 315
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
316 317 318 319 320 321 322 323 324
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
  | callback | AsyncCallback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | 是 | 注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
325
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(error,data){
Z
zengyawen 已提交
326 327 328 329 330
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Temperature: ' + data.temperature);
331 332
  },
      {interval: 10000000}
Z
zengyawen 已提交
333 334
  );
  ```
Z
zengyawen 已提交
335 336


337
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
Z
zengyawen 已提交
338

339
on(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback<MagneticFieldResponse>,options?: Options): void
Z
zengyawen 已提交
340

Z
zengyawen 已提交
341
监听磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
342

C
cff-gite 已提交
343 344
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
345 346 347 348 349 350 351 352 353
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。 |
  | callback | AsyncCallback<[MagneticFieldResponse](#magneticfieldresponse)> | 是 | 注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
354
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(error,data){
Z
zengyawen 已提交
355 356 357 358 359 360 361
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
362 363
  },
      {interval: 10000000}
Z
zengyawen 已提交
364 365
  );
  ```
Z
zengyawen 已提交
366 367


368
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
Z
zengyawen 已提交
369

370
on(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback<MagneticFieldUncalibratedResponse>, options: Options): void
Z
zengyawen 已提交
371

Z
zengyawen 已提交
372
监听未校准磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
373

C
cff-gite 已提交
374 375
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
376 377 378 379 380 381 382 383 384
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
  | callback | AsyncCallback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | 是 | 注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
385
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(error,data){
Z
zengyawen 已提交
386 387 388 389
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
390 391 392 393
      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);
Z
zengyawen 已提交
394 395
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
396 397
  },
      {interval: 10000000}
Z
zengyawen 已提交
398 399
  );
  ```
Z
zengyawen 已提交
400 401


402
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY)
Z
zengyawen 已提交
403

404
on(type:sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<ProximityResponse>,options?: Options): void
Z
zengyawen 已提交
405

Z
zengyawen 已提交
406
监听接近光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
407

C
cff-gite 已提交
408 409
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
410 411 412 413 414 415 416 417 418
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。 |
  | callback | AsyncCallback<[ProximityResponse](#proximityresponse)> | 是 | 注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
419
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(error,data){
Z
zengyawen 已提交
420 421 422 423 424
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Distance: ' + data.distance);
425 426
  },
      {interval: 10000000}
Z
zengyawen 已提交
427 428
  );
  ```
Z
zengyawen 已提交
429 430


431
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY)
Z
zengyawen 已提交
432

433
on(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<HumidityResponse>,options?: Options): void
Z
zengyawen 已提交
434

Z
zengyawen 已提交
435
监听湿度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
436

C
cff-gite 已提交
437 438
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
439 440 441 442 443 444 445 446 447
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。 |
  | callback | AsyncCallback<[HumidityResponse](#humidityresponse)> | 是 | 注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
448
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(error,data){
Z
zengyawen 已提交
449 450 451 452 453
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Humidity: ' + data.humidity);
454 455
  },
      {interval: 10000000}
Z
zengyawen 已提交
456 457
  );
  ```
Z
zengyawen 已提交
458 459


460
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER)
Z
zengyawen 已提交
461

462
on(type:sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<BarometerResponse>,options?: Options): void
Z
zengyawen 已提交
463

Z
zengyawen 已提交
464
监听气压计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
465

C
cff-gite 已提交
466 467
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
468 469 470 471 472 473 474 475 476
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。 |
  | callback | AsyncCallback<[BarometerResponse](#barometerresponse)> | 是 | 注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
477
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(error,data){
Z
zengyawen 已提交
478 479 480 481 482
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Atmospheric pressure: ' + data.pressure);
483 484
  },
      {interval: 10000000}
Z
zengyawen 已提交
485 486
  );
  ```
Z
zengyawen 已提交
487 488


489
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL)
Z
zengyawen 已提交
490

491
on(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<HallResponse>, options?: Options): void
Z
zengyawen 已提交
492

Z
zengyawen 已提交
493
监听霍尔传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
494

C
cff-gite 已提交
495 496
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
497 498 499 500 501 502 503 504 505
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。 |
  | callback | AsyncCallback<[HallResponse](#hallresponse)> | 是 | 注册霍尔传感器的回调函数,上报的数据类型为 HallResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
506
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(error,data){
Z
zengyawen 已提交
507 508 509 510 511
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Status: ' + data.status);
512 513
  },
      {interval: 10000000}
Z
zengyawen 已提交
514 515
  );
  ```
Z
zengyawen 已提交
516 517


518
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)
Z
zengyawen 已提交
519

520
on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback<LightResponse>, options?: Options): void
Z
zengyawen 已提交
521

Z
zengyawen 已提交
522
监听环境光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
523

C
cff-gite 已提交
524 525
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
526 527 528 529 530 531 532 533 534
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
  | callback | AsyncCallback<[LightResponse](#lightresponse)> | 是 | 注册环境光传感器的回调函数,上报的数据类型为LightResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
535
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(error,data){
Z
zengyawen 已提交
536 537 538 539
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
540 541 542
      console.info(' Illumination: ' + data.intensity);
  },
      {interval: 10000000}
Z
zengyawen 已提交
543 544
  );
  ```
Z
zengyawen 已提交
545 546


547
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION)
Z
zengyawen 已提交
548

549
on(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback<OrientationResponse>, options?: Options): void
Z
zengyawen 已提交
550

Z
zengyawen 已提交
551
监听方向传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
552

C
cff-gite 已提交
553 554
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
555 556 557 558 559 560 561 562 563
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION |
  | callback | AsyncCallback<[OrientationResponse](#orientationresponse)> | 是 | 注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
564
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(error,data){
Z
zengyawen 已提交
565 566 567 568 569 570 571
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
572 573
  },
      {interval: 10000000}
Z
zengyawen 已提交
574 575
  );
  ```
Z
zengyawen 已提交
576 577


578
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)
Z
zengyawen 已提交
579

580
on(type:sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback:AsyncCallback<RotationVectorResponse>,options?: Options): void
Z
zengyawen 已提交
581

Z
zengyawen 已提交
582
监听旋转矢量传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
583

C
cff-gite 已提交
584 585
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
586 587 588 589 590 591 592 593 594
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
  | callback | AsyncCallback<[RotationVectorResponse](#rotationvectorresponse)> | 是 | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
595
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(error,data){
Z
zengyawen 已提交
596 597 598 599 600 601 602
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
603 604
  },
      {interval: 10000000}
Z
zengyawen 已提交
605 606
  );
  ```
Z
zengyawen 已提交
607 608


609
## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)
Z
zengyawen 已提交
610

611
on(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback<WearDetectionResponse>,options?: Options): void
Z
zengyawen 已提交
612

Z
zengyawen 已提交
613
监听佩戴检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
614

C
cff-gite 已提交
615 616
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
617 618 619 620 621 622 623 624 625
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
  | callback | AsyncCallback<[WearDetectionResponse](#weardetectionresponse)> | 是 | 注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
  | options | [Options](#options) | 否 | 可选参数列表,设置上报频率,默认值为200000000ns。 |

- 示例:
  ```
626
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(error,data){
Z
zengyawen 已提交
627 628 629 630 631
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Wear status: ' + data.value);
632 633
  },
      {interval: 10000000}
Z
zengyawen 已提交
634 635
  );
  ```
Z
zengyawen 已提交
636 637


638
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER)
Z
zengyawen 已提交
639

640
once(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback<AccelerometerResponse>): void
Z
zengyawen 已提交
641

Z
zengyawen 已提交
642
监听加速度传感器的数据变化一次。
Z
zengyawen 已提交
643

C
cff-gite 已提交
644 645 646 647
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
648 649 650 651 652 653 654 655
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
  | callback | AsyncCallback<[AccelerometerResponse](#accelerometerresponse)> | 是 | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |

- 示例:
  ```
656
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){
Z
zengyawen 已提交
657 658 659 660 661 662 663
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
664
    }
Z
zengyawen 已提交
665 666
  );
  ```
Z
zengyawen 已提交
667 668


669
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
Z
zengyawen 已提交
670

671
once(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback<LinearAccelerometerResponse>): void
Z
zengyawen 已提交
672

Z
zengyawen 已提交
673
监听线性加速度传感器数据变化一次。
Z
zengyawen 已提交
674

C
cff-gite 已提交
675 676 677 678
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
679 680 681 682 683 684 685 686
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
  | callback | AsyncCallback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | 是 | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |

- 示例:
  ```
687
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(error, data) {
Z
zengyawen 已提交
688 689 690 691 692 693 694
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
695
    }
Z
zengyawen 已提交
696 697
  );
  ```
Z
zengyawen 已提交
698 699


700
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)
Z
zengyawen 已提交
701

702
once(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback<AccelerometerUncalibratedResponse>): void
Z
zengyawen 已提交
703

Z
zengyawen 已提交
704
监听未校准加速度传感器的数据变化一次。
Z
zengyawen 已提交
705

C
cff-gite 已提交
706 707 708 709
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
710 711 712 713 714 715 716 717
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 未校准加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
  | callback | AsyncCallback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | 是 | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |

- 示例:
  ```
718
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(error, data) {
Z
zengyawen 已提交
719 720 721 722 723 724 725 726 727 728
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      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);
Z
zengyawen 已提交
729
    }
Z
zengyawen 已提交
730 731
  );
  ```
Z
zengyawen 已提交
732 733


734
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY)
Z
zengyawen 已提交
735

736
once(type:sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<GravityResponse>): void
Z
zengyawen 已提交
737

Z
zengyawen 已提交
738
监听重力传感器的数据变化一次。
Z
zengyawen 已提交
739

C
cff-gite 已提交
740 741
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
742 743 744 745 746 747 748 749
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 重力传感器类型为SENSOR_TYPE_ID_GRAVITY。 |
  | callback | AsyncCallback<[GravityResponse](#gravityresponse)> | 是 | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |

- 示例:
  ```
750
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(error, data) {
Z
zengyawen 已提交
751 752 753 754 755 756 757
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
758
    }
Z
zengyawen 已提交
759 760
  );
  ```
Z
zengyawen 已提交
761 762


763
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE)
Z
zengyawen 已提交
764

765
once(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<GyroscopeResponse>): void
Z
zengyawen 已提交
766

Z
zengyawen 已提交
767
监听陀螺仪传感器的数据变化一次。
Z
zengyawen 已提交
768

C
cff-gite 已提交
769 770 771 772
**需要权限**:ohos.permission.GYROSCOPE ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
773 774 775 776 777 778 779 780
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。 |
  | callback | AsyncCallback<[GyroscopeResponse](#gyroscoperesponse)> | 是 | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |

- 示例:
  ```
781
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(error, data) {
Z
zengyawen 已提交
782 783 784 785 786 787 788
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
789
    }
Z
zengyawen 已提交
790 791
  );
  ```
Z
zengyawen 已提交
792 793


794
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)
Z
zengyawen 已提交
795

796
once(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback<GyroscopeUncalibratedResponse>): void
Z
zengyawen 已提交
797

Z
zengyawen 已提交
798
监听未校准陀螺仪传感器的数据变化一次。
Z
zengyawen 已提交
799

C
cff-gite 已提交
800 801 802 803
**需要权限**:ohos.permission.GYROSCOPE ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
804 805 806 807 808 809 810 811
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
  | callback | AsyncCallback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | 是 | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |

- 示例:
  ```
812
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(error, data) {
Z
zengyawen 已提交
813 814 815 816 817 818 819 820 821 822
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      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);
Z
zengyawen 已提交
823
    }
Z
zengyawen 已提交
824 825
  );
  ```
Z
zengyawen 已提交
826 827


828
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
Z
zengyawen 已提交
829

830
once(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback:AsyncCallback<SignificantMotionResponse>): void
Z
zengyawen 已提交
831

Z
zengyawen 已提交
832
监听有效运动传感器的数据变化一次。
Z
zengyawen 已提交
833

C
cff-gite 已提交
834 835
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
836 837 838 839 840 841 842 843
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
  | callback | AsyncCallback<[SignificantMotionResponse](#significantmotionresponse)> | 是 | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |

- 示例:
  ```
844
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(error, data) {
Z
zengyawen 已提交
845 846 847 848 849
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Scalar data: ' + data.scalar);
Z
zengyawen 已提交
850
    }
Z
zengyawen 已提交
851 852
  );
  ```
Z
zengyawen 已提交
853 854


855
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)
Z
zengyawen 已提交
856

C
cff-gite 已提交
857
once(type:sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback:AsyncCallback<PedometerDetectionResponse>): void
Z
zengyawen 已提交
858

Z
zengyawen 已提交
859
监听计步检测传感器数据变化一次。
Z
zengyawen 已提交
860

C
cff-gite 已提交
861
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
862 863 864

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
865 866 867 868
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
C
cff-gite 已提交
869
  | callback | AsyncCallback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | 是 | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
Z
zengyawen 已提交
870 871 872

- 示例:
  ```
873
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(error, data) {
Z
zengyawen 已提交
874 875 876 877 878
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Scalar data: ' + data.scalar);
Z
zengyawen 已提交
879
    }
Z
zengyawen 已提交
880 881
  );
  ```
Z
zengyawen 已提交
882 883


884
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER)
Z
zengyawen 已提交
885

886
once(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<PedometerResponse>): void
Z
zengyawen 已提交
887

Z
zengyawen 已提交
888
监听计步器传感器数据变化一次。
Z
zengyawen 已提交
889

C
cff-gite 已提交
890
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
891 892 893

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
894 895 896 897 898 899 900 901
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。 |
  | callback | AsyncCallback<[PedometerResponse](#pedometerresponse)> | 是 | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |

- 示例:
  ```
902
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(error, data) {
Z
zengyawen 已提交
903 904 905 906 907
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Steps: ' + data.steps);
Z
zengyawen 已提交
908
    }
Z
zengyawen 已提交
909 910
  );
  ```
Z
zengyawen 已提交
911 912


913
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
Z
zengyawen 已提交
914

915
once(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback<AmbientTemperatureResponse>): void
Z
zengyawen 已提交
916

Z
zengyawen 已提交
917
监听环境温度传感器数据变化一次。
Z
zengyawen 已提交
918

C
cff-gite 已提交
919 920
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
921 922 923 924 925 926 927 928
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
  | callback | AsyncCallback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | 是 | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |

- 示例:
  ```
929
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(error, data) {
Z
zengyawen 已提交
930 931 932 933 934
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Temperature: ' + data.temperature);
Z
zengyawen 已提交
935
    }
Z
zengyawen 已提交
936 937
  );
  ```
Z
zengyawen 已提交
938 939


940
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
Z
zengyawen 已提交
941

942
once(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback<MagneticFieldResponse>): void
Z
zengyawen 已提交
943

Z
zengyawen 已提交
944
监听磁场传感器数据变化一次。
Z
zengyawen 已提交
945

C
cff-gite 已提交
946 947
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
948 949 950 951 952 953 954 955
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。 |
  | callback | AsyncCallback<[MagneticFieldResponse](#magneticfieldresponse)> | 是 | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |

- 示例:
  ```
956
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(error, data) {
Z
zengyawen 已提交
957 958 959 960 961 962 963
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
964
    }
Z
zengyawen 已提交
965 966
  );
  ```
Z
zengyawen 已提交
967 968


969
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
Z
zengyawen 已提交
970

971
once(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback<MagneticFieldUncalibratedResponse>): void
Z
zengyawen 已提交
972

Z
zengyawen 已提交
973
监听未校准磁场传感器数据变化一次。
Z
zengyawen 已提交
974

C
cff-gite 已提交
975 976
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
977 978 979 980 981 982 983 984
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
  | callback | AsyncCallback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | 是 | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |

- 示例:
  ```
985
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(error, data) {
Z
zengyawen 已提交
986 987 988 989 990 991 992 993 994 995
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      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);
Z
zengyawen 已提交
996
    }
Z
zengyawen 已提交
997 998
  );
  ```
Z
zengyawen 已提交
999 1000


1001
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY)
Z
zengyawen 已提交
1002

1003
once(type: sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<ProximityResponse>): void
Z
zengyawen 已提交
1004

Z
zengyawen 已提交
1005
监听接近光传感器数据变化一次。
Z
zengyawen 已提交
1006

C
cff-gite 已提交
1007 1008
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1009 1010 1011 1012 1013 1014 1015 1016
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。 |
  | callback | AsyncCallback<[ProximityResponse](#proximityresponse)> | 是 | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |

- 示例:
  ```
1017
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(error, data) {
Z
zengyawen 已提交
1018 1019 1020 1021 1022
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Distance: ' + data.distance);
Z
zengyawen 已提交
1023
    }
Z
zengyawen 已提交
1024 1025
  );
  ```
Z
zengyawen 已提交
1026 1027


1028
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY)
Z
zengyawen 已提交
1029

1030
once(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<HumidityResponse>): void
Z
zengyawen 已提交
1031

Z
zengyawen 已提交
1032
监听湿度传感器数据变化一次。
Z
zengyawen 已提交
1033

C
cff-gite 已提交
1034 1035
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1036 1037 1038 1039 1040 1041 1042 1043
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。 |
  | callback | AsyncCallback<[HumidityResponse](#humidityresponse)> | 是 | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |

- 示例:
  ```
1044
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(error, data) {
Z
zengyawen 已提交
1045 1046 1047 1048 1049
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Humidity: ' + data.humidity);
Z
zengyawen 已提交
1050
    }
Z
zengyawen 已提交
1051 1052
  );
  ```
Z
zengyawen 已提交
1053 1054


1055
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER)
Z
zengyawen 已提交
1056

1057
once(type: sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<BarometerResponse>): void
Z
zengyawen 已提交
1058

Z
zengyawen 已提交
1059
监听气压计传感器数据变化一次。
Z
zengyawen 已提交
1060

C
cff-gite 已提交
1061 1062
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1063 1064 1065 1066 1067 1068 1069 1070
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。 |
  | callback | AsyncCallback<[BarometerResponse](#barometerresponse)> | 是 | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |

- 示例:
  ```
1071
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(error, data) {
Z
zengyawen 已提交
1072 1073 1074 1075 1076
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Atmospheric pressure: ' + data.pressure);
Z
zengyawen 已提交
1077
    }
Z
zengyawen 已提交
1078 1079
  );
  ```
Z
zengyawen 已提交
1080 1081


1082
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL)
Z
zengyawen 已提交
1083

1084
once(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback:   AsyncCallback<HallResponse>): void
Z
zengyawen 已提交
1085

Z
zengyawen 已提交
1086
监听霍尔传感器数据变化一次。
Z
zengyawen 已提交
1087

C
cff-gite 已提交
1088 1089
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1090 1091 1092 1093 1094 1095 1096 1097
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 霍尔传感器类型为SENSOR_TYPE_ID_HALL。 |
  | callback | AsyncCallback<[HallResponse](#hallresponse)> | 是 | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |

- 示例:
  ```
1098
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(error, data) {
Z
zengyawen 已提交
1099 1100 1101 1102 1103
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('Status: ' + data.status);
Z
zengyawen 已提交
1104
    }
Z
zengyawen 已提交
1105 1106
  );
  ```
Z
zengyawen 已提交
1107 1108


1109
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)
Z
zengyawen 已提交
1110

1111
once(type: sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback<LightResponse>): void
Z
zengyawen 已提交
1112

Z
zengyawen 已提交
1113
监听环境光传感器数据变化一次。
Z
zengyawen 已提交
1114

C
cff-gite 已提交
1115 1116
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1117 1118 1119 1120 1121 1122 1123 1124
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
  | callback | AsyncCallback<[LightResponse](#lightresponse)> | 是 | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |

- 示例:
  ```
1125
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(error, data) {
Z
zengyawen 已提交
1126 1127 1128 1129
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
1130
      console.info(' Illumination: ' + data.intensity);
Z
zengyawen 已提交
1131
    }
Z
zengyawen 已提交
1132 1133
  );
  ```
Z
zengyawen 已提交
1134 1135


1136
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION)
Z
zengyawen 已提交
1137

1138
once(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback<OrientationResponse>): void
Z
zengyawen 已提交
1139

Z
zengyawen 已提交
1140
监听方向传感器数据变化一次。
Z
zengyawen 已提交
1141

C
cff-gite 已提交
1142 1143
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1144 1145 1146 1147 1148 1149 1150 1151
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。 |
  | callback | AsyncCallback<[OrientationResponse](#orientationresponse)> | 是 | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |

- 示例:
  ```
1152
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(error, data) {
Z
zengyawen 已提交
1153 1154 1155 1156 1157 1158 1159
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
1160
    }
Z
zengyawen 已提交
1161 1162
  );
  ```
Z
zengyawen 已提交
1163 1164


1165
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)
Z
zengyawen 已提交
1166

1167
once(type: sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: AsyncCallback<RotationVectorResponse>): void
Z
zengyawen 已提交
1168

Z
zengyawen 已提交
1169
监听旋转矢量传感器数据变化一次。
Z
zengyawen 已提交
1170

C
cff-gite 已提交
1171 1172
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1173 1174 1175 1176 1177 1178 1179 1180
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
  | callback | AsyncCallback<[RotationVectorResponse](#rotationvectorresponse)> | 是 | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |

- 示例:
  ```
1181
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(error, data) {
Z
zengyawen 已提交
1182 1183 1184 1185 1186 1187 1188
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
1189
    }
Z
zengyawen 已提交
1190 1191
  );
  ```
Z
zengyawen 已提交
1192 1193


1194
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE)
Z
zengyawen 已提交
1195

1196
once(type: sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: AsyncCallback<HeartRateResponse>): void
Z
zengyawen 已提交
1197

Z
zengyawen 已提交
1198
监听心率传感器数据变化一次。
Z
zengyawen 已提交
1199

C
cff-gite 已提交
1200
**需要权限**:ohos.permission.READ_HEALTH_DATA 
C
cff-gite 已提交
1201 1202 1203

**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1204 1205 1206 1207 1208 1209 1210 1211
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。 |
  | callback | AsyncCallback<[HeartRateResponse](#heartrateresponse)> | 是 | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |

- 示例:
  ```
1212
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(error, data) {
Z
zengyawen 已提交
1213 1214 1215 1216 1217
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info("Heart rate: " + data.heartRate);
Z
zengyawen 已提交
1218
    }
Z
zengyawen 已提交
1219 1220
  );
  ```
Z
zengyawen 已提交
1221 1222


1223
## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)
Z
zengyawen 已提交
1224

1225
once(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback<WearDetectionResponse>): void
Z
zengyawen 已提交
1226

Z
zengyawen 已提交
1227
监听佩戴检测传感器数据变化一次。
Z
zengyawen 已提交
1228

C
cff-gite 已提交
1229 1230
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1231 1232 1233 1234 1235 1236 1237 1238
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
  | callback | AsyncCallback<[WearDetectionResponse](#weardetectionresponse)> | 是 | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |

- 示例:
  ```
1239
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(error, data) {
Z
zengyawen 已提交
1240 1241 1242 1243 1244
      if (error) {
          console.error("Failed to register data, error code is" + error.code + ", message: " + error.message);
          return;
      }
      console.info("Wear status: "+ data.value);
Z
zengyawen 已提交
1245
    }
Z
zengyawen 已提交
1246 1247
  );
  ```
Z
zengyawen 已提交
1248 1249


Z
zengyawen 已提交
1250
## sensor.off
Z
zengyawen 已提交
1251

Z
zengyawen 已提交
1252
off(type: SensorType, callback?: AsyncCallback<void>): void
Z
zengyawen 已提交
1253

Z
zengyawen 已提交
1254
取消订阅传感器数据。
Z
zengyawen 已提交
1255

C
cff-gite 已提交
1256 1257
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1258 1259 1260 1261 1262 1263 1264 1265
- 参数:
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | type | [SensorType](#sensortype) | 是 | 要取消订阅的传感器类型。 |
  | callback | AsyncCallback<void> | 是 | 取消订阅的传感器的回调函数,表示接口调用是否成功。 |

- 示例:
  ```
1266
  sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(error) {
Z
zengyawen 已提交
1267 1268 1269 1270 1271
      if (error) {
          console.error("Failed to unsubscribe from acceleration sensor data. Error code: " + error.code + "; message: " + error.message);
          return;
      }
      console.info("Succeeded in unsubscribing from acceleration sensor data.");
Z
zengyawen 已提交
1272
    }
Z
zengyawen 已提交
1273 1274
  );
  ```
Z
zengyawen 已提交
1275

Z
zengyawen 已提交
1276 1277 1278 1279 1280 1281
## sensor.transformCoordinateSystem

transformCoordinateSystem(inRotationVector: Array<number>, coordinates: CoordinatesOptions, callback: AsyncCallback<Array<number>>): void

旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。

C
cff-gite 已提交
1282 1283
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312
- 参数

  | 参数名           | 类型                                      | 必填 | 说明                   |
  | ---------------- | ----------------------------------------- | ---- | ---------------------- |
  | inRotationVector | Array<number>                       | 是   | 表示旋转矩阵。         |
  | coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是   | 表示坐标系方向。       |
  | callback         | AsyncCallback<Array<number>>  | 是   | 返回转换后的旋转矩阵。 |

- 示例

  ```
  sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {'axisX':2, 'axisY':3}, function(err, data) {
      if (err) {
          console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
          return;
      }
      console.info("Operation successed. Data obtained: " + data.x);
      for (var i=0; i < data.length; i++) {
          console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
      }
   })
  ```

## sensor.transformCoordinateSystem

transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;

旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。

C
cff-gite 已提交
1313 1314
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
- 参数

  | 参数名           | 类型                                      | 必填 | 说明             |
  | ---------------- | ----------------------------------------- | ---- | ---------------- |
  | inRotationVector | Array&lt;number&gt;                       | 是   | 表示旋转矩阵。   |
  | coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是   | 表示坐标系方向。 |

- 返回值

  | 类型                               | 说明                   |
  | ---------------------------------- | ---------------------- |
  | Promise&lt;Array&lt;number&gt;&gt; | 返回转换后的旋转矩阵。 |

- 示例

  ```
  const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {'axisX':2, 'axisY':3});
      promise.then((data) => {
          console.info("Operation successed.");
          for (var i=0; i < data.length; i++) {
              console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
          }
      }).catch((err) => {
             console.info("Operation failed");
  })
  ```

  

Z
zengyawen 已提交
1344

Z
zengyawen 已提交
1345
## sensor.getGeomagneticField
Z
zengyawen 已提交
1346

Z
zengyawen 已提交
1347
getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
Z
zengyawen 已提交
1348

Z
zengyawen 已提交
1349
获取地球上特定位置的地磁场。
Z
zengyawen 已提交
1350

C
cff-gite 已提交
1351 1352
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1353 1354 1355
- 参数
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
  | locationOptions | [LocationOptions](#locationoptions) | 是 | 地理位置。 |
  | timeMillis | number | 是 | 表示获取磁偏角的时间,单位为毫秒。 |
  | callback | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 是 | 返回磁场信息。 |

- 示例
  ```
  sensor.getGeomagneticField([80, 0, 0], {'timeMillis':1580486400000}, function(err, data)  {
      if (err) {
          console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
          return;
      }
      console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
  	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
  		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
  });
  ```


## sensor.getGeomagneticField

getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;

获取地球上特定位置的地磁场。

C
cff-gite 已提交
1380 1381
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1382 1383 1384 1385 1386
- 参数
  | 参数名 | 类型 | 必填 | 说明 |
  | -------- | -------- | -------- | -------- |
  | locationOptions | [LocationOptions](#locationoptions) | 是 | 地理位置。 |
  | timeMillis | number | 是 | 表示获取磁偏角的时间,单位为毫秒。 |
Z
zengyawen 已提交
1387 1388 1389 1390

- 返回值
  | 类型 | 说明 |
  | -------- | -------- |
Z
zengyawen 已提交
1391
  | Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |
Z
zengyawen 已提交
1392 1393 1394

- 示例
  ```
Z
zengyawen 已提交
1395
  const promise = sensor.getGeomagneticField([80, 0, 0], {'timeMillis':1580486400000});
Z
zengyawen 已提交
1396
      promise.then((data) => {
Z
zengyawen 已提交
1397 1398 1399
          console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
  	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
  		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
Z
zengyawen 已提交
1400
      }).catch((reason) => {
Z
zengyawen 已提交
1401 1402
          console.info('Operation failed.');
  })
Z
zengyawen 已提交
1403 1404
  ```

Z
zengyawen 已提交
1405 1406 1407 1408 1409 1410
## sensor.getAltitude

getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback&lt;number&gt;): void

根据气压值获取设备所在的海拔高度。

C
cff-gite 已提交
1411 1412
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
- 参数

  | 参数名          | 类型                        | 必填 | 说明                                  |
  | --------------- | --------------------------- | ---- | ------------------------------------- |
  | seaPressure     | number                      | 是   | 表示海平面气压值,单位为hPa。         |
  | currentPressure | number                      | 是   | 表示设备所在高度的气压值,单位为hPa。 |
  | callback        | AsyncCallback&lt;number&gt; | 是   | 返回设备所在的海拔高度,单位为米。    |

- 示例

  ```
  sensor.getAltitude(0, 200, function(err, data)  {
      if (err) {
          console.error(
  "Operation failed. Error code: " + err.code + ", message: " + err.message);
          return;
      }
          console.info("Successed to get getAltitude interface get data: " + data);
  });
  ```

## sensor.getAltitude

getAltitude(seaPressure: number, currentPressure: number): Promise&lt;number&gt;

根据气压值获取设备所在的海拔高度。

C
cff-gite 已提交
1440 1441
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
- 参数

  | 参数名          | 类型   | 必填 | 说明                                  |
  | --------------- | ------ | ---- | ------------------------------------- |
  | seaPressure     | number | 是   | 表示海平面气压值,单位为hPa。         |
  | currentPressure | number | 是   | 表示设备所在高度的气压值,单位为hPa。 |

- 返回值

  | 类型                  | 说明                                 |
  | --------------------- | ------------------------------------ |
  | Promise&lt;number&gt; | 返回设备所在的海拔高度(单位:米)。 |

- 示例

  ```
  const promise = sensor.getAltitude(0, 200);
      promise.then((data) => {
          console.info(' sensor_getAltitude_Promise success', data);
      }).catch((err) => {
          console.error("Operation failed");
  })
  ```


## sensor.getGeomagneticDip

getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void

根据倾斜矩阵计算地磁倾斜角。

C
cff-gite 已提交
1473 1474
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
- 参数

  | 参数名            | 类型                        | 必填 | 说明                         |
  | ----------------- | --------------------------- | ---- | ---------------------------- |
  | inclinationMatrix | Array&lt;number&gt;         | 是   | 表示倾斜矩阵。               |
  | callback          | AsyncCallback&lt;number&gt; | 是   | 返回地磁倾斜角,单位为弧度。 |

- 示例

  ```
  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
          console.info(Successed to get getGeomagneticDip interface get data: " + data);
  })
  ```

## sensor.getGeomagneticDip

getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;

根据倾斜矩阵计算地磁倾斜角。

C
cff-gite 已提交
1501 1502
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
- 参数

  | 参数名            | 类型                | 必填 | 说明           |
  | ----------------- | ------------------- | ---- | -------------- |
  | inclinationMatrix | Array&lt;number&gt; | 是   | 表示倾斜矩阵。 |

- 返回值

  | 类型                  | 说明                         |
  | --------------------- | ---------------------------- |
  | Promise&lt;number&gt; | 返回地磁倾斜角,单位为弧度。 |

- 示例

  ```
  const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info(' getGeomagneticDip_promise successed', data);
      }).catch((err) => {
           console.error("Operation failed");
  })
  ```

## sensor. getAngleModify

getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;,callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

获取两个旋转矩阵之间的角度变化。

C
cff-gite 已提交
1532 1533
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564
- 参数

  | 参数名                | 类型                                     | 必填 | 说明                              |
  | --------------------- | ---------------------------------------- | ---- | --------------------------------- |
  | currentRotationMatrix | Array&lt;number&gt;                      | 是   | 表示当前旋转矩阵。                |
  | preRotationMatrix     | Array&lt;number&gt;                      | 是   | 表示旋转矩阵。                    |
  | callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 返回z、x、y轴方向的旋转角度变化。 |

- 示例

  ```
  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) {
          console.error(LABEL + 'Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get  getAngleModifiy interface get data: " + data.x);
      for (var i=0; i < data.length; i++) {
          console.info(LABEL + "data[" + i + "]: " + data[i]);
      }
  })
  ```


## sensor. getAngleModify

getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

获取两个旋转矩阵之间的角度变化。

C
cff-gite 已提交
1565 1566
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1567 1568 1569 1570 1571
- 参数

  | 参数名                | 类型                | 必填 | 说明               |
  | --------------------- | ------------------- | ---- | ------------------ |
  | currentRotationMatrix | Array&lt;number&gt; | 是   | 表示当前旋转矩阵。 |
W
wusongqing 已提交
1572
  | preRotationMatrix     | Array&lt;number&gt; | 是   | 表示旋转矩阵。 |
Z
zengyawen 已提交
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600

- 返回值

  | 类型                               | 说明                              |
  | ---------------------------------- | --------------------------------- |
  | Promise&lt;Array&lt;number&gt;&gt; | 返回z、x、y轴方向的旋转角度变化。 |

- 示例

  ```
  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) => {
          console.info(LABEL + 'getAngleModifiy_promise success');
          for (var i=0; i < data.length; i++) {
              console.info(LABEL + "data[" + i + "]: " + data[i]);
          }
      }).catch((reason) => {
          console.info(LABEL + "promise::catch", reason);
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

将旋转矢量转换为旋转矩阵。

C
cff-gite 已提交
1601 1602
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632
- 参数

  | 参数名         | 类型                                     | 必填 | 说明           |
  | -------------- | ---------------------------------------- | ---- | -------------- |
  | rotationVector | Array&lt;number&gt;                      | 是   | 表示旋转矢量。 |
  | callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 返回旋转矩阵。 |

- 示例

  ```
  sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get createRotationMatrix interface get data: " + data.x);
      for (var i=0; i < data.length; i++) {
          console.info(LABEL + "data[" + i + "]: " + data[i]);
      }
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

将旋转矢量转换为旋转矩阵。

C
cff-gite 已提交
1633 1634
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
- 参数

  | 参数名         | 类型                | 必填 | 说明           |
  | -------------- | ------------------- | ---- | -------------- |
  | rotationVector | Array&lt;number&gt; | 是   | 表示旋转矢量。 |

- 返回值

  | 类型                               | 说明           |
  | ---------------------------------- | -------------- |
  | Promise&lt;Array&lt;number&gt;&gt; | 返回旋转矩阵。 |

- 示例

  ```
  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info(LABEL + 'createRotationMatrix_promise success');
          for (var i=0; i < data.length; i++) {
              console.info(LABEL + "data[" + i + "]: " + data[i]);
          }
      }).catch((reason) => {
          console.info(LABEL + "promise::catch", reason);
  })	
  ```


## sensor.createQuaternion

createQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

将旋转矢量转换为四元数。

C
cff-gite 已提交
1668 1669
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
- 参数

  | 参数名         | 类型                                     | 必填 | 说明           |
  | -------------- | ---------------------------------------- | ---- | -------------- |
  | rotationVector | Array&lt;number&gt;                      | 是   | 表示旋转矢量。 |
  | callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 返回四元数。   |

- 示例

  ```
  sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get  createQuaternion interface get data: " + data.x);
      for (var i=0; i < data.length; i++) {
          console.info(LABEL + "data[" + i + "]: " + data[i]);
      }
  })
  ```


## sensor.createQuaternion

createQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

将旋转矢量转换为四元数。

C
cff-gite 已提交
1700 1701
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
- 参数

  | 参数名         | 类型                | 必填 | 说明           |
  | -------------- | ------------------- | ---- | -------------- |
  | rotationVector | Array&lt;number&gt; | 是   | 表示旋转矢量。 |

- 返回值

  | 类型                               | 说明         |
  | ---------------------------------- | ------------ |
  | Promise&lt;Array&lt;number&gt;&gt; | 返回四元数。 |

- 示例

  ```
  const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('createQuaternion_promise successed');
          for (var i=0; i < data.length; i++) {
              console.info(LABEL + "data[" + i + "]: " + data[i]);
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```


## sensor.getDirection

getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

根据旋转矩阵计算设备的方向。

C
cff-gite 已提交
1735 1736
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766
- 参数

  | 参数名         | 类型                                     | 必填 | 说明                              |
  | -------------- | ---------------------------------------- | ---- | --------------------------------- |
  | rotationMatrix | Array&lt;number&gt;                      | 是   | 表示旋转矩阵。                    |
  | callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 返回围绕z、x、y轴方向的旋转角度。 |

- 示例

  ```
  sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
                        err.message);
          return;
      }
      console.info(LABEL + "SensorJsAPI--->Successed to get getDirection interface get data: " + data.x);
      for (var i = 1; i < data.length; i++) {
          console.info(TAG +"sensor_getDirection_callback" + data[i]);
      }
  })
  ```


## sensor.getDirection

getDirection(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

根据旋转矩阵计算设备的方向。

C
cff-gite 已提交
1767 1768
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801
- 参数

  | 参数名         | 类型                | 必填 | 说明           |
  | -------------- | ------------------- | ---- | -------------- |
  | rotationMatrix | Array&lt;number&gt; | 是   | 表示旋转矩阵。 |

- 返回值

  | 类型                               | 说明                              |
  | ---------------------------------- | --------------------------------- |
  | Promise&lt;Array&lt;number&gt;&gt; | 返回围绕z、x、y轴方向的旋转角度。 |

- 示例

  ```
  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info(' sensor_getAltitude_Promise success', data.x);
          for (var i = 1; i < data.length; i++) {
              console.info(TAG +"sensor_getDirection_promise" + data[i]);
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;, callback: AsyncCallback&lt;RotationMatrixResponse&gt;): void

根据重力矢量和地磁矢量计算旋转矩阵。

C
cff-gite 已提交
1802 1803
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
- 参数

  | 参数名      | 类型                                                         | 必填 | 说明           |
  | ----------- | ------------------------------------------------------------ | ---- | -------------- |
  | gravity     | Array&lt;number&gt;                                          | 是   | 表示重力向量。 |
  | geomagnetic | Array&lt;number&gt;                                          | 是   | 表示地磁矢量。 |
  | callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 是   | 返回旋转矩阵。 |

- 示例

  ```
  sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get createRotationMatrix interface get data: " + data.x);
      for (var i=0; i < data.length; i++) {
          console.info(LABEL + "data[" + i + "]: " + data[i])
      }
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;,): Promise&lt;RotationMatrixResponse&gt;

根据重力矢量和地磁矢量计算旋转矩阵。

C
cff-gite 已提交
1835 1836
**系统能力**:SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863
- 参数

  | 参数名      | 类型                | 必填 | 说明           |
  | ----------- | ------------------- | ---- | -------------- |
  | gravity     | Array&lt;number&gt; | 是   | 表示重力向量。 |
  | geomagnetic | Array&lt;number&gt; | 是   | 表示地磁矢量。 |

- 返回值

  | 类型                                                         | 说明           |
  | ------------------------------------------------------------ | -------------- |
  | Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 返回旋转矩阵。 |

- 示例

  ```
  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
          console.info(LABEL + 'createRotationMatrix_promise successed');
          for (var i=0; i < data.length; i++) {
              console.info(LABEL + "data[" + i + "]: " + data[i]);
          }
      }).catch((err) => {
          console.info(LABEL + 'promise failed');
  })
  ```

Z
zengyawen 已提交
1864

Z
zengyawen 已提交
1865
## SensorType
Z
zengyawen 已提交
1866 1867 1868

表示要订阅或取消订阅的传感器类型。

C
cff-gite 已提交
1869 1870
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896

| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| SENSOR_TYPE_ID_ACCELEROMETER | 1 | 加速度传感器。 |
| SENSOR_TYPE_ID_GYROSCOPE | 2 | 陀螺仪传感器。 |
| SENSOR_TYPE_ID_AMBIENT_LIGHT | 5 | 环境光传感器。 |
| SENSOR_TYPE_ID_MAGNETIC_FIELD | 6 | 磁场传感器。 |
| SENSOR_TYPE_ID_BAROMETER | 8 | 气压计传感器。 |
| SENSOR_TYPE_ID_HALL | 10 | 霍尔传感器。 |
| SENSOR_TYPE_ID_PROXIMITY | 12 | 接近光传感器。 |
| SENSOR_TYPE_ID_HUMIDITY | 13 | 湿度传感器。 |
| SENSOR_TYPE_ID_ORIENTATION | 256 | 方向传感器。 |
| SENSOR_TYPE_ID_GRAVITY | 257 | 重力传感器。 |
| SENSOR_TYPE_ID_LINEAR_ACCELERATION | 258 | 线性加速度传感器。 |
| SENSOR_TYPE_ID_ROTATION_VECTOR | 259 | 旋转矢量传感器。 |
| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | 260 | 环境温度传感器。 |
| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261 | 未校准磁场传感器。 |
| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 263 | 未校准陀螺仪传感器。 |
| SENSOR_TYPE_ID_SIGNIFICANT_MOTION | 264 | 有效运动传感器。 |
| SENSOR_TYPE_ID_PEDOMETER_DETECTION | 265 | 计步检测传感器。 |
| SENSOR_TYPE_ID_PEDOMETER | 266 | 计步传感器。 |
| SENSOR_TYPE_ID_HEART_RATE | 278 | 心率传感器。 |
| SENSOR_TYPE_ID_WEAR_DETECTION | 280 | 佩戴检测传感器。 |
| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 281 | 未校准加速度计传感器。 |


Z
zengyawen 已提交
1897 1898 1899 1900
## Response

传感器数据的时间戳。

C
cff-gite 已提交
1901 1902
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1903 1904 1905 1906 1907
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| timestamp | number | 是 | 是 | 传感器数据上报的时间戳。 |


Z
zengyawen 已提交
1908
## AccelerometerResponse
Z
zengyawen 已提交
1909

Z
zengyawen 已提交
1910
加速度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
1911

C
cff-gite 已提交
1912 1913
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1914 1915 1916

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
1917 1918 1919
| x | number | 是 | 是 | 施加在设备x轴的加速度,单位 : m/s2。 |
| y | number | 是 | 是 | 施加在设备y轴的加速度,单位 : m/s2。 |
| z | number | 是 | 是 | 施加在设备z轴的加速度,单位 : m/s2。 |
Z
zengyawen 已提交
1920 1921 1922


## LinearAccelerometerResponse
Z
zengyawen 已提交
1923

Z
zengyawen 已提交
1924
线性加速度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
1925

C
cff-gite 已提交
1926 1927
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1928 1929 1930

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
1931 1932 1933
| x | number | 是 | 是 | 施加在设备x轴的线性加速度,单位 : m/s2。 |
| y | number | 是 | 是 | 施加在设备y轴的线性加速度,单位 : m/s2。 |
| z | number | 是 | 是 | 施加在设备z轴的线性加速度,单位 : m/s2。 |
Z
zengyawen 已提交
1934 1935 1936


## AccelerometerUncalibratedResponse
Z
zengyawen 已提交
1937

Z
zengyawen 已提交
1938
未校准加速度计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
1939

C
cff-gite 已提交
1940 1941
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1942 1943 1944

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
1945 1946 1947 1948 1949 1950
| x | number | 是 | 是 | 施加在设备x轴未校准的加速度,单位 : m/s2。 |
| y | number | 是 | 是 | 施加在设备y轴未校准的加速度,单位 : m/s2。 |
| z | number | 是 | 是 | 施加在设备z轴未校准的加速度,单位 : m/s2。 |
| biasX | number | 是 | 是 | 施加在设备x轴未校准的加速度偏量,单位 : m/s2。 |
| biasY | number | 是 | 是 | 施加在设备上y轴未校准的加速度偏量,单位 : m/s2。 |
| biasZ | number | 是 | 是 | 施加在设备z轴未校准的加速度偏量,单位 : m/s2。 |
Z
zengyawen 已提交
1951 1952 1953


## GravityResponse
Z
zengyawen 已提交
1954

Z
zengyawen 已提交
1955
重力传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
1956

C
cff-gite 已提交
1957 1958
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1959 1960 1961

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
1962 1963 1964
| x | number | 是 | 是 | 施加在设备x轴的重力加速度,单位 : m/s2。 |
| y | number | 是 | 是 | 施加在设备y轴的重力加速度,单位 : m/s2。 |
| z | number | 是 | 是 | 施加在设备z轴的重力加速度,单位 : m/s2。 |
Z
zengyawen 已提交
1965 1966 1967


## OrientationResponse
Z
zengyawen 已提交
1968

Z
zengyawen 已提交
1969
方向传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
1970

C
cff-gite 已提交
1971 1972
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1973 1974 1975

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
1976 1977 1978
| x | number | 是 | 是 | 设备围绕x轴的旋转角度,单位 : rad。 |
| y | number | 是 | 是 | 设备围绕y轴的旋转角度,单位 : rad。 |
| z | number | 是 | 是 | 设备围绕z轴的旋转角度,单位 : rad。 |
Z
zengyawen 已提交
1979 1980 1981


## RotationVectorResponse
Z
zengyawen 已提交
1982

Z
zengyawen 已提交
1983
旋转矢量传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
1984

C
cff-gite 已提交
1985 1986
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
1987 1988 1989

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
1990 1991 1992
| x | number | 是 | 是 | 旋转矢量x轴分量。 |
| y | number | 是 | 是 | 旋转矢量y轴分量。 |
| z | number | 是 | 是 | 旋转矢量z轴分量。 |
Z
zengyawen 已提交
1993 1994 1995


## GyroscopeResponse
Z
zengyawen 已提交
1996

Z
zengyawen 已提交
1997
陀螺仪传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
1998

C
cff-gite 已提交
1999 2000
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2001 2002 2003

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
2004 2005 2006
| x | number | 是 | 是 | 设备x轴的旋转角速度,单位rad/s。 |
| y | number | 是 | 是 | 设备y轴的旋转角速度,单位rad/s。 |
| z | number | 是 | 是 | 设备z轴的旋转角速度,单位rad/s。 |
Z
zengyawen 已提交
2007 2008 2009


## GyroscopeUncalibratedResponse
Z
zengyawen 已提交
2010

Z
zengyawen 已提交
2011
未校准陀螺仪传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2012

C
cff-gite 已提交
2013 2014
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2015 2016 2017

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
2018 2019 2020 2021 2022 2023
| x | number | 是 | 是 | 设备x轴未校准的旋转角速度,单位rad/s。 |
| y | number | 是 | 是 | 设备y轴未校准的旋转角速度,单位rad/s。 |
| z | number | 是 | 是 | 设备z轴未校准的旋转角速度,单位rad/s。 |
| biasX | number | 是 | 是 | 设备x轴未校准的旋转角速度偏量,单位rad/s。 |
| biasY | number | 是 | 是 | 设备y轴未校准的旋转角速度偏量,单位rad/s。 |
| biasZ | number | 是 | 是 | 设备z轴未校准的旋转角速度偏量,单位rad/s。 |
Z
zengyawen 已提交
2024 2025 2026


## SignificantMotionResponse
Z
zengyawen 已提交
2027

Z
zengyawen 已提交
2028
有效运动传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2029

C
cff-gite 已提交
2030 2031
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2032 2033 2034 2035 2036 2037 2038

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| scalar | number | 是 | 是 | 表示剧烈运动程度。测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备是否存在大幅度运动;如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动。 |


## ProximityResponse
Z
zengyawen 已提交
2039

Z
zengyawen 已提交
2040
接近光传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2041

C
cff-gite 已提交
2042 2043
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2044 2045 2046 2047 2048 2049 2050

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| distance | number | 是 | 是 | 可见物体与设备显示器的接近程度。0表示接近,1表示远离。 |


## LightResponse
Z
zengyawen 已提交
2051

Z
zengyawen 已提交
2052
环境光传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2053

C
cff-gite 已提交
2054 2055
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2056 2057 2058 2059 2060 2061 2062

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| intensity | number | 是 | 是 | 光强(单位:勒克斯)。 |


## HallResponse
Z
zengyawen 已提交
2063

Z
zengyawen 已提交
2064
霍尔传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2065

C
cff-gite 已提交
2066 2067
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2068 2069 2070 2071 2072 2073 2074

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| status | number | 是 | 是 | 显示霍尔状态。测量设备周围是否存在磁力吸引,0表示有,1表示没有。 |


## MagneticFieldResponse
Z
zengyawen 已提交
2075

Z
zengyawen 已提交
2076
磁场传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2077

C
cff-gite 已提交
2078 2079
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2080 2081 2082

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
2083 2084 2085
| x | number | 是 | 是 | x轴环境磁场强度,单位 : μT。 |
| y | number | 是 | 是 | y轴环境磁场强度,单位 : μT。 |
| z | number | 是 | 是 | z轴环境磁场强度,单位 : μT。。 |
Z
zengyawen 已提交
2086 2087 2088


## MagneticFieldUncalibratedResponse
Z
zengyawen 已提交
2089

Z
zengyawen 已提交
2090
未校准磁场传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2091

C
cff-gite 已提交
2092 2093
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2094 2095 2096

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
2097 2098 2099 2100 2101 2102
| x | number | 是 | 是 | x轴未校准环境磁场强度,单位 : μT。 |
| y | number | 是 | 是 | y轴未校准环境磁场强度,单位 : μT。 |
| z | number | 是 | 是 | z轴未校准环境磁场强度,单位 : μT。 |
| biasX | number | 是 | 是 | x轴未校准环境磁场强度偏量,单位 : μT。 |
| biasY | number | 是 | 是 | y轴未校准环境磁场强度偏量,单位 : μT。 |
| biasZ | number | 是 | 是 | z轴未校准环境磁场强度偏量,单位 : μT。 |
Z
zengyawen 已提交
2103 2104 2105


## PedometerResponse
Z
zengyawen 已提交
2106

Z
zengyawen 已提交
2107
计步传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2108

C
cff-gite 已提交
2109 2110
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2111 2112 2113

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
2114
| steps | number | 是 | 是 | 用户的行走步数。 |
Z
zengyawen 已提交
2115 2116 2117


## HumidityResponse
Z
zengyawen 已提交
2118

Z
zengyawen 已提交
2119
湿度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2120

C
cff-gite 已提交
2121 2122
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2123 2124 2125 2126 2127 2128

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| humidity | number | 是 | 是 | 湿度值。测量环境的相对湿度,以百分比&nbsp;(%)&nbsp;表示。 |


C
cff-gite 已提交
2129
## PedometerDetectionResponse
Z
zengyawen 已提交
2130

Z
zengyawen 已提交
2131
计步检测传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2132

C
cff-gite 已提交
2133 2134
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2135 2136 2137 2138 2139 2140 2141

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| scalar | number | 是 | 是 | 计步器检测。检测用户的计步动作,如果取值为1则代表用户产生了计步行走的动作,取值为0则代表用户没有发生运动。 |


## AmbientTemperatureResponse
Z
zengyawen 已提交
2142

Z
zengyawen 已提交
2143
温度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2144

C
cff-gite 已提交
2145 2146
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2147 2148 2149 2150 2151 2152 2153

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| temperature | number | 是 | 是 | 环境温度(单位:摄氏度)。 |


## BarometerResponse
Z
zengyawen 已提交
2154

Z
zengyawen 已提交
2155
气压计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2156

C
cff-gite 已提交
2157 2158
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2159 2160 2161 2162 2163 2164 2165

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| pressure | number | 是 | 是 | 压力值(单位:帕斯卡)。 |


## HeartRateResponse
Z
zengyawen 已提交
2166

Z
zengyawen 已提交
2167
心率传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2168

C
cff-gite 已提交
2169 2170
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2171 2172 2173

| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
2174
| heartRate | number | 是 | 是 | 心率值。测量用户的心率数值,单位:bpm。 |
Z
zengyawen 已提交
2175 2176 2177


## WearDetectionResponse
Z
zengyawen 已提交
2178

Z
zengyawen 已提交
2179
佩戴检测传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2180

C
cff-gite 已提交
2181 2182
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2183

Z
zengyawen 已提交
2184 2185
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
2186
| value | number | 是 | 是 | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 |
Z
zengyawen 已提交
2187 2188 2189 2190


## Options

Z
zengyawen 已提交
2191
设置传感器上报频率。
Z
zengyawen 已提交
2192

C
cff-gite 已提交
2193 2194
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2195 2196 2197 2198
| 名称 | 参数类型 | 说明 |
| -------- | -------- | -------- |
| interval | number | 表示传感器的上报频率,默认值为200000000ns。 |

Z
zengyawen 已提交
2199 2200
## RotationMatrixResponse

C
cff-gite 已提交
2201 2202 2203
设置旋转矩阵响应对象。

**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
2204 2205 2206 2207 2208 2209 2210 2211 2212

| 名称        | 参数类型            | 可读 | 可写 | 说明       |
| ----------- | ------------------- | ---- | ---- | ---------- |
| rotation    | Array&lt;number&gt; | 是   | 是   | 旋转矩阵。 |
| inclination | Array&lt;number&gt; | 是   | 是   | 倾斜矩阵。 |


## CoordinatesOptions

C
cff-gite 已提交
2213 2214 2215
设置坐标选项对象。

**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
2216 2217 2218 2219 2220 2221

| 名称 | 参数类型 | 可读 | 可写 | 说明        |
| ---- | -------- | ---- | ---- | ----------- |
| x    | number   | 是   | 是   | x坐标方向。 |
| y    | number   | 是   | 是   | y坐标方向。 |

Z
zengyawen 已提交
2222 2223 2224

## GeomagneticResponse

Z
zengyawen 已提交
2225
设置地磁响应对象,继承于[Response](#response)
Z
zengyawen 已提交
2226

C
cff-gite 已提交
2227 2228
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2229 2230
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
Z
zengyawen 已提交
2231 2232 2233 2234 2235 2236 2237
| x | number | 是 | 是 | 地磁场的北分量。 |
| y | number | 是 | 是 | 地磁场的东分量。 |
| z | number | 是 | 是 | 地磁场的垂直分量。 |
| geomagneticDip | number | 是 | 是 | 地磁倾角,即地球磁场线与水平面的夹角。 |
| deflectionAngle | number | 是 | 是 | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 |
| levelIntensity | number | 是 | 是 | 地磁场的水平强度。 |
| totalIntensity | number | 是 | 是 | 地磁场的总强度。 |
Z
zengyawen 已提交
2238 2239 2240

## LocationOptions

C
cff-gite 已提交
2241 2242 2243 2244
指示地理位置。

**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2245 2246 2247 2248
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| latitude | number | 是 | 是 | 纬度。 |
| longitude | number | 是 | 是 | 经度。 |
Z
zengyawen 已提交
2249
| altitude | number | 是 | 是 | 海拔高度。 |