diff --git a/en/application-dev/reference/apis/js-apis-sensor.md b/en/application-dev/reference/apis/js-apis-sensor.md index 6c3f45743f9c1e4144d3a8e70d1c6aff8a3d9ab5..440a79eab1934eba07f7ca2c90cdc20c96fafe62 100644 --- a/en/application-dev/reference/apis/js-apis-sensor.md +++ b/en/application-dev/reference/apis/js-apis-sensor.md @@ -1,3748 +1,1544 @@ -# Sensors +# Sensor ->![](../../public_sys-resources/icon-note.gif) **NOTE:** ->The APIs of this module are supported since API version 8. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. -## Modules to Import + +## Modules to Import ``` import sensor from '@ohos.sensor'; ``` -## Required Permissions - -To use the pedometer sensor, you must declare the **ohos.permission.ACTIVITY\_MOTION** permission. - -To use the heart rate sensor, you must declare the **ohos.permission.READ\_HEALTH\_DATA** permission. - -To use the acceleration sensor, you must declare the **ohos.permission.ACCELEROMETER** permission. - -To use the gyroscope sensor, you must declare the **ohos.permission.GYROSCOPE** permission. - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_ACCELEROMETER\) - -on\(type: SensorType.SENSOR\_TYPE\_ID\_ACCELEROMETER, callback: AsyncCallback,options?: Options\): void - -Subscribes to acceleration sensor data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ACCELEROMETER.

-

callback

-

AsyncCallback<AccelerometerResponse>

-

Yes

-

Callback used to return the acceleration sensor data. The reported data type in the callback is AccelerometerResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type:SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, +## System Capabilities + +SystemCapability.Sensors.Sensor + +## Required Permissions + +To use the pedometer sensor, you must declare the **ohos.permission.ACTIVITY_MOTION** permission. + +To use the heart rate sensor, you must declare the **ohos.permission.READ_HEALTH_DATA** permission. + +To use the acceleration sensor, you must declare the **ohos.permission.ACCELEROMETER** permission. + +To use the gyroscope sensor, you must declare the **ohos.permission.GYROSCOPE** permission. + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER) + +on(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback<AccelerometerResponse>,options?: Options): void + + +Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. + + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.| + | callback | AsyncCallback<[AccelerometerResponse](#accelerometerresponse)> | Yes| Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){ + 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); + }, {interval: 10000000} - ); - ``` + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_LINEAR\_ACCELERATION\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION) -on\(type:SensorType.SENSOR\_TYPE\_ID\_LINEAR\_ACCELERATION,callback:AsyncCallback, options?: Options\): void +on(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback<LinearAccelerometerResponse>, options?: Options): void Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_LINEAR_ACCELERATION.

-

callback

-

AsyncCallback<LinearAccelerometerResponse>

-

Yes

-

Callback used to return the linear acceleration sensor data. The reported data type in the callback is LinearAccelerometerResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type:SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.| + | callback | AsyncCallback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes| Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(error,data){ + 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); + }, {interval: 10000000} - ); - ``` + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_ACCELEROMETER\_UNCALIBRATED\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED) -on\(type:SensorType.SENSOR\_TYPE\_ID\_ACCELEROMETER\_UNCALIBRATED,callback:AsyncCallback, options?: Options\): void +on(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback<AccelerometerUncalibratedResponse>, options?: Options): void Subscribes to data changes of the uncalibrated acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED.

-

callback

-

AsyncCallback<AccelerometerUncalibratedResponse>

-

Yes

-

Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is AccelerometerUncalibratedResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type:SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - // Print the x-, y-, and z-coordinate biases. - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.| + | callback | AsyncCallback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes| Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(error,data){ + 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); + }, {interval: 10000000} - ); - ``` - - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_GRAVITY\) - -on\(type: SensorType.SENSOR\_TYPE\_ID\_GRAVITY, callback: AsyncCallback,options?: Options\): void - -Subscribes to gravity sensor data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GRAVITY.

-

callback

-

AsyncCallback<GravityResponse>

-

Yes

-

Callback used to return the gravity sensor data. The reported data type in the callback is GravityResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type:SensorType.SENSOR_TYPE_ID_GRAVITY,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + ); + ``` + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY) + +on(type: sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<GravityResponse>,options?: Options): void + +Subscribes to data changes of the gravity sensor. If this API is called multiple times for the same application, the last call takes effect. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.| + | callback | AsyncCallback<[GravityResponse](#gravityresponse)> | Yes| Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(error,data){ + 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); + }, {interval: 10000000} - ); - ``` - - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_GYROSCOPE\) - -on\(type: SensorType.SENSOR\_TYPE\_ID\_GYROSCOPE, callback: AsyncCallback, options?: Options\): void - -Subscribes to gyroscope sensor data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GYROSCOPE.

-

callback

-

AsyncCallback<GyroscopeResponse>

-

Yes

-

Callback used to return the gyroscope sensor data. The reported data type in the callback is GyroscopeResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type:SensorType.SENSOR_TYPE_ID_GUROSCOPE,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + ); + ``` + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE) + +on(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<GyroscopeResponse>, options?: Options): void + +Subscribes to data changes of the gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.| + | callback | AsyncCallback<[GyroscopeResponse](#gyroscoperesponse)> | Yes| Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(error,data){ + 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); + }, {interval: 10000000} - ); - ``` + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_GYROSCOPE\_UNCALIBRATED\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED) -on\(type:SensorType.SENSOR\_TYPE\_ID\_GYROSCOPE\_UNCALIBRATED,callback:AsyncCallback, options?: Options\): void +on(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback<GyroscopeUncalibratedResponse>, options?: Options): void Subscribes to data changes of the uncalibrated gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED.

-

callback

-

AsyncCallback<GyroscopeUncalibratedResponse>

-

Yes

-

Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is GyroscopeUncalibratedResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - // Print the x-, y-, and z-coordinate biases. - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.| + | callback | AsyncCallback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes| Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(error,data){ + 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); + }, {interval: 10000000} - ); - ``` + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_SIGNIFICANT\_MOTION\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION) -on\(type: SensorType.SENSOR\_TYPE\_ID\_SIGNIFICANT\_MOTION, callback: AsyncCallback, options?: Options\): void +on(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: AsyncCallback<SignificantMotionResponse>, options?: Options): void Subscribes to data changes of the significant motion sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_SIGNIFICANT_MOTION.

-

callback

-

AsyncCallback<SignificantMotionResponse>

-

Yes

-

Callback used to return the significant motion sensor data. The reported data type in the callback is SignificantMotionResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Scalar data: ' + data.scalar); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.| + | callback | AsyncCallback<[SignificantMotionResponse](#significantmotionresponse)> | Yes| Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - {interval: 10000000} - ); - ``` + console.info('Scalar data: ' + data.scalar); + }, + {interval: 10000000} + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_PEDOMETER\_DETECTION\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION) -on\(type: SensorType.SENSOR\_TYPE\_ID\_PEDOMETER\_DETECTION, callback: AsyncCallback, options?: Options\): void +on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: AsyncCallback<PedometerDetectResponse>, options?: Options): void Subscribes to data changes of the pedometer detection sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PEDOMETER_DETECTION.

-

callback

-

AsyncCallback<PedometerDetectResponse>

-

Yes

-

Callback used to return the pedometer detection sensor data. The reported data type in the callback is PedometerDetectResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(error,data){ - if (error) { - console.error(""Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Scalar data: ' + data.scalar); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.| + | callback | AsyncCallback<[PedometerDetectResponse](#pedometerdetectresponse)> | Yes| Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } + console.info('Scalar data: ' + data.scalar); + }, {interval: 10000000} - ); - ``` - - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_PEDOMETER\) - -on\(type: SensorType.SENSOR\_TYPE\_ID\_PEDOMETER, callback: AsyncCallback, options?: Options\): void - -Subscribes to pedometer sensor data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PEDOMETER.

-

callback

-

AsyncCallback<PedometerResponse>

-

Yes

-

Callback used to return the pedometer sensor data. The reported data type in the callback is PedometerResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the number of steps. - console.info('Steps: ' + data.steps); + ); + ``` + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER) + +on(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<PedometerResponse>, options?: Options): void + +Subscribes to data changes of the pedometer sensor. If this API is called multiple times for the same application, the last call takes effect. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.| + | callback | AsyncCallback<[PedometerResponse](#pedometerresponse)> | Yes| Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } + console.info('Steps: ' + data.steps); + }, {interval: 10000000} - ); - ``` + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_AMBIENT\_TEMPERATURE\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) -on\(type:SensorType.SENSOR\_TYPE\_ID\_AMBIENT\_TEMPERATURE,callback:AsyncCallback, options?: Options\): void +on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback<AmbientTemperatureResponse>, options?: Options): void Subscribes to data changes of the ambient temperature sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_AMBIENT_TEMPERATURE.

-

callback

-

AsyncCallback<AmbientTemperatureResponse>

-

Yes

-

Callback used to return the ambient temperature sensor data. The reported data type in the callback is AmbientTemperatureResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the temperature. - console.info('Temperature: ' + data.temperature); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.| + | callback | AsyncCallback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes| Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } + console.info('Temperature: ' + data.temperature); + }, {interval: 10000000} - ); - ``` + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_MAGNETIC\_FIELD\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD) -on\(type: SensorType.SENSOR\_TYPE\_ID\_MAGNETIC\_FIELD, callback: AsyncCallback,options?: Options\): void +on(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback<MagneticFieldResponse>,options?: Options): void Subscribes to data changes of the magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_MAGNETIC_FIELD.

-

callback

-

AsyncCallback<MagneticFieldResponse>

-

Yes

-

Callback used to return the magnetic field sensor data. The reported data type in the callback is MagneticFieldResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.| + | callback | AsyncCallback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes| Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(error,data){ + 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); + }, {interval: 10000000} - ); - ``` + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_MAGNETIC\_FIELD\_UNCALIBRATED\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED) -on\(type:SensorType.SENSOR\_TYPE\_ID\_MAGNETIC\_FIELD\_UNCALIBRATED,callback:AsyncCallback, options: Options\): void +on(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback<MagneticFieldUncalibratedResponse>, options: Options): void Subscribes to data changes of the uncalibrated magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED.

-

callback

-

AsyncCallback<MagneticFieldUncalibratedResponse>

-

Yes

-

Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is MagneticFieldUncalibratedResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - ensor.on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - // Print the x-, y-, and z-coordinate biases. - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.| + | callback | AsyncCallback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes| Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - {interval: 10000000} // Set the data reporting frequency. - ); - ``` - - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_PROXIMITY\) - -on\(type: SensorType.SENSOR\_TYPE\_ID\_PROXIMITY, callback: AsyncCallback,options?: Options\): void - -Subscribes to proximity sensor data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PROXIMITY.

-

callback

-

AsyncCallback<ProximityResponse>

-

Yes

-

Callback used to return the proximity sensor data. The reported data type in the callback is ProximityResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the proximity. - console.info('Distance: ' + data.distance); + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); + console.info('X-coordinate bias: ' + data.biasX); + console.info('Y-coordinate bias: ' + data.biasY); + console.info('Z-coordinate bias: ' + data.biasZ); + }, + {interval: 10000000} + ); + ``` + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY) + +on(type:sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<ProximityResponse>,options?: Options): void + +Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.| + | callback | AsyncCallback<[ProximityResponse](#proximityresponse)> | Yes| Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } + console.info('Distance: ' + data.distance); + }, {interval: 10000000} - ); - ``` - - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_HUMIDITY\) - -on\(type: SensorType.SENSOR\_TYPE\_ID\_HUMIDITY, callback: AsyncCallback,options?: Options\): void - -Subscribes to humidity sensor data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HUMIDITY.

-

callback

-

AsyncCallback<HumidityResponse>

-

Yes

-

Callback used to return the humidity sensor data. The reported data type in the callback is HumidityResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the humidity. - console.info('Humidity: ' + data.humidity); + ); + ``` + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY) + +on(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<HumidityResponse>,options?: Options): void + +Subscribes to data changes of the humidity sensor. If this API is called multiple times for the same application, the last call takes effect. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.| + | callback | AsyncCallback<[HumidityResponse](#humidityresponse)> | Yes| Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } + console.info('Humidity: ' + data.humidity); + }, {interval: 10000000} - ); - ``` - - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_BAROMETER\) - -on\(type: SensorType.SENSOR\_TYPE\_ID\_BAROMETER, callback: AsyncCallback,options?: Options\): void - -Subscribes to barometer sensor data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_BAROMETER.

-

callback

-

AsyncCallback<BarometerResponse>

-

Yes

-

Callback used to return the barometer sensor data. The reported data type in the callback is BarometerResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_BAROMETER,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the atmospheric pressure. - console.info('Atmospheric pressure: ' + data.pressure); + ); + ``` + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER) + +on(type:sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<BarometerResponse>,options?: Options): void + +Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.| + | callback | AsyncCallback<[BarometerResponse](#barometerresponse)> | Yes| Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } + console.info('Atmospheric pressure: ' + data.pressure); + }, {interval: 10000000} - ); - ``` + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_HALL\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL) -on\(type: SensorType.SENSOR\_TYPE\_ID\_HALL, callback: AsyncCallback, options?: Options\): void +on(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<HallResponse>, options?: Options): void Subscribes to data changes of the Hall effect sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HALL.

-

callback

-

AsyncCallback<HallResponse>

-

Yes

-

Callback used to return the Hall effect sensor data. The reported data type in the callback is HallResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_HALL,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the status. - console.info('Status: ' + data.status); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.| + | callback | AsyncCallback<[HallResponse](#hallresponse)> | Yes| Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } + console.info('Status: ' + data.status); + }, {interval: 10000000} - ); - ``` + ); + ``` -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_AMBIENT\_LIGHT\) +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT) -on\(type: SensorType.SENSOR\_TYPE\_ID\_AMBIENT\_LIGHT, callback: AsyncCallback, options?: Options\): void +on(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback<LightResponse>, options?: Options): void Subscribes to data changes of the ambient light sensor. If this API is called multiple times for the same application, the last call takes effect. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_AMBIENT_LIGHT.

-

callback

-

AsyncCallback<LightResponse>

-

Yes

-

Callback used to return the ambient light sensor data. The reported data type in the callback is LightResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the illumination. - console.info(''Illumination: ' + data.intensity); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.| + | callback | AsyncCallback<[LightResponse](#lightresponse)> | Yes| Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } + console.info(' Illumination: ' + data.intensity); + }, {interval: 10000000} - ); - ``` - - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_ORIENTATION\) - -on\(type: SensorType.SENSOR\_TYPE\_ID\_ORIENTATION, callback: AsyncCallback, options?: Options\): void - -Subscribes to orientation sensor data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ORIENTATION.

-

callback

-

AsyncCallback<OrientationResponse>

-

Yes

-

Callback used to return the orientation sensor data. The reported data type in the callback is OrientationResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + ); + ``` + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION) + +on(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback<OrientationResponse>, options?: Options): void + +Subscribes to data changes of the orientation sensor. If this API is called multiple times for the same application, the last call takes effect. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.| + | callback | AsyncCallback<[OrientationResponse](#orientationresponse)> | Yes| Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(error,data){ + 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); + }, {interval: 10000000} - ); - ``` - - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_ROTATION\_VECTOR\) - -on\(type:SensorType.SENSOR\_TYPE\_ID\_ROTATION\_VECTOR,callback:AsyncCallback,options?: Options\): void - -Subscribes to rotation vector data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ROTATION_VECTOR.

-

callback

-

AsyncCallback<RotationVectorResponse>

-

Yes

-

Callback used to return the rotation vector sensor data. The reported data type in the callback is RotationVectorResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + ); + ``` + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR) + +on(type:sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback:AsyncCallback<RotationVectorResponse>,options?: Options): void + +Subscribes to data changes of the rotation vector sensor. If this API is called multiple times for the same application, the last call takes effect. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.| + | callback | AsyncCallback<[RotationVectorResponse](#rotationvectorresponse)> | Yes| Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(error,data){ + 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); + }, {interval: 10000000} - ); - ``` - - -## sensor.on\(SensorType.SENSOR\_TYPE\_ID\_WEAR\_DETECTION\) - -on\(type: SensorType.SENSOR\_TYPE\_ID\_WEAR\_DETECTION, callback: AsyncCallback,options?: Options\): void - -Subscribes to wear detection data changes. If this API is called multiple times for the same application, the last call takes effect. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_WEAR_DETECTION.

-

callback

-

AsyncCallback<WearDetectionResponse>

-

Yes

-

Callback used to return the wear detection sensor data. The reported data type in the callback is WearDetectionResponse.

-

options

-

Options

-

No

-

Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.

-
- -- Example - - ``` - sensor.on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(error,data){ - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the wear status. - console.info('Wear status: ' + data.value); + ); + ``` + + +## sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION) + +on(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback<WearDetectionResponse>,options?: Options): void + +Subscribes to data changes of the wear detection sensor. If this API is called multiple times for the same application, the last call takes effect. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.| + | callback | AsyncCallback<[WearDetectionResponse](#weardetectionresponse)> | Yes| Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.| + | options | [Options](#options) | No| Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.| + +- Example + ``` + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(error,data){ + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } + console.info('Wear status: ' + data.value); + }, {interval: 10000000} - ); - ``` - - -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_ACCELEROMETER\) - -once\(type: SensorType.SENSOR\_TYPE\_ID\_ACCELEROMETER, callback: AsyncCallback\): void - -Subscribes to only one acceleration sensor data change. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ACCELEROMETER.

-

callback

-

AsyncCallback<AccelerometerResponse>

-

Yes

-

One-shot callback used to return the acceleration sensor data. The reported data type in the callback is AccelerometerResponse.

-
- - -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + ); + ``` + + +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER) + +once(type: sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: AsyncCallback<AccelerometerResponse>): void + +Subscribes to only one data change of the acceleration sensor. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.| + | callback | AsyncCallback<[AccelerometerResponse](#accelerometerresponse)> | Yes| One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(error,data){ + 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); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_LINEAR\_ACCELERATION\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION) -once\(type:SensorType.SENSOR\_TYPE\_ID\_LINEAR\_ACCELERATION,callback:AsyncCallback\): void +once(type:sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:AsyncCallback<LinearAccelerometerResponse>): void Subscribes to only one data change of the linear acceleration sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_LINEAR_ACCELERATION.

-

callback

-

AsyncCallback<LinearAccelerometerResponse>

-

Yes

-

One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is LinearAccelerometerResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.| + | callback | AsyncCallback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes| One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(error, data) { + 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); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_ACCELEROMETER\_UNCALIBRATED\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED) -once\(type:SensorType.SENSOR\_TYPE\_ID\_ACCELEROMETER\_UNCALIBRATED,callback:AsyncCallback\): void +once(type:sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback:AsyncCallback<AccelerometerUncalibratedResponse>): void Subscribes to only one data change of the uncalibrated acceleration sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED.

-

callback

-

AsyncCallback<AccelerometerUncalibratedResponse>

-

Yes

-

One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is AccelerometerUncalibratedResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - // Print the x-, y-, and z-coordinate biases. - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.| + | callback | AsyncCallback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes| One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` - - -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_GRAVITY\) - -once\(type: SensorType.SENSOR\_TYPE\_ID\_GRAVITY, callback: AsyncCallback\): void - -Subscribes to only one gravity sensor data change. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GRAVITY.

-

callback

-

AsyncCallback<GravityResponse>

-

Yes

-

One-shot callback used to return the gravity sensor data. The reported data type in the callback is GravityResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_GRAVITY, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - 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 component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); + console.info('X-coordinate bias: ' + data.biasX); + console.info('Y-coordinate bias: ' + data.biasY); + console.info('Z-coordinate bias: ' + data.biasZ); + } + ); + ``` + + +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY) + +once(type:sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback: AsyncCallback<GravityResponse>): void + +Subscribes to only one data change of the gravity sensor. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.| + | callback | AsyncCallback<[GravityResponse](#gravityresponse)> | Yes| One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` - - -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_GYROSCOPE\) - -once\(type: SensorType.SENSOR\_TYPE\_ID\_GYROSCOPE, callback: AsyncCallback\): void - -Subscribes to only one gyroscope sensor data change. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GYROSCOPE.

-

callback

-

AsyncCallback<GyroscopeResponse>

-

Yes

-

One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is GyroscopeResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - 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 component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); + } + ); + ``` + + +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE) + +once(type: sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: AsyncCallback<GyroscopeResponse>): void + +Subscribes to only one data change of the gyroscope sensor. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.| + | callback | AsyncCallback<[GyroscopeResponse](#gyroscoperesponse)> | Yes| One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(error, data) { + 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); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_GYROSCOPE\_UNCALIBRATED\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED) -once\(type:SensorType.SENSOR\_TYPE\_ID\_GYROSCOPE\_UNCALIBRATED,callback:AsyncCallback\): void +once(type:sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:AsyncCallback<GyroscopeUncalibratedResponse>): void Subscribes to only one data change of the uncalibrated gyroscope sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED.

-

callback

-

AsyncCallback<GyroscopeUncalibratedResponse>

-

Yes

-

One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is GyroscopeUncalibratedResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - // Print the x-, y-, and z-coordinate biases. - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.| + | callback | AsyncCallback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes| One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(error, data) { + 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); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_SIGNIFICANT\_MOTION\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION) -once\(type: SensorType.SENSOR\_TYPE\_ID\_SIGNIFICANT\_MOTION,callback:AsyncCallback\): void +once(type: sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback:AsyncCallback<SignificantMotionResponse>): void Subscribes to only one data change of the significant motion sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_SIGNIFICANT_MOTION.

-

callback

-

AsyncCallback<SignificantMotionResponse>

-

Yes

-

One-shot callback used to return the significant motion sensor data. The reported data type in the callback is SignificantMotionResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Scalar data: ' + data.scalar); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.| + | callback | AsyncCallback<[SignificantMotionResponse](#significantmotionresponse)> | Yes| One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` + console.info('Scalar data: ' + data.scalar); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_PEDOMETER\_DETECTION\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION) -once\(type:SensorType.SENSOR\_TYPE\_ID\_PEDOMETER\_DETECTION,callback:AsyncCallback\): void +once(type:sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback:AsyncCallback<PedometerDetectResponse>): void Subscribes to only one data change of the pedometer detection sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PEDOMETER_DETECTION.

-

callback

-

AsyncCallback<PedometerDetectResponse>

-

Yes

-

One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is PedometerDetectResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info('Scalar data: ' + data.scalar); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.| + | callback | AsyncCallback<[PedometerDetectResponse](#pedometerdetectresponse)> | Yes| One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` - - -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_PEDOMETER\) - -once\(type: SensorType.SENSOR\_TYPE\_ID\_PEDOMETER, callback: AsyncCallback\): void - -Subscribes to only one pedometer sensor data change. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PEDOMETER.

-

callback

-

AsyncCallback<PedometerResponse>

-

Yes

-

One-shot callback used to return the pedometer sensor data. The reported data type in the callback is PedometerResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_PEDOMETER, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the number of steps. - console.info('Steps: ' + data.steps); + console.info('Scalar data: ' + data.scalar); + } + ); + ``` + + +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER) + +once(type: sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: AsyncCallback<PedometerResponse>): void + +Subscribes to only one data change of the pedometer sensor. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.| + | callback | AsyncCallback<[PedometerResponse](#pedometerresponse)> | Yes| One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` + console.info('Steps: ' + data.steps); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_AMBIENT\_TEMPERATURE\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE) -once\(type:SensorType.SENSOR\_TYPE\_ID\_AMBIENT\_TEMPERATURE,callback:AsyncCallback\): void +once(type:sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:AsyncCallback<AmbientTemperatureResponse>): void Subscribes to only one data change of the ambient temperature sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_AMBIENT_TEMPERATURE.

-

callback

-

AsyncCallback<AmbientTemperatureResponse>

-

Yes

-

One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is AmbientTemperatureResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the temperature data. - console.info('Temperature: ' + data.temperature); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.| + | callback | AsyncCallback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes| One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` + console.info('Temperature: ' + data.temperature); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_MAGNETIC\_FIELD\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD) -once\(type: SensorType.SENSOR\_TYPE\_ID\_MAGNETIC\_FIELD, callback: AsyncCallback\): void +once(type: sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: AsyncCallback<MagneticFieldResponse>): void Subscribes to only one data change of the magnetic field sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_MAGNETIC_FIELD.

-

callback

-

AsyncCallback<MagneticFieldResponse>

-

Yes

-

One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is MagneticFieldResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.| + | callback | AsyncCallback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes| One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(error, data) { + 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); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_MAGNETIC\_FIELD\_UNCALIBRATED\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED) -once\(type:SensorType.SENSOR\_TYPE\_ID\_MAGNETIC\_FIELD\_UNCALIBRATED,callback:AsyncCallback\): void +once(type:sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback:AsyncCallback<MagneticFieldUncalibratedResponse>): void Subscribes to only one data change of the uncalibrated magnetic field sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED.

-

callback

-

AsyncCallback<MagneticFieldUncalibratedResponse>

-

Yes

-

One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is MagneticFieldUncalibratedResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - // Print the x-, y-, and z-coordinate biases. - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.| + | callback | AsyncCallback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes| One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` - - -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_PROXIMITY\) - -once\(type: SensorType.SENSOR\_TYPE\_ID\_PROXIMITY, callback: AsyncCallback\): void - -Subscribes to only one proximity sensor data change. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_PROXIMITY.

-

callback

-

AsyncCallback<ProximityResponse>

-

Yes

-

One-shot callback used to return the proximity sensor data. The reported data type in the callback is ProximityResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_PROXIMITY, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the proximity. - console.info('Distance: ' + data.distance); + console.info('X-coordinate component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); + console.info('X-coordinate bias: ' + data.biasX); + console.info('Y-coordinate bias: ' + data.biasY); + console.info('Z-coordinate bias: ' + data.biasZ); + } + ); + ``` + + +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY) + +once(type: sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: AsyncCallback<ProximityResponse>): void + +Subscribes to only one data change of the proximity sensor. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.| + | callback | AsyncCallback<[ProximityResponse](#proximityresponse)> | Yes| One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` - - -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_HUMIDITY\) - -once\(type: SensorType.SENSOR\_TYPE\_ID\_HUMIDITY, callback: AsyncCallback\): void - -Subscribes to only one humidity sensor data change. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HUMIDITY.

-

callback

-

AsyncCallback<HumidityResponse>

-

Yes

-

One-shot callback used to return the humidity sensor data. The reported data type in the callback is HumidityResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_HUMIDITY, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the humidity. - console.info('Humidity: ' + data.humidity); + console.info('Distance: ' + data.distance); + } + ); + ``` + + +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY) + +once(type: sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: AsyncCallback<HumidityResponse>): void + +Subscribes to only one data change of the humidity sensor. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.| + | callback | AsyncCallback<[HumidityResponse](#humidityresponse)> | Yes| One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` - - -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_BAROMETER\) - -once\(type: SensorType.SENSOR\_TYPE\_ID\_BAROMETER, callback: AsyncCallback\): void - -Subscribes to only one barometer sensor data change. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_BAROMETER.

-

callback

-

AsyncCallback<BarometerResponse>

-

Yes

-

One-shot callback used to return the barometer sensor data. The reported data type in the callback is BarometerResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_BAROMETER, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the atmospheric pressure. - console.info('Atmospheric pressure: ' + data.pressure); + console.info('Humidity: ' + data.humidity); + } + ); + ``` + + +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER) + +once(type: sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback: AsyncCallback<BarometerResponse>): void + +Subscribes to only one data change of the barometer sensor. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.| + | callback | AsyncCallback<[BarometerResponse](#barometerresponse)> | Yes| One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` + console.info('Atmospheric pressure: ' + data.pressure); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_HALL\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL) -once\(type: SensorType.SENSOR\_TYPE\_ID\_HALL, callback: AsyncCallback\): void +once(type: sensor.SensorType.SENSOR_TYPE_ID_HALL, callback: AsyncCallback<HallResponse>): void Subscribes to only one data change of the Hall effect sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HALL.

-

callback

-

AsyncCallback<HallResponse>

-

Yes

-

One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is HallResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_HALL, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the status. - console.info('Status: ' + data.status); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.| + | callback | AsyncCallback<[HallResponse](#hallresponse)> | Yes| One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` + console.info('Status: ' + data.status); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_AMBIENT\_LIGHT\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT) -once\(type: SensorType.SENSOR\_TYPE\_ID\_AMBIENT\_LIGHT, callback: AsyncCallback\): void +once(type: sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: AsyncCallback<LightResponse>): void Subscribes to only one data change of the ambient light sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_AMBIENT_LIGHT.

-

callback

-

AsyncCallback<LightResponse>

-

Yes

-

One-shot callback used to return the ambient light sensor data. The reported data type in the callback is LightResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the illumination. - console.info('Illumination: ' + data.intensity); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.| + | callback | AsyncCallback<[LightResponse](#lightresponse)> | Yes| One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` - - -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_ORIENTATION\) - -once\(type: SensorType.SENSOR\_TYPE\_ID\_ORIENTATION, callback: AsyncCallback\): void - -Subscribes to only one orientation sensor data change. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ORIENTATION.

-

callback

-

AsyncCallback<OrientationResponse>

-

Yes

-

One-shot callback used to return the orientation sensor data. The reported data type in the callback is OrientationResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_ORIENTATION, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + console.info(' Illumination: ' + data.intensity); + } + ); + ``` + + +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION) + +once(type: sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: AsyncCallback<OrientationResponse>): void + +Subscribes to only one data change of the orientation sensor. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.| + | callback | AsyncCallback<[OrientationResponse](#orientationresponse)> | Yes| One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` - - -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_ROTATION\_VECTOR\) - -once\(type: SensorType.SENSOR\_TYPE\_ID\_ROTATION\_VECTOR, callback: AsyncCallback\): void - -Subscribes to only one rotation vector data change. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_ROTATION_VECTOR.

-

callback

-

AsyncCallback<RotationVectorResponse>

-

Yes

-

One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is RotationVectorResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the x-, y-, and z-coordinate components. - 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 component: ' + data.x); + console.info('Y-coordinate component: ' + data.y); + console.info('Z-coordinate component: ' + data.z); + } + ); + ``` + + +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR) + +once(type: sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: AsyncCallback<RotationVectorResponse>): void + +Subscribes to only one data change of the rotation vector sensor. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.| + | callback | AsyncCallback<[RotationVectorResponse](#rotationvectorresponse)> | Yes| One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(error, data) { + 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); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_HEART\_RATE\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE) -once\(type: SensorType.SENSOR\_TYPE\_ID\_HEART\_RATE, callback: AsyncCallback\): void +once(type: sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: AsyncCallback<HeartRateResponse>): void Subscribes to only one data change of the heart rate sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_HEART_RATE.

-

callback

-

AsyncCallback<HeartRateResponse>

-

Yes

-

One-shot callback used to return the heart rate sensor data. The reported data type in the callback is HeartRateResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_HEART_RATE, function(error, data) { - if (error) { - console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); - return; - } - // Print the heart rate. - console.info("Heart rate: " + data.heartRate); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.| + | callback | AsyncCallback<[HeartRateResponse](#heartrateresponse)> | Yes| One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(error, data) { + if (error) { + console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message); + return; } - ); - ``` + console.info("Heart rate: " + data.heartRate); + } + ); + ``` -## sensor.once\(SensorType.SENSOR\_TYPE\_ID\_WEAR\_DETECTION\) +## sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION) -once\(type: SensorType.SENSOR\_TYPE\_ID\_WEAR\_DETECTION, callback: AsyncCallback\): void +once(type: sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: AsyncCallback<WearDetectionResponse>): void Subscribes to only one data change of the wear detection sensor. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to subscribe to, which is SENSOR_TYPE_ID_WEAR_DETECTION.

-

callback

-

AsyncCallback<WearDetectionResponse>

-

Yes

-

One-shot callback used to return the wear detection sensor data. The reported data type in the callback is WearDetectionResponse.

-
- -- Example - - ``` - sensor.once(type:SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(error, data) { - if (error) { - console.error("Failed to register data, error code is" + error.code + ", message: " + error.message); - return; - } - // Print the wear status. - console.info("Wear status: "+ data.value); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.| + | callback | AsyncCallback<[WearDetectionResponse](#weardetectionresponse)> | Yes| One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.| + +- Example + ``` + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(error, data) { + if (error) { + console.error("Failed to register data, error code is" + error.code + ", message: " + error.message); + return; } - ); - ``` + console.info("Wear status: "+ data.value); + } + ); + ``` -## sensor.off +## sensor.off -off\(type: SensorType, callback?: AsyncCallback\): void +off(type: SensorType, callback?: AsyncCallback<void>): void Unsubscribes from sensor data changes. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

type

-

SensorType

-

Yes

-

Type of the sensor to unsubscribe from.

-

callback

-

AsyncCallback<void>

-

Yes

-

Callback used to return the execution result.

-
- -- Example - - ``` - sensor.off(type:SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(error) { - 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."); +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | type | [SensorType](#sensortype) | Yes| Type of the sensor to unsubscribe from.| + | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + +- Example + ``` + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(error) { + 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."); + } + ); + + ``` + + +## sensor.getGeomagneticField + +getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback<GeomagneticResponse>): void + +Obtains the geomagnetic field of a geographic location. This method uses a callback to return the result. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locationOptions | [LocationOptions](#locationoptions) | Yes| Geographic location.| + | timeMillis | number | Yes| Time for obtaining the magnetic declination, in milliseconds.| + | callback | AsyncCallback<[GeomagneticResponse](#geomagneticresponse)> | Yes| Callback used to return the geomagnetic field.| + +- Example + ``` + 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<GeomagneticResponse> -## SensorType +Obtains the geomagnetic field of a geographic location. This method uses a callback to return the result. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locationOptions | [LocationOptions](#locationoptions) | Yes| Geographic location.| + | timeMillis | number | Yes| Time for obtaining the magnetic declination, in milliseconds.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<[GeomagneticResponse](#geomagneticresponse)> | Callback used to return the geomagnetic field.| + +- Example + ``` + const promise = sensor.getGeomagneticField([80, 0, 0], {'timeMillis':1580486400000}); + promise.then((data) => { + 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); + }).catch((reason) => { + console.info('Operation failed.'); + }) + ``` + + +## SensorType Enumerates the sensor types. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

SENSOR_TYPE_ID_ACCELEROMETER

-

1

-

Acceleration sensor.

-

SENSOR_TYPE_ID_GYROSCOPE

-

2

-

Gyroscope sensor.

-

SENSOR_TYPE_ID_AMBIENT_LIGHT

-

5

-

Ambient light sensor.

-

SENSOR_TYPE_ID_MAGNETIC_FIELD

-

6

-

Magnetic field sensor.

-

SENSOR_TYPE_ID_BAROMETER

-

8

-

Barometer sensor.

-

SENSOR_TYPE_ID_HALL

-

10

-

Hall effect sensor.

-

SENSOR_TYPE_ID_PROXIMITY

-

12

-

Proximity sensor.

-

SENSOR_TYPE_ID_HUMIDITY

-

13

-

Humidity sensor.

-

SENSOR_TYPE_ID_ORIENTATION

-

256

-

Orientation sensor.

-

SENSOR_TYPE_ID_GRAVITY

-

257

-

Gravity sensor.

-

SENSOR_TYPE_ID_LINEAR_ACCELERATION

-

258

-

Linear acceleration sensor.

-

SENSOR_TYPE_ID_ROTATION_VECTOR

-

259

-

Rotation vector sensor.

-

SENSOR_TYPE_ID_AMBIENT_TEMPERATURE

-

260

-

Ambient temperature sensor.

-

SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED

-

261

-

Uncalibrated magnetic field sensor.

-

SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED

-

263

-

Uncalibrated gyroscope sensor.

-

SENSOR_TYPE_ID_SIGNIFICANT_MOTION

-

264

-

Significant motion sensor.

-

SENSOR_TYPE_ID_PEDOMETER_DETECTION

-

265

-

Pedometer detection sensor.

-

SENSOR_TYPE_ID_PEDOMETER

-

266

-

Pedometer sensor.

-

SENSOR_TYPE_ID_HEART_RATE

-

278

-

Heart rate sensor.

-

SENSOR_TYPE_ID_WEAR_DETECTION

-

280

-

Wear detection sensor.

-

SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED

-

281

-

Uncalibrated acceleration sensor.

-
- -## AccelerometerResponse - -Describes the acceleration sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-
- -## LinearAccelerometerResponse - -Describes the linear acceleration sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-
- -## AccelerometerUncalibratedResponse - -Describes the uncalibrated acceleration sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-

biasX

-

number

-

Yes

-

Yes

-

X-coordinate bias.

-

biasY

-

number

-

Yes

-

Yes

-

Y-coordinate bias.

-

biasZ

-

number

-

Yes

-

Yes

-

Z-coordinate bias.

-
- -## GravityResponse - -Describes the gravity sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-
- -## OrientationResponse - -Describes the orientation sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-
- -## RotationVectorResponse - -Describes the rotation vector sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-
- -## GyroscopeResponse - -Describes the gyroscope sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-
- -## GyroscopeUncalibratedResponse - -Describes the uncalibrated gyroscope sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-

biasX

-

number

-

Yes

-

Yes

-

X-coordinate bias.

-

biasY

-

number

-

Yes

-

Yes

-

Y-coordinate bias.

-

biasZ

-

number

-

Yes

-

Yes

-

Z-coordinate bias.

-
- -## SignificantMotionResponse - -Describes the significant motion sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

scalar

-

number

-

Yes

-

Yes

-

Intensity of a motion. This parameter specifies whether a device has a significant motion on three physical axes (X, Y, and Z). The value 0 means that the device does not have a significant motion, and 1 means the opposite.

-
- -## ProximityResponse - -Describes the proximity sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

distance

-

number

-

Yes

-

Yes

-

Proximity between the visible object and the device monitor. The value 0 means the two are close to each other, and 1 means that they are far away from each other.

-
- -## LightResponse - -Describes the ambient light sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

intensity

-

number

-

Yes

-

Yes

-

Illumination, in lux.

-
- -## HallResponse - -Describes the Hall effect sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

status

-

number

-

Yes

-

Yes

-

Hall effect sensor status. This parameter specifies whether a magnetic field exists around a device. The value 0 means that a magnetic field exists around the device, and 1 means the opposite.

-
- -## MagneticFieldResponse - -Describes the magnetic field sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-
- -## MagneticFieldUncalibratedResponse - -Describes the uncalibrated magnetic field sensor data. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

x

-

number

-

Yes

-

Yes

-

X-coordinate component.

-

y

-

number

-

Yes

-

Yes

-

Y-coordinate component.

-

z

-

number

-

Yes

-

Yes

-

Z-coordinate component.

-

biasX

-

number

-

Yes

-

Yes

-

X-coordinate bias.

-

biasY

-

number

-

Yes

-

Yes

-

Y-coordinate bias.

-

biasZ

-

number

-

Yes

-

Yes

-

Z-coordinate bias.

-
- -## PedometerResponse - -Describes the pedometer sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

steps

-

number

-

Yes

-

Yes

-

Number of steps. The number starts from 0 each time the device restarts.

-
- -## HumidityResponse - -Describes the humidity sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

humidity

-

number

-

Yes

-

Yes

-

Ambient relative humidity, in a percentage (%).

-
- -## PedometerDetectResponse - -Describes the pedometer detection sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

scalar

-

number

-

Yes

-

Yes

-

Pedometer detection. This parameter specifies whether a user takes a step. The value 0 means that the user does not take a step, and 1 means that the user takes a step.

-
- -## AmbientTemperatureResponse - -Describes the ambient temperature sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

temperature

-

number

-

Yes

-

Yes

-

Ambient temperature, in degree Celsius.

-
- -## BarometerResponse - -Describes the barometer sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

pressure

-

number

-

Yes

-

Yes

-

Atmospheric pressure, in pascal.

-
- -## HeartRateResponse - -Describes the heart rate sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

heartRate

-

number

-

Yes

-

Yes

-

Heart rate, in beats per minute.

-
- -## WearDetectionResponse - -Describes the wear detection sensor data. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

value

-

boolean

-

Yes

-

Yes

-

Whether the device is being worn. The value true means that the device is being worn, and false means the opposite.

-
- -## Options + +| Name| Default Value| Description| +| -------- | -------- | -------- | +| SENSOR_TYPE_ID_ACCELEROMETER | 1 | Acceleration sensor.| +| SENSOR_TYPE_ID_GYROSCOPE | 2 | Gyroscope sensor.| +| SENSOR_TYPE_ID_AMBIENT_LIGHT | 5 | Ambient light sensor.| +| SENSOR_TYPE_ID_MAGNETIC_FIELD | 6 | Magnetic field sensor.| +| SENSOR_TYPE_ID_BAROMETER | 8 | Barometer sensor.| +| SENSOR_TYPE_ID_HALL | 10 | Hall effect sensor.| +| SENSOR_TYPE_ID_PROXIMITY | 12 | Proximity sensor.| +| SENSOR_TYPE_ID_HUMIDITY | 13 | Humidity sensor.| +| SENSOR_TYPE_ID_ORIENTATION | 256 | Orientation sensor.| +| SENSOR_TYPE_ID_GRAVITY | 257 | Gravity sensor.| +| SENSOR_TYPE_ID_LINEAR_ACCELERATION | 258 | Linear acceleration sensor.| +| SENSOR_TYPE_ID_ROTATION_VECTOR | 259 | Rotation vector sensor.| +| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | 260 | Ambient temperature sensor.| +| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261 | Uncalibrated magnetic field sensor.| +| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 263 | Uncalibrated gyroscope sensor.| +| SENSOR_TYPE_ID_SIGNIFICANT_MOTION | 264 | Significant motion sensor.| +| SENSOR_TYPE_ID_PEDOMETER_DETECTION | 265 | Pedometer detection sensor.| +| SENSOR_TYPE_ID_PEDOMETER | 266 | Pedometer sensor.| +| SENSOR_TYPE_ID_HEART_RATE | 278 | Heart rate sensor.| +| SENSOR_TYPE_ID_WEAR_DETECTION | 280 | Wear detection sensor.| +| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 281 | Uncalibrated acceleration sensor.| + + +## Response + +Describes the timestamp of the sensor data. + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| timestamp | number | Yes| Yes| Timestamp when the sensor reports data.| + + +## AccelerometerResponse + +Describes the acceleration sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| Acceleration along the x-axis of the device, in m/s2.| +| y | number | Yes| Yes| Acceleration along the y-axis of the device, in m/s2.| +| z | number | Yes| Yes| Acceleration along the z-axis of the device, in m/s2.| + + +## LinearAccelerometerResponse + +Describes the linear acceleration sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| Linear acceleration along the x-axis of the device, in m/s2.| +| y | number | Yes| Yes| Linear acceleration along the y-axis of the device, in m/s2.| +| z | number | Yes| Yes| Linear acceleration along the z-axis of the device, in m/s2.| + + +## AccelerometerUncalibratedResponse + +Describes the uncalibrated acceleration sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| Uncalibrated acceleration along the x-axis of the device, in m/s2.| +| y | number | Yes| Yes| Uncalibrated acceleration along the y-axis of the device, in m/s2.| +| z | number | Yes| Yes| Uncalibrated acceleration along the z-axis of the device, in m/s2.| +| biasX | number | Yes| Yes| Uncalibrated acceleration bias along the x-axis of the device, in m/s2.| +| biasY | number | Yes| Yes| Uncalibrated acceleration bias along the y-axis of the device, in m/s2.| +| biasZ | number | Yes| Yes| Uncalibrated acceleration bias along the z-axis of the device, in m/s2.| + + +## GravityResponse + +Describes the gravity sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| Gravitational acceleration along the x-axis of the device, in m/s2.| +| y | number | Yes| Yes| Gravitational acceleration along the y-axis of the device, in m/s2.| +| z | number | Yes| Yes| Gravitational acceleration along the z-axis of the device, in m/s2.| + + +## OrientationResponse + +Describes the orientation sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| Rotation angle of the device around the x-axis, in rad.| +| y | number | Yes| Yes| Rotation angle of the device around the y-axis, in rad.| +| z | number | Yes| Yes| Rotation angle of the device around the z-axis, in rad.| + + +## RotationVectorResponse + +Describes the rotation vector sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| X-component of the rotation vector.| +| y | number | Yes| Yes| Y-component of the rotation vector.| +| z | number | Yes| Yes| Z-component of the rotation vector.| + + +## GyroscopeResponse + +Describes the gyroscope sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| Angular velocity of rotation around the x-axis of the device, in rad/s.| +| y | number | Yes| Yes| Angular velocity of rotation around the y-axis of the device, in rad/s.| +| z | number | Yes| Yes| Angular velocity of rotation around the z-axis of the device, in rad/s.| + + +## GyroscopeUncalibratedResponse + +Describes the uncalibrated gyroscope sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| Uncalibrated angular velocity of rotation around the x-axis of the device, in rad/s.| +| y | number | Yes| Yes| Uncalibrated angular velocity of rotation around the y-axis of the device, in rad/s.| +| z | number | Yes| Yes| Uncalibrated angular velocity of rotation around the z-axis of the device, in rad/s.| +| biasX | number | Yes| Yes| Uncalibrated angular velocity bias of rotation around the x-axis of the device, in rad/s.| +| biasY | number | Yes| Yes| Uncalibrated angular velocity bias of rotation around the y-axis of the device, in rad/s.| +| biasZ | number | Yes| Yes| Uncalibrated angular velocity bias of rotation around the z-axis of the device, in rad/s.| + + +## SignificantMotionResponse + +Describes the significant motion sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| scalar | number | Yes| Yes| Intensity of a motion. This parameter specifies whether a device has a significant motion on three physical axes (X, Y, and Z). The value **0** means that the device does not have a significant motion, and **1** means the opposite.| + + +## ProximityResponse + +Describes the proximity sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| distance | number | Yes| Yes| Proximity between the visible object and the device monitor. The value **0** means the two are close to each other, and **1** means that they are far away from each other.| + + +## LightResponse + +Describes the ambient light sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| intensity | number | Yes| Yes| Illumination, in lux.| + + +## HallResponse + +Describes the Hall effect sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| status | number | Yes| Yes| Hall effect sensor status. This parameter specifies whether a magnetic field exists around a device. The value **0** means that a magnetic field exists around the device, and **1** means the opposite.| + + +## MagneticFieldResponse + +Describes the magnetic field sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| Magnetic field strength on the x-axis, in μT.| +| y | number | Yes| Yes| Magnetic field strength on the y-axis, in μT.| +| z | number | Yes| Yes| Magnetic field strength on the z-axis, in μT.| + + +## MagneticFieldUncalibratedResponse + +Describes the uncalibrated magnetic field sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| Uncalibrated magnetic field strength on the x-axis, in μT.| +| y | number | Yes| Yes| Uncalibrated magnetic field strength on the y-axis, in μT.| +| z | number | Yes| Yes| Uncalibrated magnetic field strength on the z-axis, in μT.| +| biasX | number | Yes| Yes| Bias of the uncalibrated magnetic field strength on the x-axis, in μT.| +| biasY | number | Yes| Yes| Bias of the uncalibrated magnetic field strength on the y-axis, in μT.| +| biasZ | number | Yes| Yes| Bias of the uncalibrated magnetic field strength on the z-axis, in μT.| + + +## PedometerResponse + +Describes the pedometer sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| steps | number | Yes| Yes| Number of steps a user has walked.| + + +## HumidityResponse + +Describes the humidity sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| humidity | number | Yes| Yes| Ambient relative humidity, in a percentage (%).| + + +## PedometerDetectResponse + +Describes the pedometer detection sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| scalar | number | Yes| Yes| Pedometer detection. This parameter specifies whether a user takes a step. The value **0** means that the user does not take a step, and **1** means that the user takes a step.| + + +## AmbientTemperatureResponse + +Describes the ambient temperature sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| temperature | number | Yes| Yes| Ambient temperature, in degree Celsius.| + + +## BarometerResponse + +Describes the barometer sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| pressure | number | Yes| Yes| Atmospheric pressure, in pascal.| + + +## HeartRateResponse + +Describes the heart rate sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| heartRate | number | Yes| Yes| Heart rate, in beats per minute (bpm).| + + +## WearDetectionResponse + +Describes the wear detection sensor data. It extends from [Response](#response). + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| value | number | Yes| Yes| Whether the device is being worn. The value **1** means that the device is being worn, and **0** means the opposite.| + + +## Options Describes the sensor data reporting frequency. - - - - - - - - - - - -

Name

-

Type

-

Description

-

interval

-

number

-

Frequency at which a sensor reports data. The default value is 200,000,000 ns.

-
+| Name| Type| Description| +| -------- | -------- | -------- | +| interval | number | Frequency at which a sensor reports data. The default value is 200,000,000 ns.| + + +## GeomagneticResponse + +Describes a geomagnetic response object. It extends from [Response](#response). + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| x | number | Yes| Yes| North component of the geomagnetic field.| +| y | number | Yes| Yes| East component of the geomagnetic field.| +| z | number | Yes| Yes| Vertical component of the geomagnetic field.| +| geomagneticDip | number | Yes| Yes| Magnetic dip, also called magnetic inclination, which is the angle measured from the horizontal plane to the magnetic field vector.| +| deflectionAngle | number | Yes| Yes| Magnetic declination, which is the angle between true north (geographic north) and the magnetic north (the horizontal component of the field).| +| levelIntensity | number | Yes| Yes| Horizontal intensity of the magnetic field vector field.| +| totalIntensity | number | Yes| Yes| Total intensity of the magnetic field vector.| + + +## LocationOptions +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| latitude | number | Yes| Yes| Latitude.| +| longitude | number | Yes| Yes| Longitude.| +| altitude | number | Yes| Yes| Altitude.| diff --git a/en/application-dev/reference/apis/js-apis-vibrator.md b/en/application-dev/reference/apis/js-apis-vibrator.md index 661c24307550feeee1e511d2c9058aa649b2705a..f309d858016300549a829a3572b7c368779b1f78 100644 --- a/en/application-dev/reference/apis/js-apis-vibrator.md +++ b/en/application-dev/reference/apis/js-apis-vibrator.md @@ -1,413 +1,191 @@ -# Vibration +# Vibrator ->![](../../public_sys-resources/icon-note.gif) **NOTE:** ->The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** +> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. -## Modules to Import + +## Modules to Import ``` -import vibrate from '@ohos.vibrator'; +import vibrator from '@ohos.vibrator'; ``` -## Required Permissions +## System Capabilities + +SystemCapability.Sensors.MiscDevice + +## Required Permissions ohos.permission.VIBRATE -## vibrate.vibrate -vibrate\(duration: number\): Promise +## vibrator.vibrate + +vibrate(duration: number): Promise<void> + Triggers vibration with a specific duration. This method uses a promise to return the execution result. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

duration

-

number

-

Yes

-

Vibration duration.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<void>

-

Promise used to indicate whether the vibration is triggered successfully.

-
- - -- Example - - ``` - vibrator.vibrate(1000).then(error)=>{ - if(error){ - console.log("error.code"+error.code+"error.message"+error.message); - }else{ - console.log("Promise returned to indicate a successful vibration."); - } - } - ``` - - -## vibrate.vibrate - -vibrate\(duration: number, callback?: AsyncCallback\): void + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | duration | number | Yes| Vibration duration.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<void> | Promise used to indicate whether the vibration is triggered successfully.| + + +- Example + ``` + vibrator.vibrate(1000).then(()=>{ + console.log("Promise returned to indicate a successful vibration."); + }, (error)=>{ + console.log("error.code"+error.code+"error.message"+error.message); + }); + ``` + + +## vibrator.vibrate + +vibrate(duration: number, callback?: AsyncCallback<void>): void Triggers vibration with a specific duration. This method uses a callback to return the execution result. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

duration

-

number

-

Yes

-

Vibration duration.

-

callback

-

AsyncCallback<void>

-

No

-

Callback used to indicate whether the vibration is triggered successfully.

-
- -- Example - - ``` - vibrator.vibrate(1000,function(error){ - if(error){ - console.log("error.code"+error.code+"error.message"+error.message); - }else{ - console.log("Callback returned to indicate a successful vibration."); - } - }) - ``` - - -## vibrate.vibrate - -vibrate\(effectId: EffectId\): Promise +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | duration | number | Yes| Vibration duration.| + | callback | AsyncCallback<void> | No| Callback used to indicate whether the vibration is triggered successfully.| + +- Example + ``` + vibrator.vibrate(1000,function(error){ + if(error){ + console.log("error.code"+error.code+"error.message"+error.message); + }else{ + console.log("Callback returned to indicate a successful vibration."); + } + }) + ``` + + +## vibrator.vibrate + +vibrate(effectId: EffectId): Promise<void> Triggers vibration with a specific effect. This method uses a promise to return the execution result. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

effectId

-

EffectId

-

Yes

-

String that indicates the vibration effect.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<void>

-

Promise used to indicate whether the vibration is triggered successfully.

-
- - -- Example - - ``` - vibrator.vibrate(effectId:EffectId).then(error)=>{ - if(error){ - console.log("error.code"+error.code+"error.message"+error.message); - }else{ - Console.log("Promise returned to indicate a successful vibration."); - } - } - ``` - - -## vibrate.vibrate - -vibrate\(effectId: EffectId, callback?: AsyncCallback\): void +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | effectId | [EffectId](#effectid) | Yes| String that indicates the vibration effect.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<void> | Promise used to indicate whether the vibration is triggered successfully.| + +- Example + ``` + vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(()=>{ + console.log("Promise returned to indicate a successful vibration."); + }, (error)=>{ + console.log("error.code"+error.code+"error.message"+error.message); + }); + ``` + + +## vibrator.vibrate + +vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void Triggers vibration with a specific effect. This method uses a callback to return the execution result. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

effectId

-

EffectId

-

Yes

-

String that indicates the vibration effect.

-

callback

-

AsyncCallback<void>

-

No

-

Callback used to indicate whether the vibration is triggered successfully.

-
- -- Example - - ``` - vibrator.vibrate(effectId:EffectId,function(error){ - if(error){ - console.log("error.code"+error.code+"error.message"+error.message); - }else{ - console.log("Callback returned to indicate a successful vibration."); - } - }) - ``` - - -## vibrate.stop - -stop\(stopMode: VibratorStopMode\): Promise - -Stops the vibration based on the specified **stopMode**. This method uses a promise to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this method fails to be called. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

stopMode

-

VibratorStopMode

-

Yes

-

Vibration mode to stop.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<void>

-

Promise used to indicate whether the vibration is stopped successfully.

-
- - -- Example - - ``` - vibrator.stop(stopMode:VibratorStopMode).then((error)=>{ - if(error){ - console.log("error.code"+error.code+"error.message"+error.message); - }else{ - Console.log("Promise returned to indicate a successful stop."); - } - }) - ``` - - -## vibrate.stop - -stop\(stopMode: VibratorStopMode, callback?: AsyncCallback\): void; - -Stops the vibration based on the specified **stopMode**. This method uses a callback to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this method fails to be called. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

stopMode

-

VibratorStopMode

-

Yes

-

Vibration mode to stop.

-

callback

-

AsyncCallback<void>

-

No

-

Callback used to indicate whether the vibration is stopped successfully.

-
- -- Example - - ``` - vibrator.stop(stopMode:VibratorStopMode,function(error){ - if(error){ - console.log("error.code"+error.code+"error.message"+error.message); - }else{ - Console.log("Callback returned to indicate a successful stop."); - } - }) - ``` - - -## EffectId +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | effectId | [EffectId](#effectid) | Yes| String that indicates the vibration effect.| + | callback | AsyncCallback<void> | No| Callback used to indicate whether the vibration is triggered successfully.| + +- Example + ``` + vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER, function(error){ + if(error){ + console.log("error.code"+error.code+"error.message"+error.message); + }else{ + console.log("Callback returned to indicate a successful vibration."); + } + }) + ``` + + +## vibrator.stop + +stop(stopMode: VibratorStopMode): Promise<void> + +Stops the vibration based on the specified **stopMode**. This method uses a promise to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this method fails to be called. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | stopMode | [VibratorStopMode](#vibratorstopmode) | Yes| Vibration mode to stop.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<void> | Promise used to indicate whether the vibration is stopped successfully.| + +- Example + ``` + vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(()=>{ + console.log("Promise returned to indicate a successful vibration."); + }, (error)=>{ + console.log("error.code"+error.code+"error.message"+error.message); + }); + ``` + + +## vibrator.stop + +stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void; + +Stops the vibration based on the specified **stopMode**. This method uses an asynchronous callback to return the execution result. If the specified **stopMode** is different from the mode used to trigger the vibration, this method fails to be called. + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | stopMode | [VibratorStopMode](#vibratorstopmode) | Yes| Vibration mode to stop.| + | callback | AsyncCallback<void> | No| Callback used to indicate whether the vibration is stopped successfully.| + +- Example + ``` + vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET, function(error){ + if(error){ + console.log("error.code"+error.code+"error.message"+error.message); + }else{ + console.log("Callback returned to indicate a successful stop."); + } + }) + ``` + + +## EffectId Describes the vibration effect. - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

EFFECT_CLOCK_TIMER

-

"haptic.clock.timer"

-

Vibration effect of the vibrator when a user adjusts the timer.

-
- -## VibratorStopMode +| Name| Default Value| Description| +| -------- | -------- | -------- | +| EFFECT_CLOCK_TIMER | "haptic.clock.timer" | Vibration effect of the vibrator when a user adjusts the timer.| -Describes the vibration mode to stop. - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

VIBRATOR_STOP_MODE_TIME

-

"time"

-

Indicates that the vibration to stop is in duration mode. This vibration is triggered with the parameter duration of the number type.

-

VIBRATOR_STOP_MODE_PRESET

-

"preset"

-

Indicates the vibration to stop is in EffectId mode. This vibration is triggered with the parameter effectId of the EffectId type.

-
+## VibratorStopMode + +Describes the vibration mode to stop. +| Name| Default Value| Description| +| -------- | -------- | -------- | +| VIBRATOR_STOP_MODE_TIME | "time" | The vibration to stop is in **duration** mode. This vibration is triggered with the parameter **duration** of the **number** type.| +| VIBRATOR_STOP_MODE_PRESET | "preset" | The vibration to stop is in **EffectId** mode. This vibration is triggered with the parameter **effectId** of the **EffectId** type.|