diff --git a/en/application-dev/device/sensor-guidelines.md b/en/application-dev/device/sensor-guidelines.md index d3bb893bbbdf1c23192f3397e54d745cf920043c..6ff5eb7405027da0853737ba64959cec4e59ad3a 100644 --- a/en/application-dev/device/sensor-guidelines.md +++ b/en/application-dev/device/sensor-guidelines.md @@ -31,12 +31,13 @@ For details about the APIs, see [Sensor](../reference/apis/js-apis-sensor.md). For details about how to configure a permission, see [Declaring Permissions](../security/accesstoken-guidelines.md). -2. Subscribe to data changes of a type of sensor. The following uses the acceleration sensor as an example. +2. Subscribe to data changes of a type of sensor. The following uses the acceleration sensor as an example. - ```js + ```ts import sensor from "@ohos.sensor"; - sensor.on(sensor.SensorId.ACCELEROMETER, function(data){ - console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. + + sensor.on(sensor.SensorId.ACCELEROMETER, function (data) { + console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. }); ``` @@ -44,7 +45,7 @@ For details about the APIs, see [Sensor](../reference/apis/js-apis-sensor.md). 3. Unsubscribe from sensor data changes. - ```js + ```ts import sensor from "@ohos.sensor"; sensor.off(sensor.SensorId.ACCELEROMETER); ``` @@ -53,10 +54,11 @@ For details about the APIs, see [Sensor](../reference/apis/js-apis-sensor.md). 4. Subscribe to only one data change of a type of sensor. - ```js + ```ts import sensor from "@ohos.sensor"; - sensor.once(sensor.SensorId.ACCELEROMETER, function(data) { - console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. + + sensor.once(sensor.SensorId.ACCELEROMETER, function (data) { + console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. }); ``` @@ -64,13 +66,14 @@ For details about the APIs, see [Sensor](../reference/apis/js-apis-sensor.md). If the API fails to be called, you are advised to use the **try/catch** statement to capture error information that may occur in the code. Example: - ```js + ```ts import sensor from "@ohos.sensor"; - try { - sensor.once(sensor.SensorId.ACCELEROMETER, function(data) { - console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. - }); - } catch (error) { - console.error("Get sensor data error. data:" + error.data, " msg:", error.message); - } + + try { + sensor.once(sensor.SensorId.ACCELEROMETER, function (data) { + console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. + }); + } catch (error) { + console.error(`Failed to get sensor data. Code: ${error.code}, message: ${error.message}`); + } ``` diff --git a/en/application-dev/device/vibrator-guidelines.md b/en/application-dev/device/vibrator-guidelines.md index cfa6e7cd1d26d5781a850384aa4be148ebb247e2..7d3434d680d0d1a369d4f0ccd0bc8f720bd71349 100644 --- a/en/application-dev/device/vibrator-guidelines.md +++ b/en/application-dev/device/vibrator-guidelines.md @@ -78,8 +78,8 @@ This JSON file contains two attributes: **MetaData** and **Channels**. - **Channels** provides information about the vibration channel. It is a JSON array that holds information about each channel. It contains two attributes: **Parameters** and **Pattern**. - **Parameters** provides parameters related to the channel. Under it, **Index** indicates the channel ID. The value is fixed at **1** for a single channel. This parameter is mandatory. - **Pattern** indicates the vibration sequence. It is a JSON array. Under it, **Event** indicates a vibration event, which can be either of the following types: - - **transient**: short vibration - - **continuous**: long vibration +- **transient**: short vibration + - **continuous**: long vibration The table below describes the parameters under **Event**. @@ -105,170 +105,161 @@ The following requirements must be met: 2. Start vibration with the specified effect and attribute. - ```js + ```ts import vibrator from '@ohos.vibrator'; + try { - vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission. - type: 'time', - duration: 1000, - }, { - id: 0, - usage: 'alarm' - }, (error) => { - if (error) { - console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message); - return; - } - console.log('Callback returned to indicate a successful vibration.'); - }); + vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission. + type: 'time', + duration: 1000, + }, { + id: 0, + usage: 'alarm' + }, (error) => { + if (error) { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in starting vibration.'); + }); } catch (err) { - console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + console.error(`An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); } ``` 3. Stop vibration in the specified mode. - ```js + ```ts import vibrator from '@ohos.vibrator'; + try { - // Stop vibration in VIBRATOR_STOP_MODE_TIME mode. To use stopVibration, you must configure the ohos.permission.VIBRATE permission. - vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, function (error) { - if (error) { - console.log('error.code' + error.code + 'error.message' + error.message); - return; - } - console.log('Callback returned to indicate successful.'); - }) + // Stop vibration in VIBRATOR_STOP_MODE_TIME mode. To use stopVibration, you must configure the ohos.permission.VIBRATE permission. + vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, function (error) { + if (error) { + console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeeded in stopping vibration.'); + }) } catch (err) { - console.info('errCode: ' + err.code + ' ,msg: ' + err.message); + console.error(`An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); } ``` 4. Stop vibration in all modes. - ```js + ```ts import vibrator from '@ohos.vibrator'; // To use startVibration and stopVibration, you must configure the ohos.permission.VIBRATE permission. try { - vibrator.startVibration({ - type: 'time', - duration: 1000, - }, { - id: 0, - usage: 'alarm' - }, (error) => { - if (error) { - console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message); - return; - } - console.log('Callback returned to indicate a successful vibration.'); - }); - // Stop vibration in all modes. - vibrator.stopVibration(function (error) { - if (error) { - console.log('error.code' + error.code + 'error.message' + error.message); - return; - } - console.log('Callback returned to indicate successful.'); - }) + vibrator.startVibration({ + type: 'time', + duration: 1000, + }, { + id: 0, + usage: 'alarm' + }, (error) => { + if (error) { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in starting vibration'); + }); + // Stop vibration in all modes. + vibrator.stopVibration(function (error) { + if (error) { + console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in stopping vibration'); + }) } catch (error) { - console.info('errCode: ' + error.code + ' ,msg: ' + error.message); + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` 5. Check whether the passed effect ID is supported. - ```js + ```ts import vibrator from '@ohos.vibrator'; + try { - // Check whether 'haptic.clock.timer' is supported. - vibrator.isSupportEffect('haptic.clock.timer', function (err, state) { - if (err) { - console.error('isSupportEffect failed, error:' + JSON.stringify(err)); - return; - } - console.log('The effectId is ' + (state ? 'supported' : 'unsupported')); - if (state) { - try { - vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission. - type: 'preset', - effectId: 'haptic.clock.timer', - count: 1, - }, { - usage: 'unknown' - }, (error) => { - if(error) { - console.error('haptic.clock.timer vibrator error:' + JSON.stringify(error)); - } else { - console.log('haptic.clock.timer vibrator success'); - } - }); - } catch (error) { - console.error('Exception in, error:' + JSON.stringify(error)); - } - } - }) + // Check whether 'haptic.clock.timer' is supported. + vibrator.isSupportEffect('haptic.clock.timer', function (err, state) { + if (err) { + console.error(`Failed to query effect. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info('Succeed in querying effect'); + if (state) { + try { + vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission. + type: 'preset', + effectId: 'haptic.clock.timer', + count: 1, + }, { + usage: 'unknown' + }, (error) => { + if (error) { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + } else { + console.info('Succeed in starting vibration'); + } + }); + } catch (error) { + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); + } + } + }) } catch (error) { - console.error('Exception in, error:' + JSON.stringify(error)); + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` 6. Start and stop custom vibration. - ```js + ```ts import vibrator from '@ohos.vibrator'; - import resourceManager from '@ohos.resourceManager'; const FILE_NAME = "xxx.json"; - async function openResource(fileName) { - let fileDescriptor = undefined; - let mgr = await resourceManager.getResourceManager(); - await mgr.getRawFd(fileName).then(value => { - fileDescriptor = {fd: value.fd, offset: value.offset, length: value.length}; - console.log('openResource success fileName: ' + fileName); - }).catch(error => { - console.log('openResource err: ' + error); - }); - return fileDescriptor; - } - - async function closeResource(fileName) { - let mgr = await resourceManager.getResourceManager(); - await mgr.closeRawFd(fileName).then(()=> { - console.log('closeResource success fileName: ' + fileName); - }).catch(error => { - console.log('closeResource err: ' + error); - }); - } - // Obtain the file descriptor of the vibration configuration file. - let rawFd = openResource(FILE_NAME); + let fileDescriptor = undefined; + getContext().resourceManager.getRawFd(FILE_NAME).then(value => { + fileDescriptor = { fd: value.fd, offset: value.offset, length: value.length }; + console.info('Succeed in getting resource file descriptor'); + }).catch(error => { + console.error(`Failed to get resource file descriptor. Code: ${error.code}, message: ${error.message}`); + }); // To use startVibration and stopVibration, you must configure the ohos.permission.VIBRATE permission. try { - // Start custom vibration. - vibrator.startVibration({ - type: "file", - hapticFd: { fd: rawFd.fd, offset: rawFd.offset, length: rawFd.length } - }, { - usage: "alarm" - }).then(() => { - console.info('startVibration success'); - }, (error) => { - console.info('startVibration error'); - }); - // Stop vibration in all modes. - vibrator.stopVibration(function (error) { - if (error) { - console.log('error.code' + error.code + 'error.message' + error.message); - return; - } - console.log('Callback returned to indicate successful.'); - }) + // Start custom vibration. + vibrator.startVibration({ + type: "file", + hapticFd: { fd: fileDescriptor.fd, offset: fileDescriptor.offset, length: fileDescriptor.length } + }, { + usage: "alarm" + }).then(() => { + console.info('Succeed in starting vibration'); + }, (error) => { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + }); + // Stop vibration in all modes. + vibrator.stopVibration(function (error) { + if (error) { + console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in stopping vibration'); + }) } catch (error) { - console.info('errCode: ' + error.code + ' ,msg: ' + error.message); + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } - // Close the vibration configuration file. - closeResource(FILE_NAME); + // Close the vibration file. + getContext().resourceManager.closeRawFd(FILE_NAME).then(() => { + console.info('Succeed in closing resource file descriptor'); + }).catch(error => { + console.error(`Failed to close resource file descriptor. Code: ${error.code}, message: ${error.message}`); + }); ``` diff --git a/en/application-dev/reference/apis/js-apis-sensor.md b/en/application-dev/reference/apis/js-apis-sensor.md index f439302caddedbbffbe160778843db8e72a6a826..e2058f68ea5d50766c17fa4381fbf6453aa19b4e 100644 --- a/en/application-dev/reference/apis/js-apis-sensor.md +++ b/en/application-dev/reference/apis/js-apis-sensor.md @@ -9,11 +9,87 @@ The **Sensor** module provides APIs for obtaining the sensor list and subscribin ## Modules to Import -```js +```ts import sensor from '@ohos.sensor'; ``` +## sensor.on -## sensor.on9+ +### COLOR10+ + +on(type: SensorId.COLOR, callback: Callback\,options?: Options): void + +Subscribes to data of the color sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +**System API**: This is a system API. + +**Error code** + +For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). + +| ID| Error Message | +| -------- | ------------------ | +| 14500101 | Service exception. | + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).COLOR | Yes | Sensor type. The value is fixed at **SensorId.COLOR**. | +| callback | Callback<[ColorResponse](#colorresponse)> | Yes | Callback used to report the sensor data, which is a **ColorResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| + +**Example** + +```ts +try { + sensor.on(sensor.SensorId.COLOR, function (data) { + console.info('Succeeded in getting the intensity of light: ' + data.lightIntensity); + console.info('Succeeded in getting the color temporature: ' + data.colorTemperature); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); +} +``` + +### SAR10+ + +on(type: SensorId.SAR, callback: Callback\,options?: Options): void + +Subscribes to data of the Sodium Adsorption Ratio (SAR) sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +**System API**: This is a system API. + +**Error code** + +For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). + +| ID| Error Message | +| -------- | ------------------ | +| 14500101 | Service exception. | + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).SAR | Yes | Sensor type. The value is fixed at **SensorId.SAR**. | +| callback | Callback<[SarResponse](#sarresponse)> | Yes | Callback used to report the sensor data, which is a **SarResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| + +**Example** + +```ts +try { + sensor.on(sensor.SensorId.SAR, function (data) { + console.info('Succeeded in getting specific absorption rate : ' + data.absorptionRatio); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); +} +``` ### ACCELEROMETER9+ @@ -31,7 +107,7 @@ Subscribes to data of the acceleration sensor. | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | | type | [SensorId](#sensorid9).ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**. | | callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -43,15 +119,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.ACCELEROMETER, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.ACCELEROMETER, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -71,7 +147,7 @@ Subscribes to data of the uncalibrated acceleration sensor. | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. | | callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerUncalibratedResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Error code** @@ -83,18 +159,18 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -108,11 +184,11 @@ Subscribes to data of the ambient light sensor. **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------- | ---- | --------------------------------------------------- | -| type | [SensorId](#sensorid9).AMBIENT_LIGHT | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**. | -| callback | Callback<[LightResponse](#lightresponse)> | Yes | Callback used to report the sensor data, which is a **LightResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).AMBIENT_LIGHT | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**. | +| callback | Callback<[LightResponse](#lightresponse)> | Yes | Callback used to report the sensor data, which is a **LightResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -124,13 +200,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.AMBIENT_LIGHT, function (data) { - console.info('The ambient light intensity: ' + data.intensity); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.AMBIENT_LIGHT, function (data) { + console.info('Succeeded in getting the ambient light intensity: ' + data.intensity); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -148,7 +224,7 @@ Subscribes to data of the ambient temperature sensor. | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorId](#sensorid9).AMBIENT_TEMPERATURE | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**. | | callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes | Callback used to report the sensor data, which is an **AmbientTemperatureResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Error code** @@ -160,13 +236,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, function (data) { - console.info('Temperature: ' + data.temperature); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, function (data) { + console.info('Succeeded in invoking on. Temperature: ' + data.temperature); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -180,11 +256,11 @@ Subscribes to data of the barometer sensor. **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | -| type | [SensorId](#sensorid9).BAROMETER | Yes | Sensor type. The value is fixed at **SensorId.BAROMETER**. | -| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | Callback used to report the sensor data, which is a **BarometerResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).BAROMETER | Yes | Sensor type. The value is fixed at **SensorId.BAROMETER**. | +| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | Callback used to report the sensor data, which is a **BarometerResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -196,13 +272,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.BAROMETER, function (data) { - console.info('Atmospheric pressure: ' + data.pressure); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.BAROMETER, function (data) { + console.info('Succeeded in invoking on. Atmospheric pressure: ' + data.pressure); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -216,11 +292,11 @@ Subscribes to data of the gravity sensor. **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------- | -| type | [SensorId](#sensorid9).GRAVITY | Yes | Sensor type. The value is fixed at **SensorId.GRAVITY**. | -| callback | Callback<[GravityResponse](#gravityresponse)> | Yes | Callback used to report the sensor data, which is a **GravityResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).GRAVITY | Yes | Sensor type. The value is fixed at **SensorId.GRAVITY**. | +| callback | Callback<[GravityResponse](#gravityresponse)> | Yes | Callback used to report the sensor data, which is a **GravityResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -232,15 +308,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.GRAVITY, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.GRAVITY, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -256,11 +332,11 @@ Subscribes to data of the gyroscope sensor. **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | -| type | [SensorId](#sensorid9).GYROSCOPE | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE**. | -| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).GYROSCOPE | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE**. | +| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -272,15 +348,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.GYROSCOPE, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.GYROSCOPE, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -301,7 +377,7 @@ Subscribes to data of the uncalibrated gyroscope sensor. | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**. | | callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeUncalibratedResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Error code** @@ -313,18 +389,18 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -338,11 +414,11 @@ Subscribes to data of the Hall effect sensor. **Parameters** -| Name | Type | Mandatory| Description | -| -------- | --------------------------------------------- | ---- | -------------------------------------------------- | -| type | [SensorId](#sensorid9).HALL | Yes | Sensor type. The value is fixed at **SensorId.HALL**. | -| callback | Callback<[HallResponse](#hallresponse)> | Yes | Callback used to report the sensor data, which is a **HallResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).HALL | Yes | Sensor type. The value is fixed at **SensorId.HALL**. | +| callback | Callback<[HallResponse](#hallresponse)> | Yes | Callback used to report the sensor data, which is a **HallResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -354,13 +430,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.HALL, function (data) { - console.info('Hall status: ' + data.status); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.HALL, function (data) { + console.info('Succeeded in invoking on. Hall status: ' + data.status); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -376,11 +452,11 @@ Subscribes to data of the heart rate sensor. **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | -| type | [SensorId](#sensorid9).HEART_RATE | Yes | Sensor type. The value is fixed at **SensorId.HEART_RATE**. | -| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | Callback used to report the sensor data, which is a **HeartRateResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).HEART_RATE | Yes | Sensor type. The value is fixed at **SensorId.HEART_RATE**. | +| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | Callback used to report the sensor data, which is a **HeartRateResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -392,13 +468,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.HEART_RATE, function (data) { - console.info('Heart rate: ' + data.heartRate); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.HEART_RATE, function (data) { + console.info('Succeeded in invoking on. Heart rate: ' + data.heartRate); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -412,11 +488,11 @@ Subscribes to data of the humidity sensor. **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------ | -| type | [SensorId](#sensorid9).HUMIDITY | Yes | Sensor type. The value is fixed at **SensorId.HUMIDITY**. | -| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | Callback used to report the sensor data, which is a **HumidityResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).HUMIDITY | Yes | Sensor type. The value is fixed at **SensorId.HUMIDITY**. | +| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | Callback used to report the sensor data, which is a **HumidityResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -428,13 +504,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.HUMIDITY, function (data) { - console.info('Humidity: ' + data.humidity); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.HUMIDITY, function (data) { + console.info('Succeeded in invoking on. Humidity: ' + data.humidity); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -455,7 +531,7 @@ Subscribes to data of the linear acceleration sensor. | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorId](#sensorid9).LINEAR_ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELEROMETER**. | | callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes | Callback used to report the sensor data, which is a **LinearAccelerometerResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Error code** @@ -467,15 +543,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -493,7 +569,7 @@ Subscribes to data of the magnetic field sensor. | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | | type | [SensorId](#sensorid9).MAGNETIC_FIELD | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**. | | callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -505,15 +581,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.MAGNETIC_FIELD, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.MAGNETIC_FIELD, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -531,7 +607,7 @@ Subscribes to data of the uncalibrated magnetic field sensor. | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.| | callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldUncalibratedResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Error code** @@ -543,18 +619,18 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -576,23 +652,23 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ----------------------------------------------------------- | ---- | --------------------------------------------------------- | -| type | [SensorId](#sensorid9).ORIENTATION | Yes | Sensor type. The value is fixed at **SensorId.ORIENTATION**. | -| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | Callback used to report the sensor data, which is a **OrientationResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).ORIENTATION | Yes | Sensor type. The value is fixed at **SensorId.ORIENTATION**. | +| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | Callback used to report the sensor data, which is a **OrientationResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Example** -```js +```ts try { - sensor.on(sensor.SensorId.ORIENTATION, function (data) { - console.info('The device rotates at an angle around the Z axis: ' + data.alpha); - console.info('The device rotates at an angle around the X axis: ' + data.beta); - console.info('The device rotates at an angle around the Y axis: ' + data.gamma); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.ORIENTATION, function (data) { + console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha); + console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta); + console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -616,21 +692,21 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | -| type | [SensorId](#sensorid9).PEDOMETER | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER**. | -| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).PEDOMETER | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER**. | +| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Example** -```js +```ts try { - sensor.on(sensor.SensorId.PEDOMETER, function (data) { - console.info('Step count: ' + data.steps); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.PEDOMETER, function (data) { + console.info('Succeeded in invoking on. Step count: ' + data.steps); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -651,7 +727,7 @@ Subscribes to data of the pedometer detection sensor. | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorId](#sensorid9).PEDOMETER_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**. | | callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerDetectionResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Error code** @@ -663,13 +739,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.PEDOMETER_DETECTION, function (data) { - console.info('Pedometer scalar: ' + data.scalar); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.PEDOMETER_DETECTION, function (data) { + console.info('Succeeded in invoking on. Pedometer scalar: ' + data.scalar); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -683,11 +759,11 @@ Subscribes to data of the proximity sensor. **Parameters** -| Name | Type | Mandatory| Description | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | -| type | [SensorId](#sensorid9).PROXIMITY | Yes | Sensor type. The value is fixed at **SensorId.PROXIMITY**. | -| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | Callback used to report the sensor data, which is a **ProximityResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- | +| type | [SensorId](#sensorid9).PROXIMITY | Yes | Sensor type. The value is fixed at **SensorId.PROXIMITY**. | +| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | Callback used to report the sensor data, which is a **ProximityResponse** object. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -699,13 +775,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.PROXIMITY, function (data) { - console.info('Distance: ' + data.distance); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.PROXIMITY, function (data) { + console.info('Succeeded in invoking on. Distance: ' + data.distance); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -724,7 +800,7 @@ Subscribes to data of the rotation vector sensor. | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorId](#sensorid9).ROTATION_VECTOR | Yes | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**. | | callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes | Callback used to report the sensor data, which is a **RotationVectorResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Error code** @@ -736,16 +812,16 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.ROTATION_VECTOR, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('Scalar quantity: ' + data.w); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.ROTATION_VECTOR, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking on. Scalar quantity: ' + data.w); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -764,7 +840,7 @@ Subscribes to data of the significant motion sensor. | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorId](#sensorid9).SIGNIFICANT_MOTION | Yes | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**. | | callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes | Callback used to report the sensor data, which is a **SignificantMotionResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Error code** @@ -776,13 +852,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, function (data) { - console.info('Scalar data: ' + data.scalar); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, function (data) { + console.info('Succeeded in invoking on. Scalar data: ' + data.scalar); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -801,7 +877,7 @@ Subscribes to data of the wear detection sensor. | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | | type | [SensorId](#sensorid9).WEAR_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**. | | callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes | Callback used to report the sensor data, which is a **WearDetectionResponse** object.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Error code** @@ -813,13 +889,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.on(sensor.SensorId.WEAR_DETECTION, function (data) { - console.info('Wear status: ' + data.value); - }, { interval: 100000000 }); -} catch (err) { - console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.WEAR_DETECTION, function (data) { + console.info('Succeeded in invoking on. Wear status: ' + data.value); + }, { interval: 100000000 }); +} catch (error) { + console.error(`Failed to invoke on. Code: ${error.code}, message: ${error.message}`); } ``` @@ -852,15 +928,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.ACCELEROMETER, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.ACCELEROMETER, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -891,18 +967,18 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -931,13 +1007,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.AMBIENT_LIGHT, function (data) { - console.info('The ambient light intensity: ' + data.intensity); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.AMBIENT_LIGHT, function (data) { + console.info('Succeeded in invoking once. the ambient light intensity: ' + data.intensity); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -966,13 +1042,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.AMBIENT_TEMPERATURE, function (data) { - console.info('Temperature: ' + data.temperature); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.AMBIENT_TEMPERATURE, function (data) { + console.info('Succeeded in invoking once. Temperature: ' + data.temperature); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1001,13 +1077,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function (data) { - console.info('Atmospheric pressure: ' + data.pressure); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.BAROMETER, function (data) { + console.info('Succeeded in invoking once. Atmospheric pressure: ' + data.pressure); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1036,15 +1112,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.GRAVITY, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.GRAVITY, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1075,15 +1151,17 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts +import sensor from '@ohos.sensor'; + try { - sensor.once(sensor.SensorId.GYROSCOPE, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.GYROSCOPE, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1114,18 +1192,18 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.GYROSCOPE_UNCALIBRATED, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.GYROSCOPE_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1154,13 +1232,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.HALL, function (data) { - console.info('Status: ' + data.status); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.HALL, function (data) { + console.info('Succeeded in invoking once. Status: ' + data.status); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1191,13 +1269,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.HEART_RATE, function (data) { - console.info('Heart rate: ' + data.heartRate); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.HEART_RATE, function (data) { + console.info('Succeeded in invoking once. Heart rate: ' + data.heartRate); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1226,13 +1304,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.HUMIDITY, function (data) { - console.info('Humidity: ' + data.humidity); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.HUMIDITY, function (data) { + console.info('Succeeded in invoking once. Humidity: ' + data.humidity); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1263,15 +1341,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.LINEAR_ACCELEROMETER, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.LINEAR_ACCELEROMETER, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1300,15 +1378,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.MAGNETIC_FIELD, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.MAGNETIC_FIELD, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1337,18 +1415,18 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1377,15 +1455,15 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.ORIENTATION, function (data) { - console.info('The device rotates at an angle around the X axis: ' + data.beta); - console.info('The device rotates at an angle around the Y axis: ' + data.gamma); - console.info('The device rotates at an angle around the Z axis: ' + data.alpha); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.ORIENTATION, function (data) { + console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta); + console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma); + console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1416,13 +1494,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.PEDOMETER, function (data) { - console.info('Step count: ' + data.steps); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.PEDOMETER, function (data) { + console.info('Succeeded in invoking once. Step count: ' + data.steps); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1453,13 +1531,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.PEDOMETER_DETECTION, function (data) { - console.info('Scalar data: ' + data.scalar); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.PEDOMETER_DETECTION, function (data) { + console.info('Succeeded in invoking once. Scalar data: ' + data.scalar); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1488,13 +1566,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.PROXIMITY, function (data) { - console.info('Distance: ' + data.distance); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.PROXIMITY, function (data) { + console.info('Succeeded in invoking once. Distance: ' + data.distance); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1523,16 +1601,16 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.ROTATION_VECTOR, function (data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('Scalar quantity: ' + data.w); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.ROTATION_VECTOR, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking once. Scalar quantity: ' + data.w); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1561,13 +1639,13 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.SIGNIFICANT_MOTION, function (data) { - console.info('Scalar data: ' + data.scalar); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.SIGNIFICANT_MOTION, function (data) { + console.info('Succeeded in invoking once. Scalar data: ' + data.scalar); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1596,17 +1674,97 @@ For details about the following error codes, see [Sensor Error Codes](../errorco **Example** -```js +```ts try { - sensor.once(sensor.SensorId.WEAR_DETECTION, function (data) { - console.info("Wear status: " + data.value); - }); -} catch (err) { - console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.once(sensor.SensorId.WEAR_DETECTION, function (data) { + console.info('Succeeded in invoking once. Wear status: ' + data.value); + }); +} catch (error) { + console.error(`Failed to invoke once. Code: ${error.code}, message: ${error.message}`); +} +``` + +## sensor.off + +### COLOR10+ + +off(type: SensorId.COLOR, callback?: Callback\): void + +Unsubscribes from data of the color sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorId](#sensorid9).COLOR | Yes | Sensor type. The value is fixed at **SensorId.COLOR**. | +| callback | Callback<[ColorResponse](#colorresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| + +**Example** + +```ts +function callback1(data) { + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); +} + +function callback2(data) { + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); +} + +try { + sensor.on(sensor.SensorId.COLOR, callback1); + sensor.on(sensor.SensorId.COLOR, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.COLOR, callback1); + // Unsubscribe from all callbacks of the SensorId.COLOR type. + sensor.off(sensor.SensorId.COLOR); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` -## sensor.off9+ +### SAR10+ + +off(type: SensorId.SAR, callback?: Callback\): void + +Unsubscribes from data of the SAR sensor. + +**System capability**: SystemCapability.Sensors.Sensor + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | +| type | [SensorId](#sensorid9).SAR | Yes | Sensor type. The value is fixed at **SensorId.SAR**. | +| callback | Callback<[SarResponse](#sarresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| + +**Example** + +```ts +function callback1(data) { + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); +} + +function callback2(data) { + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); +} + +try { + sensor.on(sensor.SensorId.SAR, callback1); + sensor.on(sensor.SensorId.SAR, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.SAR, callback1); + // Unsubscribe from all callbacks of the SensorId.SAR type. + sensor.off(sensor.SensorId.SAR); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); +} +``` ### ACCELEROMETER9+ @@ -1627,22 +1785,24 @@ Unsubscribes from data of the acceleration sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.ACCELEROMETER, callback1); - sensor.on(sensor.SensorId.ACCELEROMETER, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.ACCELEROMETER, callback1); - // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER type. - sensor.off(sensor.SensorId.ACCELEROMETER); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.ACCELEROMETER, callback1); + sensor.on(sensor.SensorId.ACCELEROMETER, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.ACCELEROMETER, callback1); + // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER type. + sensor.off(sensor.SensorId.ACCELEROMETER); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1665,22 +1825,24 @@ Unsubscribes from data of the uncalibrated acceleration sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1); - sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1); - // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER_UNCALIBRATED type. - sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1); + sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1); + // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER_UNCALIBRATED type. + sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1701,22 +1863,24 @@ Unsubscribes from data of the ambient light sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback1); - sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback1); - // Unsubscribe from all callbacks of the SensorId.AMBIENT_LIGHT type. - sensor.off(sensor.SensorId.AMBIENT_LIGHT); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback1); + sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback1); + // Unsubscribe from all callbacks of the SensorId.AMBIENT_LIGHT type. + sensor.off(sensor.SensorId.AMBIENT_LIGHT); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1737,22 +1901,24 @@ Unsubscribes from data of the ambient temperature sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback1); - sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE, callback1); - // Unsubscribe from all callbacks of the SensorId.AMBIENT_TEMPERATURE type. - sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback1); + sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE, callback1); + // Unsubscribe from all callbacks of the SensorId.AMBIENT_TEMPERATURE type. + sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1773,13 +1939,15 @@ Unsubscribes from data of the barometer sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { sensor.on(sensor.SensorId.BAROMETER, callback1); sensor.on(sensor.SensorId.BAROMETER, callback2); @@ -1787,8 +1955,8 @@ try { sensor.off(sensor.SensorId.BAROMETER, callback1); // Unsubscribe from all callbacks of the SensorId.BAROMETER type. sensor.off(sensor.SensorId.BAROMETER); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1809,22 +1977,24 @@ Unsubscribes from data of the gravity sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.GRAVITY, callback1); - sensor.on(sensor.SensorId.GRAVITY, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.GRAVITY, callback1); - // Unsubscribe from all callbacks of the SensorId.GRAVITY type. - sensor.off(sensor.SensorId.GRAVITY); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.GRAVITY, callback1); + sensor.on(sensor.SensorId.GRAVITY, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.GRAVITY, callback1); + // Unsubscribe from all callbacks of the SensorId.GRAVITY type. + sensor.off(sensor.SensorId.GRAVITY); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1847,22 +2017,24 @@ Unsubscribes from data of the gyroscope sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.GYROSCOPE, callback1); - sensor.on(sensor.SensorId.GYROSCOPE, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.GYROSCOPE, callback1); - // Unsubscribe from all callbacks of the SensorId.GYROSCOPE type. - sensor.off(sensor.SensorId.GYROSCOPE); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.GYROSCOPE, callback1); + sensor.on(sensor.SensorId.GYROSCOPE, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.GYROSCOPE, callback1); + // Unsubscribe from all callbacks of the SensorId.GYROSCOPE type. + sensor.off(sensor.SensorId.GYROSCOPE); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1885,22 +2057,24 @@ off(type: SensorId.GYROSCOPE_UNCALIBRATED, callback?: Callback<GyroscopeUncal **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1); - sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1); - // Unsubscribe from all callbacks of the SensorId.GYROSCOPE_UNCALIBRATED type. - sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1); + sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1); + // Unsubscribe from all callbacks of the SensorId.GYROSCOPE_UNCALIBRATED type. + sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1921,22 +2095,24 @@ Unsubscribes from data of the Hall effect sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.HALL, callback1); - sensor.on(sensor.SensorId.HALL, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.HALL, callback1); - // Unsubscribe from all callbacks of the SensorId.HALL type. - sensor.off(sensor.SensorId.HALL); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.HALL, callback1); + sensor.on(sensor.SensorId.HALL, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.HALL, callback1); + // Unsubscribe from all callbacks of the SensorId.HALL type. + sensor.off(sensor.SensorId.HALL); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1959,22 +2135,24 @@ Unsubscribes from data of the heart rate sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.HEART_RATE, callback1); - sensor.on(sensor.SensorId.HEART_RATE, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.HEART_RATE, callback1); - // Unsubscribe from all callbacks of the SensorId.HEART_RATE type. - sensor.off(sensor.SensorId.HEART_RATE); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.HEART_RATE, callback1); + sensor.on(sensor.SensorId.HEART_RATE, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.HEART_RATE, callback1); + // Unsubscribe from all callbacks of the SensorId.HEART_RATE type. + sensor.off(sensor.SensorId.HEART_RATE); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -1995,22 +2173,24 @@ Unsubscribes from data of the humidity sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.HUMIDITY, callback1); - sensor.on(sensor.SensorId.HUMIDITY, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.HUMIDITY, callback1); - // Unsubscribe from all callbacks of the SensorId.HUMIDITY type. - sensor.off(sensor.SensorId.HUMIDITY); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.HUMIDITY, callback1); + sensor.on(sensor.SensorId.HUMIDITY, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.HUMIDITY, callback1); + // Unsubscribe from all callbacks of the SensorId.HUMIDITY type. + sensor.off(sensor.SensorId.HUMIDITY); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2033,22 +2213,24 @@ Unsubscribes from data of the linear acceleration sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback1); - sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback1); - // Unsubscribe from all callbacks of the SensorId.LINEAR_ACCELEROMETER type. - sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback1); + sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback1); + // Unsubscribe from all callbacks of the SensorId.LINEAR_ACCELEROMETER type. + sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2069,22 +2251,24 @@ Unsubscribes from data of the magnetic field sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback1); - sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback1); - // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD type. - sensor.off(sensor.SensorId.MAGNETIC_FIELD); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback1); + sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback1); + // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD type. + sensor.off(sensor.SensorId.MAGNETIC_FIELD); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2105,22 +2289,24 @@ Unsubscribes from data of the uncalibrated magnetic field sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1); - sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1); - // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD_UNCALIBRATED type. - sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1); + sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1); + // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD_UNCALIBRATED type. + sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2141,22 +2327,24 @@ Unsubscribes from data of the orientation sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.ORIENTATION, callback1); - sensor.on(sensor.SensorId.ORIENTATION, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.ORIENTATION, callback1); - // Unsubscribe from all callbacks of the SensorId.ORIENTATION type. - sensor.off(sensor.SensorId.ORIENTATION); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.ORIENTATION, callback1); + sensor.on(sensor.SensorId.ORIENTATION, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.ORIENTATION, callback1); + // Unsubscribe from all callbacks of the SensorId.ORIENTATION type. + sensor.off(sensor.SensorId.ORIENTATION); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2179,22 +2367,24 @@ Unsubscribes from data of the pedometer sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.PEDOMETER, callback1); - sensor.on(sensor.SensorId.PEDOMETER, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.PEDOMETER, callback1); - // Unsubscribe from all callbacks of the SensorId.PEDOMETER type. - sensor.off(sensor.SensorId.PEDOMETER); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.PEDOMETER, callback1); + sensor.on(sensor.SensorId.PEDOMETER, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.PEDOMETER, callback1); + // Unsubscribe from all callbacks of the SensorId.PEDOMETER type. + sensor.off(sensor.SensorId.PEDOMETER); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2217,22 +2407,24 @@ Unsubscribes from data of the pedometer detection sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback1); - sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback1); - // Unsubscribe from all callbacks of the SensorId.PEDOMETER_DETECTION type. - sensor.off(sensor.SensorId.PEDOMETER_DETECTION); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback1); + sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback1); + // Unsubscribe from all callbacks of the SensorId.PEDOMETER_DETECTION type. + sensor.off(sensor.SensorId.PEDOMETER_DETECTION); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2253,22 +2445,24 @@ Unsubscribes from data of the proximity sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.PROXIMITY, callback1); - sensor.on(sensor.SensorId.PROXIMITY, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.PROXIMITY, callback1); - // Unsubscribe from all callbacks of the SensorId.PROXIMITY type. - sensor.off(sensor.SensorId.PROXIMITY); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.PROXIMITY, callback1); + sensor.on(sensor.SensorId.PROXIMITY, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.PROXIMITY, callback1); + // Unsubscribe from all callbacks of the SensorId.PROXIMITY type. + sensor.off(sensor.SensorId.PROXIMITY); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2289,22 +2483,24 @@ Unsubscribes from data of the rotation vector sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.ROTATION_VECTOR, callback1); - sensor.on(sensor.SensorId.ROTATION_VECTOR, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.ROTATION_VECTOR, callback1); - // Unsubscribe from all callbacks of the SensorId.ROTATION_VECTOR type. - sensor.off(sensor.SensorId.ROTATION_VECTOR); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.ROTATION_VECTOR, callback1); + sensor.on(sensor.SensorId.ROTATION_VECTOR, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.ROTATION_VECTOR, callback1); + // Unsubscribe from all callbacks of the SensorId.ROTATION_VECTOR type. + sensor.off(sensor.SensorId.ROTATION_VECTOR); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2325,22 +2521,24 @@ Unsubscribes from data of the significant motion sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback1); - sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback1); - // Unsubscribe from all callbacks of the SensorId.SIGNIFICANT_MOTION type. - sensor.off(sensor.SensorId.SIGNIFICANT_MOTION); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback1); + sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback1); + // Unsubscribe from all callbacks of the SensorId.SIGNIFICANT_MOTION type. + sensor.off(sensor.SensorId.SIGNIFICANT_MOTION); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2361,22 +2559,24 @@ Unsubscribes from data of the wear detection sensor. **Example** -```js +```ts function callback1(data) { - console.info('Callback1 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); } + function callback2(data) { - console.info('Callback2 data: ' + JSON.stringify(data)); + console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); } + try { - sensor.on(sensor.SensorId.WEAR_DETECTION, callback1); - sensor.on(sensor.SensorId.WEAR_DETECTION, callback2); - // Unsubscribe from callback1. - sensor.off(sensor.SensorId.WEAR_DETECTION, callback1); - // Unsubscribe from all callbacks of the SensorId.WEAR_DETECTION type. - sensor.off(sensor.SensorId.WEAR_DETECTION); -} catch (err) { - console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message); + sensor.on(sensor.SensorId.WEAR_DETECTION, callback1); + sensor.on(sensor.SensorId.WEAR_DETECTION, callback2); + // Unsubscribe from callback1. + sensor.off(sensor.SensorId.WEAR_DETECTION, callback1); + // Unsubscribe from all callbacks of the SensorId.WEAR_DETECTION type. + sensor.off(sensor.SensorId.WEAR_DETECTION); +} catch (error) { + console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2406,23 +2606,23 @@ For details about the following error codes, see [Error Codes of sensor.getGeoma **Example** -```js +```ts try { - sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000, function (err, data) { - if (err) { - console.error('Get geomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - console.info("GeomagneticInfo x" + data.x); - console.info("GeomagneticInfo y" + data.y); - console.info("GeomagneticInfo z" + data.z); - console.info("GeomagneticInfo geomagneticDip" + data.geomagneticDip); - console.info("GeomagneticInfo deflectionAngle" + data.deflectionAngle); - console.info("GeomagneticInfo levelIntensity" + data.levelIntensity); - console.info("GeomagneticInfo totalIntensity" + data.totalIntensity); - }); -} catch (err) { - console.error('Get geomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message); + sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000, function (err, data) { + if (err) { + console.error(`Failed to get geomagneticInfo. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info("Succeeded in getting geomagneticInfo x" + data.x); + console.info("Succeeded in getting geomagneticInfo y" + data.y); + console.info("Succeeded in getting geomagneticInfo z" + data.z); + console.info("Succeeded in getting geomagneticInfo geomagneticDip" + data.geomagneticDip); + console.info("Succeeded in getting geomagneticInfo deflectionAngle" + data.deflectionAngle); + console.info("Succeeded in getting geomagneticInfo levelIntensity" + data.levelIntensity); + console.info("Succeeded in getting geomagneticInfo totalIntensity" + data.totalIntensity); + }); +} catch (error) { + console.error(`Failed to get geomagneticInfo. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2457,22 +2657,22 @@ For details about the following error codes, see [Error Codes of sensor.getGeoma **Example** -```js +```ts try { - const promise = sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000); - promise.then((data) => { - console.info("GeomagneticInfo x" + data.x); - console.info("GeomagneticInfo y" + data.y); - console.info("GeomagneticInfo z" + data.z); - console.info("GeomagneticInfo geomagneticDip" + data.geomagneticDip); - console.info("GeomagneticInfo deflectionAngle" + data.deflectionAngle); - console.info("GeomagneticInfo levelIntensity" + data.levelIntensity); - console.info("GeomagneticInfo totalIntensity" + data.totalIntensity); - }, (err)=>{ - console.error('Get geomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('Get geomagneticInfo. Error code: ' + err.code + '; message: ' + err.message); + const promise = sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000); + promise.then((data) => { + console.info("Succeeded in getting geomagneticInfo x" + data.x); + console.info("Succeeded in getting geomagneticInfo y" + data.y); + console.info("Succeeded in getting geomagneticInfo z" + data.z); + console.info("Succeeded in getting geomagneticInfo geomagneticDip" + data.geomagneticDip); + console.info("Succeeded in getting geomagneticInfo deflectionAngle" + data.deflectionAngle); + console.info("Succeeded in getting geomagneticInfo levelIntensity" + data.levelIntensity); + console.info("Succeeded in getting geomagneticInfo totalIntensity" + data.totalIntensity); + }, (err) => { + console.error(`Failed to get geomagneticInfo. Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to get geomagneticInfo. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2502,19 +2702,19 @@ For details about the following error codes, see [Error Codes of sensor.getDevic **Example** -```js +```ts try { - let seaPressure = 1013.2; - let currentPressure = 1500.0; - sensor.getDeviceAltitude(seaPressure, currentPressure, function (err, data) { - if (err) { - console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - console.info('altitude: ' + data); - }); -} catch (err) { - console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message); + let seaPressure = 1013.2; + let currentPressure = 1500.0; + sensor.getDeviceAltitude(seaPressure, currentPressure, function (err, data) { + if (err) { + console.error(`Failed to get altitude. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info('Succeeded in getting altitude: ' + data); + }); +} catch (error) { + console.error(`Failed to get altitude. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2549,18 +2749,18 @@ For details about the following error codes, see [Error Codes of sensor.getDevic **Example** -```js +```ts try { - let seaPressure = 1013.2; - let currentPressure = 1500.0; - const promise = sensor.getDeviceAltitude(seaPressure, currentPressure); - promise.then((data) => { - console.info('sensor_getDeviceAltitude_Promise success', data); - }, (err) => { - console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message); + let seaPressure = 1013.2; + let currentPressure = 1500.0; + const promise = sensor.getDeviceAltitude(seaPressure, currentPressure); + promise.then((data) => { + console.info('Succeeded in getting sensor_getDeviceAltitude_Promise', data); + }, (err) => { + console.error(`Failed to get altitude. Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to get altitude. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2589,23 +2789,23 @@ For details about the following error codes, see [Error Codes of sensor.getIncli **Example** -```js +```ts try { - // inclinationMatrix can be 3*3 or 4*4. - let inclinationMatrix = [ - 1, 0, 0, - 0, 1, 0, - 0, 0, 1 - ] - sensor.getInclination(inclinationMatrix, function (err, data) { - if (err) { - console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - console.info('Inclination: ' + data); - }) -} catch (err) { - console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message); + // inclinationMatrix can be 3*3 or 4*4. + let inclinationMatrix = [ + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + ] + sensor.getInclination(inclinationMatrix, function (err, data) { + if (err) { + console.error(`Failed to get inclination. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info('Succeeded in getting inclination: ' + data); + }) +} catch (error) { + console.error(`Failed to get inclination. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2639,22 +2839,22 @@ For details about the following error codes, see [Error Codes of sensor.getIncli **Example** -```js +```ts try { - // inclinationMatrix can be 3*3 or 4*4. - let inclinationMatrix = [ - 1, 0, 0, - 0, 1, 0, - 0, 0, 1 - ] - const promise = sensor.getInclination(inclinationMatrix); - promise.then((data) => { - console.info('Inclination: ' + data); - }, (err) => { - console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message); + // inclinationMatrix can be 3*3 or 4*4. + let inclinationMatrix = [ + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + ] + const promise = sensor.getInclination(inclinationMatrix); + promise.then((data) => { + console.info('Succeeded in getting inclination: ' + data); + }, (err) => { + console.error(`Failed to get inclination. Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to get inclination. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2685,33 +2885,33 @@ For details about the following error codes, see [Error Codes of sensor.getAngle **Example** -```js +```ts try { - // The rotation matrix can be 3*3 or 4*4. - let currentRotationMatrix = [ - 1, 0, 0, - 0, 1, 0, - 0, 0, 1 - ]; - let preRotationMatrix = [ - 1, 0, 0, - 0, 0.87, -0.50, - 0, 0.50, 0.87 - ]; - sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix, function (err, data) { - if (err) { - console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - if (data.length < 3) { - console.error("Get angle variation failed, length" + data.length); - } - console.info("Z: " + data[0]); - console.info("X: " + data[1]); - console.info("Y : " + data[2]); - }) -} catch (err) { - console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message); + // The rotation matrix can be 3*3 or 4*4. + let currentRotationMatrix = [ + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + ]; + let preRotationMatrix = [ + 1, 0, 0, + 0, 0.87, -0.50, + 0, 0.50, 0.87 + ]; + sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix, function (err, data) { + if (err) { + console.error(`Failed to get angle variation. Code: ${err.code}, message: ${err.message}`); + return; + } + if (data.length < 3) { + console.error("Failed to get angle variation, length" + data.length); + } + console.info("Z: " + data[0]); + console.info("X: " + data[1]); + console.info("Y : " + data[2]); + }) +} catch (error) { + console.error(`Failed to get angle variation. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2746,32 +2946,32 @@ For details about the following error codes, see [Error Codes of sensor.getAngle **Example** -```js +```ts try { - // The rotation matrix can be 3*3 or 4*4. - let currentRotationMatrix = [ - 1, 0, 0, - 0, 1, 0, - 0, 0, 1 - ]; - let preRotationMatrix = [ - 1, 0, 0, - 0, 0.87, -0.50, - 0, 0.50, 0.87 - ]; - const promise = sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix); - promise.then((data) => { - if (data.length < 3) { - console.error("Get angle variation failed, length" + data.length); - } - console.info("Z: " + data[0]); - console.info("X: " + data[1]); - console.info("Y : " + data[2]); - }, (err) => { - console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message); + // The rotation matrix can be 3*3 or 4*4. + let currentRotationMatrix = [ + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + ]; + let preRotationMatrix = [ + 1, 0, 0, + 0, 0.87, -0.50, + 0, 0.50, 0.87 + ]; + const promise = sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix); + promise.then((data) => { + if (data.length < 3) { + console.error("Failed to get angle variation, length" + data.length); + } + console.info("Z: " + data[0]); + console.info("X: " + data[1]); + console.info("Y : " + data[2]); + }, (err) => { + console.error(`Failed to get angle variation. Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to get angle variation. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2800,20 +3000,20 @@ For details about the following error codes, see [Error Codes of sensor.getRotat **Example** -```js +```ts try { - let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; - sensor.getRotationMatrix(rotationVector, function (err, data) { - if (err) { - console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - for (var i = 0; i < data.length; i++) { - console.info('data[' + i + ']: ' + data[i]); - } - }) -} catch (err) { - console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); + let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; + sensor.getRotationMatrix(rotationVector, function (err, data) { + if (err) { + console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`); + return; + } + for (var i = 0; i < data.length; i++) { + console.info('Succeeded in getting data[' + i + ']: ' + data[i]); + } + }) +} catch (error) { + console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2847,19 +3047,19 @@ For details about the following error codes, see [Error Codes of sensor.getRotat **Example** -```js +```ts try { - let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; - const promise = sensor.getRotationMatrix(rotationVector); - promise.then((data) => { - for (var i = 0; i < data.length; i++) { - console.info('data[' + i + ']: ' + data[i]); - } - }, (err) => { - console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); + let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; + const promise = sensor.getRotationMatrix(rotationVector); + promise.then((data) => { + for (var i = 0; i < data.length; i++) { + console.info('Succeeded in getting data[' + i + ']: ' + data[i]); + } + }, (err) => { + console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2890,24 +3090,24 @@ For details about the following error codes, see [Error Codes of sensor.transfor **Example** -```js +```ts try { - let rotationMatrix = [ - 1, 0, 0, - 0, 0.87, -0.50, - 0, 0.50, 0.87 - ]; - sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 }, function (err, data) { - if (err) { - console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - for (var i = 0; i < data.length; i++) { - console.info('data[' + i + '] = ' + data[i]); - } - }) -} catch (err) { - console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); + let rotationMatrix = [ + 1, 0, 0, + 0, 0.87, -0.50, + 0, 0.50, 0.87 + ]; + sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 }, function (err, data) { + if (err) { + console.error(`Failed to transform rotationMatrix. Code: ${err.code}, message: ${err.message}`); + return; + } + for (var i = 0; i < data.length; i++) { + console.info('Succeeded in getting data[' + i + '] = ' + data[i]); + } + }) +} catch (error) { + console.error(`Failed to transform rotationMatrix. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2942,23 +3142,23 @@ For details about the following error codes, see [Error Codes of sensor.transfor **Example** -```js +```ts try { - let rotationMatrix = [ - 1, 0, 0, - 0, 0.87, -0.50, - 0, 0.50, 0.87 - ]; - const promise = sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 }); - promise.then((data) => { - for (var i = 0; i < data.length; i++) { - console.info('data[' + i + ']: ' + data[i]); - } - }, (err) => { - console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); + let rotationMatrix = [ + 1, 0, 0, + 0, 0.87, -0.50, + 0, 0.50, 0.87 + ]; + const promise = sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 }); + promise.then((data) => { + for (var i = 0; i < data.length; i++) { + console.info('Succeeded in getting data[' + i + ']: ' + data[i]); + } + }, (err) => { + console.error(`Failed to transform rotationMatrix. Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to transform rotationMatrix. Code: ${error.code}, message: ${error.message}`); } ``` @@ -2987,20 +3187,20 @@ For details about the following error codes, see [Error Codes of sensor.getQuate **Example** -```js +```ts try { - let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; - sensor.getQuaternion(rotationVector, function (err, data) { - if (err) { - console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - for (var i = 0; i < data.length; i++) { - console.info('data[' + i + ']: ' + data[i]); - } - }) -} catch (err) { - console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message); + let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; + sensor.getQuaternion(rotationVector, function (err, data) { + if (err) { + console.error(`Failed to get quaternion. Code: ${err.code}, message: ${err.message}`); + return; + } + for (var i = 0; i < data.length; i++) { + console.info('Succeeded in getting data[' + i + ']: ' + data[i]); + } + }) +} catch (error) { + console.error(`Failed to get quaternion. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3034,19 +3234,19 @@ For details about the following error codes, see [Error Codes of sensor.getQuate **Example** -```js +```ts try { let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; const promise = sensor.getQuaternion(rotationVector); promise.then((data) => { for (var i = 0; i < data.length; i++) { - console.info('data[' + i + ']: ' + data[i]); + console.info('Succeeded in getting data[' + i + ']: ' + data[i]); } }, (err) => { - console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message); + console.error(`Failed to get quaternion. Code: ${err.code}, message: ${err.message}`); }); -} catch (err) { - console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message); +} catch (error) { + console.error(`Failed to get quaternion. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3075,27 +3275,27 @@ For details about the following error codes, see [Error Codes of sensor.getOrien **Example** -```js +```ts try { - let preRotationMatrix = [ - 1, 0, 0, - 0, 0.87, -0.50, - 0, 0.50, 0.87 - ]; - sensor.getOrientation(preRotationMatrix, function (err, data) { - if (err) { - console.error('Get orientation failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - if (data.length < 3) { - console.error("Get orientation failed, length" + data.length); - } - console.info("Z: " + data[0]); - console.info("X: " + data[1]); - console.info("Y : " + data[2]); - }) -} catch (err) { - console.error('Get orientation failed. Error code: ' + err.code + '; message: ' + err.message); + let preRotationMatrix = [ + 1, 0, 0, + 0, 0.87, -0.50, + 0, 0.50, 0.87 + ]; + sensor.getOrientation(preRotationMatrix, function (err, data) { + if (err) { + console.error(`Failed to get orientation. Code: ${err.code}, message: ${err.message}`); + return; + } + if (data.length < 3) { + console.error("Failed to get orientation, length" + data.length); + } + console.info("Succeeded in getting data. Z: " + data[0]); + console.info("Succeeded in getting data. X: " + data[1]); + console.info("Succeeded in getting data. Y: " + data[2]); + }) +} catch (error) { + console.error(`Failed to get orientation. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3129,23 +3329,23 @@ For details about the following error codes, see [Error Codes of sensor.getOrien **Example** -```js +```ts try { - let preRotationMatrix = [ - 1, 0, 0, - 0, 0.87, -0.50, - 0, 0.50, 0.87 - ]; - const promise = sensor.getOrientation(preRotationMatrix); - promise.then((data) => { - for (var i = 0; i < data.length; i++) { - console.info('data[' + i + ']: ' + data[i]); - } - }, (err) => { - console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message); + let preRotationMatrix = [ + 1, 0, 0, + 0, 0.87, -0.50, + 0, 0.50, 0.87 + ]; + const promise = sensor.getOrientation(preRotationMatrix); + promise.then((data) => { + for (var i = 0; i < data.length; i++) { + console.info('Succeeded in getting data[' + i + ']: ' + data[i]); + } + }, (err) => { + console.error(`Failed to getOrientatin. Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to getOrientatin Code: ${error.code}, message: ${error.message}`); } ``` @@ -3175,19 +3375,19 @@ For details about the following error codes, see [Error Codes of sensor.getRotat **Example** -```js +```ts try { - let gravity = [-0.27775216, 0.5351276, 9.788099]; - let geomagnetic = [210.87253, -78.6096, -111.44444]; - sensor.getRotationMatrix(gravity, geomagnetic, function (err, data) { - if (err) { - console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - console.info('RotationMatrix' + JSON.stringify(data)); - }) -} catch (err) { - console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); + let gravity = [-0.27775216, 0.5351276, 9.788099]; + let geomagnetic = [210.87253, -78.6096, -111.44444]; + sensor.getRotationMatrix(gravity, geomagnetic, function (err, data) { + if (err) { + console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data)); + }) +} catch (error) { +console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3222,18 +3422,18 @@ For details about the following error codes, see [Error Codes of sensor.getRotat **Example** -```js +```ts try { - let gravity = [-0.27775216, 0.5351276, 9.788099]; - let geomagnetic = [210.87253, -78.6096, -111.44444]; - const promise = sensor.getRotationMatrix(gravity, geomagnetic); - promise.then((data) => { - console.info('RotationMatrix' + JSON.stringify(data)); - }, (err) => { - console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message); + let gravity = [-0.27775216, 0.5351276, 9.788099]; + let geomagnetic = [210.87253, -78.6096, -111.44444]; + const promise = sensor.getRotationMatrix(gravity, geomagnetic); + promise.then((data) => { + console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data)); + }, (err) => { + console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3261,19 +3461,19 @@ For details about the following error codes, see [Error Codes of sensor.getSenso **Example** -```js +```ts try { - sensor.getSensorList((err, data) => { - if (err) { - console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - for (var i = 0; i < data.length; i++) { - console.info('data[' + i + ']: ' + JSON.stringify(data[i])); - } - }); -} catch (err) { - console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message); + sensor.getSensorList((err, data) => { + if (err) { + console.error(`Failed to get sensorList. Code: ${err.code}, message: ${err.message}`); + return; + } + for (var i = 0; i < data.length; i++) { + console.info('Succeeded in getting data[' + i + ']: ' + JSON.stringify(data[i])); + } + }); +} catch (error) { + console.error(`Failed to get sensorList. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3301,17 +3501,17 @@ For details about the following error codes, see [Error Codes of sensor.getSenso **Example** -```js +```ts try { - sensor.getSensorList().then((data) => { - for (var i = 0; i < data.length; i++) { - console.info('data[' + i + ']: ' + JSON.stringify(data[i])); - } - }, (err) => { - console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message); + sensor.getSensorList().then((data) => { + for (var i = 0; i < data.length; i++) { + console.info('Succeeded in getting data[' + i + ']: ' + JSON.stringify(data[i])); + } + }, (err) => { + console.error(`Failed to get sensorList. Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to get sensorList. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3340,17 +3540,17 @@ For details about the following error codes, see [Error Codes of sensor.getSingl **Example** -```js +```ts try { - sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER, (err, data) => { - if (err) { - console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - console.info('Sensor: ' + JSON.stringify(data)); - }); -} catch (err) { - console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message); + sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER, (err, data) => { + if (err) { + console.error(`Failed to get singleSensor. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info('Succeeded in getting sensor: ' + JSON.stringify(data)); + }); +} catch (error) { + console.error(`Failed to get singleSensor. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3384,15 +3584,15 @@ For details about the following error codes, see [Error Codes of sensor.getSingl **Example** -```js +```ts try { - sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER).then((data) => { - console.info('Sensor: ' + JSON.stringify(data)); - }, (err) => { - console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message); - }); -} catch (err) { - console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message); + sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER).then((data) => { + console.info('Succeeded in getting sensor: ' + JSON.stringify(data)); + }, (err) => { + console.error(`Failed to get singleSensor . Code: ${err.code}, message: ${err.message}`); + }); +} catch (error) { + console.error(`Failed to get singleSensor . Code: ${error.code}, message: ${error.message}`); } ``` @@ -3457,7 +3657,6 @@ Enumerates the sensor types. | 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. @@ -3487,6 +3686,33 @@ Describes the sensor information. | precision | number | Yes | Yes | Precision of the sensor. | | power | number | Yes | Yes | Power of the sensor. | +## ColorResponse10+ + +Describes the color sensor data. It extends from [Response](#response). + +**System capability**: SystemCapability.Sensors.Sensor + +**System API**: This is a system API. + + +| Name | Type | Readable| Writable| Description | +| ---------------- | ------ | ---- | ---- | ----------------------------- | +| lightIntensity | number | Yes | Yes | Intensity of light, in lux.| +| colorTemperature | number | Yes | Yes | Color temperature, in Kelvin. | + +## SarResponse10+ + +Describes the SAR sensor data. It extends from [Response](#response). + +**System capability**: SystemCapability.Sensors.Sensor + +**System API**: This is a system API. + + +| Name | Type | Readable| Writable| Description | +| --------------- | ------ | ---- | ---- | ------------------------------- | +| absorptionRatio | number | Yes | Yes | Absorption ratio, in W/kg.| + ## AccelerometerResponse Describes the acceleration sensor data. It extends from [Response](#response). @@ -3851,19 +4077,19 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.AC | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**. | | callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){ - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 100000000} - ); - ``` +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); +}, + { interval: 100000000 } +); +``` ### LINEAR_ACCELERATION(deprecated) @@ -3883,7 +4109,7 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.LI | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.| | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | ### ACCELEROMETER_UNCALIBRATED(deprecated) @@ -3903,21 +4129,22 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.AC | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.| | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | - -**Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){ - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }, - {interval: 100000000} - ); - ``` +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | + +**Example** + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); +}, + { interval: 100000000 } +); +``` ### GRAVITY(deprecated) @@ -3935,19 +4162,19 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.GR | -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_GRAVITY | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**. | | callback | Callback<[GravityResponse](#gravityresponse)> | Yes | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){ - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 100000000} - ); - ``` +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); +}, + { interval: 100000000 } +); +``` ### GYROSCOPE(deprecated) @@ -3967,18 +4194,19 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.GY | -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**. | | callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){ - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 100000000} - ); - ``` + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); +}, + { interval: 100000000 } +); +``` ### GYROSCOPE_UNCALIBRATED(deprecated) @@ -3998,21 +4226,22 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.GY | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.| | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | - -**Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){ - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }, - {interval: 100000000} - ); - ``` +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | + +**Example** + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); +}, + { interval: 100000000 } +); +``` ### SIGNIFICANT_MOTION(deprecated) @@ -4030,16 +4259,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.SI | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.| | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){ - console.info('Scalar data: ' + data.scalar); - }, - {interval: 100000000} - ); - ``` + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function (data) { + console.info('Succeeded in invoking on. Scalar data: ' + data.scalar); +}, + { interval: 100000000 } +); +``` ### PEDOMETER_DETECTION(deprecated) @@ -4059,16 +4289,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.PE | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.| | callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){ - console.info('Scalar data: ' + data.scalar); - }, - {interval: 100000000} - ); - ``` + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function (data) { + console.info('Succeeded in invoking on. Scalar data: ' + data.scalar); +}, + { interval: 100000000 } +); +``` ### PEDOMETER(deprecated) @@ -4088,16 +4319,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.PE | -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**. | | callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){ - console.info('Steps: ' + data.steps); - }, - {interval: 100000000} - ); - ``` + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function (data) { + console.info('Succeeded in invoking on. Steps: ' + data.steps); +}, + { interval: 100000000 } +); +``` ### AMBIENT_TEMPERATURE(deprecated) @@ -4115,17 +4347,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.AM | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.| | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){ - console.info('Temperature: ' + data.temperature); - }, - {interval: 100000000} - ); - ``` +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function (data) { + console.info('Succeeded in invoking on. Temperature: ' + data.temperature); +}, + { interval: 100000000 } +); +``` ### MAGNETIC_FIELD(deprecated) @@ -4143,19 +4375,19 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.MA | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. | | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){ - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - }, - {interval: 100000000} - ); - ``` +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); +}, + { interval: 100000000 } +); +``` ### MAGNETIC_FIELD_UNCALIBRATED(deprecated) @@ -4173,21 +4405,22 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.MA | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.| | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | - -**Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){ - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - }, - {interval: 100000000} - ); - ``` +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | + +**Example** + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); +}, + { interval: 100000000 } +); +``` ### PROXIMITY(deprecated) @@ -4205,16 +4438,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.PR | -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_PROXIMITY | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**. | | callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){ - console.info('Distance: ' + data.distance); - }, - {interval: 100000000} - ); - ``` + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function (data) { + console.info('Succeeded in invoking on. Distance: ' + data.distance); +}, + { interval: 100000000 } +); +``` ### HUMIDITY(deprecated) @@ -4232,17 +4466,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.HU | -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_HUMIDITY | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**. | | callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){ - console.info('Humidity: ' + data.humidity); - }, - {interval: 100000000} - ); - ``` +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function (data) { + console.info('Succeeded in invoking on. Humidity: ' + data.humidity); +}, + { interval: 100000000 } +); +``` ### BAROMETER(deprecated) @@ -4260,17 +4494,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.BA | -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_BAROMETER | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**. | | callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){ - console.info('Atmospheric pressure: ' + data.pressure); - }, - {interval: 100000000} - ); - ``` +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function (data) { + console.info('Succeeded in invoking on. Atmospheric pressure: ' + data.pressure); +}, + { interval: 100000000 } +); +``` ### HALL(deprecated) @@ -4288,16 +4522,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.HA | -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_HALL | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**. | | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){ - console.info('Status: ' + data.status); - }, - {interval: 100000000} - ); - ``` + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, function (data) { + console.info('Succeeded in invoking on. Status: ' + data.status); +}, + { interval: 100000000 } +); +``` ### AMBIENT_LIGHT(deprecated) @@ -4315,17 +4550,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.AM | -------- | ------------------------------------------------------ | ---- | ----------------------------------------------------------- | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**. | | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){ - console.info(' Illumination: ' + data.intensity); - }, - {interval: 100000000} - ); - ``` +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function (data) { + console.info('Succeeded in invoking on. Illumination: ' + data.intensity); +}, + { interval: 100000000 } +); +``` ### ORIENTATION(deprecated) @@ -4343,18 +4578,19 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.OR | -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_ORIENTATION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**. | | callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){ - console.info('The device rotates at an angle around the X axis: ' + data.beta); - console.info('The device rotates at an angle around the Y axis: ' + data.gamma); - console.info('The device rotates at an angle around the Z axis: ' + data.alpha); - }, - {interval: 100000000} - ); - ``` + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function (data) { + console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta); + console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma); + console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha); +}, + { interval: 100000000 } +); +``` ### HEART_RATE(deprecated) @@ -4374,7 +4610,7 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.HE | -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_HEART_RATE | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**. | | callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | Callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.| -| options | [Options](#options) | No | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | ### ROTATION_VECTOR(deprecated) @@ -4392,19 +4628,20 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.RO | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.| | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){ - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('Scalar quantity: ' + data.w); - }, - {interval: 100000000} - ); - ``` + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function (data) { + console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking on. Scalar quantity: ' + data.w); +}, + { interval: 100000000 } +); +``` ### WEAR_DETECTION(deprecated) @@ -4422,16 +4659,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.on.WE | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | type | [SensorType](#sensortype).SENSOR_TYPE_ID_WEAR_DETECTION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. | | callback | Callback<[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 | List of optional parameters. Currently, this parameter can be used to set the data reporting frequency. The default value is 200,000,000 ns. | +| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | **Example** - ```js - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){ - console.info('Wear status: ' + data.value); - }, - {interval: 100000000} - ); - ``` + +```ts +sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function (data) { + console.info('Succeeded in invoking on. Wear status: ' + data.value); +}, + { interval: 100000000 } +); +``` ## sensor.once(deprecated) @@ -4455,14 +4693,14 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){ - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); +}); +``` ### LINEAR_ACCELERATION(deprecated) @@ -4503,17 +4741,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[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(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); +}); +``` ### GRAVITY(deprecated) @@ -4533,14 +4771,14 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[GravityResponse](#gravityresponse)> | Yes | One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + }); +``` ### GYROSCOPE(deprecated) @@ -4562,14 +4800,14 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); +}); +``` ### GYROSCOPE_UNCALIBRATED(deprecated) @@ -4591,17 +4829,16 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes | One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - } - ); - ``` +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); +}); +``` ### SIGNIFICANT_MOTION(deprecated) @@ -4621,12 +4858,12 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes | One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) { - console.info('Scalar data: ' + data.scalar); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function (data) { + console.info('Succeeded in invoking once. Scalar data: ' + data.scalar); +}); +``` ### PEDOMETER_DETECTION(deprecated) @@ -4648,12 +4885,12 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) { - console.info('Scalar data: ' + data.scalar); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function (data) { + console.info('Succeeded in invoking once. Scalar data: ' + data.scalar); +}); +``` ### PEDOMETER(deprecated) @@ -4675,12 +4912,12 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) { - console.info('Steps: ' + data.steps); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function (data) { + console.info('Succeeded in invoking once. Steps: ' + data.steps); +}); +``` ### AMBIENT_TEMPERATURE(deprecated) @@ -4700,12 +4937,12 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes | One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) { - console.info('Temperature: ' + data.temperature); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function (data) { + console.info('Succeeded in invoking once. Temperature: ' + data.temperature); +}); +``` ### MAGNETIC_FIELD(deprecated) @@ -4725,14 +4962,14 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes | One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); +}); +``` ### MAGNETIC_FIELD_UNCALIBRATED(deprecated) @@ -4752,17 +4989,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[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** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); +}); +``` ### PROXIMITY(deprecated) @@ -4782,12 +5019,13 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) { - console.info('Distance: ' + data.distance); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function (data) { + console.info('Succeeded in invoking once. Distance: ' + data.distance); +} +); +``` ### HUMIDITY(deprecated) @@ -4807,12 +5045,12 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) { - console.info('Humidity: ' + data.humidity); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function (data) { + console.info('Succeeded in invoking once. Humidity: ' + data.humidity); +}); +``` ### BAROMETER(deprecated) @@ -4832,12 +5070,12 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) { - console.info('Atmospheric pressure: ' + data.pressure); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function (data) { + console.info('Succeeded in invoking once. Atmospheric pressure: ' + data.pressure); +}); +``` ### HALL(deprecated) @@ -4857,12 +5095,12 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[HallResponse](#hallresponse)> | Yes | One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) { - console.info('Status: ' + data.status); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function (data) { + console.info('Succeeded in invoking once. Status: ' + data.status); +}); +``` ### AMBIENT_LIGHT(deprecated) @@ -4883,12 +5121,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) { - console.info(' Illumination: ' + data.intensity); - } - ); - ``` +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function (data) { + console.info('Succeeded in invoking once. invoking once. Illumination: ' + data.intensity); +}); +``` ### ORIENTATION(deprecated) @@ -4908,14 +5145,14 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) { - console.info('The device rotates at an angle around the X axis: ' + data.beta); - console.info('The device rotates at an angle around the Y axis: ' + data.gamma); - console.info('The device rotates at an angle around the Z axis: ' + data.alpha); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function (data) { + console.info('Succeeded in invoking the device rotateing at an angle around the X axis: ' + data.beta); + console.info('Succeeded in invoking the device rotateing at an angle around the Y axis: ' + data.gamma); + console.info('Succeeded in invoking the device rotateing at an angle around the Z axis: ' + data.alpha); +}); +``` ### ROTATION_VECTOR(deprecated) @@ -4935,15 +5172,15 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes | One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('Scalar quantity: ' + data.w); - } - ); - ``` + +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function (data) { + console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking once. Scalar quantity: ' + data.w); +}); +``` ### HEART_RATE(deprecated) @@ -4982,12 +5219,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.once. | callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes | One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.| **Example** - ```js - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) { - console.info("Wear status: "+ data.value); - } - ); - ``` +```ts +sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function (data) { + console.info("Succeeded in invoking once. Wear status: " + data.value); +}); +``` ## sensor.off(deprecated) @@ -5012,12 +5248,13 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.A **Example** -```js +```ts function callback(data) { - console.info('x-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback); ``` @@ -5042,15 +5279,16 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.A **Example** -```js +```ts function callback(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); + console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback); ``` @@ -5073,10 +5311,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.A **Example** -```js +```ts function callback(data) { - console.info(' Illumination: ' + data.intensity); + console.info('Succeeded in invoking off. Illumination: ' + data.intensity); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback); ``` @@ -5099,10 +5338,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.A **Example** -```js +```ts function callback(data) { - console.info('Temperature: ' + data.temperature); + console.info('Succeeded in invoking off. Temperature: ' + data.temperature); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback); ``` @@ -5125,10 +5365,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.B **Example** -```js +```ts function callback(data) { - console.info('Atmospheric pressure: ' + data.pressure); + console.info('Succeeded in invoking off. Atmospheric pressure: ' + data.pressure); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback); ``` @@ -5151,13 +5392,14 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.G **Example** -```js +```ts function callback(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); } -sensor.off( sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + +sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); ``` ### GYROSCOPE(deprecated) @@ -5181,12 +5423,13 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.G **Example** -```js +```ts function callback(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback); ``` @@ -5211,12 +5454,13 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.G **Example** -```js +```ts function callback(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback); ``` @@ -5239,10 +5483,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.H **Example** -```js +```ts function callback(data) { - console.info('Status: ' + data.status); + console.info('Succeeded in invoking off. Status: ' + data.status); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback); ``` @@ -5284,10 +5529,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.H **Example** -```js +```ts function callback(data) { - console.info('Humidity: ' + data.humidity); + console.info('Succeeded in invoking off. Humidity: ' + data.humidity); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback); ``` @@ -5329,12 +5575,13 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.M **Example** -```js +```ts function callback(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback); ``` @@ -5357,15 +5604,16 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.M **Example** -```js +```ts function callback(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('X-coordinate bias: ' + data.biasX); - console.info('Y-coordinate bias: ' + data.biasY); - console.info('Z-coordinate bias: ' + data.biasZ); + console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX); + console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY); + console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback); ``` @@ -5388,12 +5636,13 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.O **Example** -```js +```ts function callback(data) { - console.info('The device rotates at an angle around the X axis: ' + data.beta); - console.info('The device rotates at an angle around the Y axis: ' + data.gamma); - console.info('The device rotates at an angle around the Z axis: ' + data.alpha); + console.info('Succeeded in invoking off. The device rotates at an angle around the X axis: ' + data.beta); + console.info('Succeeded in invoking off. The device rotates at an angle around the Y axis: ' + data.gamma); + console.info('Succeeded in invoking off. The device rotates at an angle around the Z axis: ' + data.alpha); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); ``` @@ -5418,10 +5667,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.P **Example** -```js +```ts function callback(data) { - console.info('Steps: ' + data.steps); + console.info('Succeeded in invoking off. Steps: ' + data.steps); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback); ``` @@ -5446,10 +5696,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.P **Example** -```js +```ts function callback(data) { - console.info('Scalar data: ' + data.scalar); + console.info('Succeeded in invoking off. Scalar data: ' + data.scalar); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback); ``` @@ -5472,10 +5723,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.P **Example** -```js +```ts function callback(data) { - console.info('Distance: ' + data.distance); + console.info('Succeeded in invoking off. Distance: ' + data.distance); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback); ``` @@ -5498,13 +5750,14 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.R **Example** -```js +```ts function callback(data) { - console.info('X-coordinate component: ' + data.x); - console.info('Y-coordinate component: ' + data.y); - console.info('Z-coordinate component: ' + data.z); - console.info('Scalar quantity: ' + data.w); + console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); + console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); + console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); + console.info('Succeeded in invoking off. Scalar quantity: ' + data.w); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback); ``` @@ -5527,10 +5780,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.S **Example** -```js +```ts function callback(data) { - console.info('Scalar data: ' + data.scalar); + console.info('Succeeded in invoking off. Scalar data: ' + data.scalar); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback); ``` @@ -5553,10 +5807,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.off.W **Example** -```js +```ts function accCallback(data) { - console.info('Wear status: ' + data.value); + console.info('Succeeded in invoking off. Wear status: ' + data.value); } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback); ``` @@ -5580,17 +5835,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.trans **Example** -```js -sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) { - if (err) { - console.error("Operation failed. Error code: " + err.code + ", message: " + err.message); - return; - } - console.info("Operation succeeded. Data obtained: " + data); - for (var i=0; i < data.length; i++) { - console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]); - } - }) +```ts +sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 }, function (err, data) { + if (err) { + console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info("Succeeded in starting Operation. Data obtained: " + data); + for (var i = 0; i < data.length; i++) { + console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]); + } +}) ``` ## sensor.transformCoordinateSystem(deprecated) @@ -5617,15 +5872,15 @@ This API is deprecated since API version 9. You are advised to use [sensor.trans **Example** -```js -const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}); - promise.then((data) => { - console.info("Operation succeeded."); - for (var i=0; i < data.length; i++) { - console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]); - } - }).catch((err) => { - console.info("Operation failed"); +```ts +const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 }); +promise.then((data) => { + console.info("Succeeded in starting Operation"); + for (var i = 0; i < data.length; i++) { + console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]); + } +}).catch((err) => { + console.error(`Failed to operate.`); }) ``` @@ -5648,15 +5903,16 @@ This API is deprecated since API version 9. You are advised to use [sensor.getGe | callback | AsyncCallback<[GeomagneticResponse](#geomagneticresponse)> | Yes | Callback used to return the geomagnetic field. | **Example** -```js -sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data) { - if (err) { - console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message); - return; - } - console.info('sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' + - data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle + - ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity); + +```ts +sensor.getGeomagneticField({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000, function (err, data) { + if (err) { + console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info('Succeeded in getting sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' + + data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle + + ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity); }); ``` ## sensor.getGeomagneticField(deprecated) @@ -5682,16 +5938,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.getGe | Promise<[GeomagneticResponse](#geomagneticresponse)> | Promise used to return the geomagnetic field.| **Example** - ```js - const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 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.'); - }) - ``` + +```ts +const promise = sensor.getGeomagneticField({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000); +promise.then((data) => { + console.info('Succeeded in getting 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.error(`Failed to operate.`); +}) +``` ## sensor.getAltitude(deprecated) @@ -5713,16 +5970,15 @@ This API is deprecated since API version 9. You are advised to use [sensor.getDe **Example** - ```js - sensor.getAltitude(0, 200, function(err, data) { - if (err) { - console.error( - "Operation failed. Error code: " + err.code + ", message: " + err.message); - return; - } - console.info("Succeeded to get getAltitude interface get data: " + data); - }); - ``` +```ts +sensor.getAltitude(0, 200, function (err, data) { + if (err) { + console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info("Succeeded in getting getAltitude interface get data: " + data); +}); +``` ## sensor.getAltitude(deprecated) @@ -5749,14 +6005,14 @@ This API is deprecated since API version 9. You are advised to use [sensor.getDe **Example** - ```js - const promise = sensor.getAltitude(0, 200); - promise.then((data) => { - console.info(' sensor_getAltitude_Promise success', data); - }).catch((err) => { - console.error("Operation failed"); - }) - ``` +```ts +const promise = sensor.getAltitude(0, 200); +promise.then((data) => { + console.info('Succeeded in getting sensor_getAltitude_Promise success', data); +}).catch((err) => { + console.error(`Failed to operate.`); +}) +``` ## sensor.getGeomagneticDip(deprecated) @@ -5778,16 +6034,15 @@ This API is deprecated since API version 9. You are advised to use [sensor.getIn **Example** - ```js - sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data) { - if (err) { - console.error('SensorJsAPI--->Failed to register data, error code is:' + err.code + ', message: ' + - err.message); - return; - } - console.info("Succeeded to get getGeomagneticDip interface get data: " + data); - }) - ``` +```ts +sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function (err, data) { + if (err) { + console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info("Succeeded in getting getGeomagneticDip interface get data: " + data); +}) +``` ## sensor.getGeomagneticDip(deprecated) @@ -5813,14 +6068,14 @@ This API is deprecated since API version 9. You are advised to use [sensor.getIn **Example** - ```js - const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]); - promise.then((data) => { - console.info('getGeomagneticDip_promise succeeded', data); - }).catch((err) => { - console.error("Operation failed"); - }) - ``` +```ts +const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]); +promise.then((data) => { + console.info('Succeeded in get GeomagneticDip_promise', data); +}).catch((err) => { + console.error(`Failed to operate.`); +}) +``` ## sensor. getAngleModify(deprecated) @@ -5842,19 +6097,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.getAn **Example** - ```js - sensor. getAngleModify([1,0,0,0,1,0,0,0,1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function(err, data) { - if (err) { - console.error('Failed to register data, error code is: ' + err.code + ', message: ' + - err.message); - return; - } - for (var i=0; i < data.length; i++) { - console.info("data[" + i + "]: " + data[i]); - } - }) - ``` - +```ts +sensor.getAngleModify([1, 0, 0, 0, 1, 0, 0, 0, 1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function (err, data) { + if (err) { + console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); + return; + } + for (var i = 0; i < data.length; i++) { + console.info("data[" + i + "]: " + data[i]); + } +}) +``` ## sensor. getAngleModify(deprecated) @@ -5881,18 +6134,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.getAn **Example** - ```js - const promise = sensor.getAngleModify([1,0,0,0,1,0,0,0,1], [1,0,0,0,0.87,-0.50,0,0.50,0.87]); - promise.then((data) => { - console.info('getAngleModify_promise success'); - for (var i=0; i < data.length; i++) { - console.info("data[" + i + "]: " + data[i]); - } - }).catch((reason) => { - console.info("promise::catch", reason); - }) - ``` - +```ts +const promise = sensor.getAngleModify([1, 0, 0, 0, 1, 0, 0, 0, 1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87]); +promise.then((data) => { + console.info('Succeeded in getting AngleModify_promise.'); + for (var i = 0; i < data.length; i++) { + console.info("Succeeded in getting data[" + i + "]: " + data[i]); + } +}).catch((reason) => { + console.info("Succeeded in getting promise::catch", reason); +}) +``` ## sensor.createRotationMatrix(deprecated) @@ -5913,19 +6165,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.getRo **Example** - ```js - sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) { - if (err) { - console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + - err.message); - return; - } - for (var i=0; i < data.length; i++) { - console.info("data[" + i + "]: " + data[i]); - } - }) - ``` - +```ts +sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function (err, data) { + if (err) { + console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); + return; + } + for (var i = 0; i < data.length; i++) { + console.info("Succeeded in getting data[" + i + "]: " + data[i]); + } +}) +``` ## sensor.createRotationMatrix(deprecated) @@ -5951,18 +6201,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.getRo **Example** - ```js - const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]); - promise.then((data) => { - console.info('createRotationMatrix_promise success'); - for (var i=0; i < data.length; i++) { - console.info("data[" + i + "]: " + data[i]); - } - }).catch((reason) => { - console.info("promise::catch", reason); - }) - ``` - + ```ts +const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]); +promise.then((data) => { + console.info('Succeeded in getting createRotationMatrix_promise'); + for (var i = 0; i < data.length; i++) { + console.info("data[" + i + "]: " + data[i]); + } +}).catch((reason) => { + console.info("Succeeded in getting promise::catch", reason); +}) +``` ## sensor.createQuaternion(deprecated) @@ -5983,19 +6232,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.getQu **Example** - ```js - sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) { - if (err) { - console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + - err.message); - return; - } - for (var i=0; i < data.length; i++) { - console.info("data[" + i + "]: " + data[i]); - } - }) - ``` - +```ts +sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function (err, data) { + if (err) { + console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); + return; + } + for (var i = 0; i < data.length; i++) { + console.info("Succeeded in getting data[" + i + "]: " + data[i]); + } +}) +``` ## sensor.createQuaternion(deprecated) @@ -6021,18 +6268,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.getQu **Example** - ```js - const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]); - promise.then((data) => { - console.info('createQuaternion_promise succeeded'); - for (var i=0; i < data.length; i++) { - console.info("data[" + i + "]: " + data[i]); - } - }).catch((err) => { - console.info('promise failed'); - }) - ``` - +```ts +const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]); +promise.then((data) => { + console.info('Succeeded in getting createQuaternion_promise'); + for (var i = 0; i < data.length; i++) { + console.info("data[" + i + "]: " + data[i]); + } +}).catch((err) => { + console.info(`Failed to get promise.`); +}) +``` ## sensor.getDirection(deprecated) @@ -6048,25 +6294,23 @@ This API is deprecated since API version 9. You are advised to use [sensor.getOr | Name | Type | Mandatory | Description | | -------------- | ---------------------------------------- | ---- | ------------------ | -| rotationMatrix | Array<number> | Yes | Rotation matrix. | +| rotationMatrix | Array<number> | Yes | The other rotation matrix. | | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation angle around the z, x, and y axes.| **Example** - ```js - sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data) { - if (err) { - console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + - err.message); - return; - } - console.info("SensorJsAPI--->Succeeded to get getDirection interface get data: " + data); - for (var i = 1; i < data.length; i++) { - console.info("sensor_getDirection_callback" + data[i]); - } - }) - ``` - +```ts +sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function (err, data) { + if (err) { + console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info("Succeeded in getting getDirection interface get data: " + data); + for (var i = 1; i < data.length; i++) { + console.info("Succeeded in getting sensor_getDirection_callback" + data[i]); + } +}) +``` ## sensor.getDirection(deprecated) @@ -6082,7 +6326,7 @@ This API is deprecated since API version 9. You are advised to use [sensor.getOr | Name | Type | Mandatory | Description | | -------------- | ------------------- | ---- | ------- | -| rotationMatrix | Array<number> | Yes | Rotation matrix.| +| rotationMatrix | Array<number> | Yes | The other rotation matrix.| **Return value** @@ -6092,18 +6336,17 @@ This API is deprecated since API version 9. You are advised to use [sensor.getOr **Example** - ```js - const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]); - promise.then((data) => { - console.info('sensor_getAltitude_Promise success', data); - for (var i = 1; i < data.length; i++) { - console.info("sensor_getDirection_promise" + data[i]); - } - }).catch((err) => { - console.info('promise failed'); - }) - ``` - +```ts +const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]); +promise.then((data) => { + console.info('Succeeded in getting sensor_getAltitude_Promise', data); + for (var i = 1; i < data.length; i++) { + console.info("Succeeded in getting sensor_getDirection_promise" + data[i]); + } +}).catch((err) => { + console.info(`Failed to get promise.`); +}) +``` ## sensor.createRotationMatrix(deprecated) @@ -6125,16 +6368,15 @@ This API is deprecated since API version 9. You are advised to use [sensor.getRo **Example** - ```js - sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data) { - if (err) { - console.error('error code is: ' + err.code + ', message: ' + err.message); - return; - } - console.info(JSON.stringify(data)); - }) - ``` - +```ts +sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function (err, data) { + if (err) { + console.error(`Failed to get create rotationMatrix. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info(JSON.stringify(data)); +}) +``` ## sensor.createRotationMatrix(deprecated) @@ -6161,11 +6403,11 @@ This API is deprecated since API version 9. You are advised to use [sensor.getRo **Example** - ```js - const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]); - promise.then((data) => { - console.info(JSON.stringify(data)); - }).catch((err) => { - console.info('promise failed'); - }) - ``` +```ts +const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]); +promise.then((data) => { + console.info(JSON.stringify(data)); +}).catch((err) => { + console.info(`Failed to get promise.`); +}) + ``` diff --git a/en/application-dev/reference/apis/js-apis-system-sensor.md b/en/application-dev/reference/apis/js-apis-system-sensor.md index 945be8c89d79e74cb6bc284e90089edad1709b4e..7b77fb30247b7e859e862111b0b4ec2447c34a66 100644 --- a/en/application-dev/reference/apis/js-apis-system-sensor.md +++ b/en/application-dev/reference/apis/js-apis-system-sensor.md @@ -25,7 +25,7 @@ import sensor from '@system.sensor'; Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Required permissions**: ohos.permission.ACCELEROMETER (a system permission) @@ -37,16 +37,16 @@ Subscribes to data changes of the acceleration sensor. If this API is called mul **Example** -```js +```ts sensor.subscribeAccelerometer({ interval: 'normal', - success: function(ret) { - console.log('X-axis data: ' + ret.x); - console.log('Y-axis data: ' + ret.y); - console.log('Z-axis data: ' + ret.z); + success: function (ret) { + console.info('Succeeded in subscribing. X-axis data: ' + ret.x); + console.info('Succeeded in subscribing. Y-axis data: ' + ret.y); + console.info('Succeeded in subscribing. Z-axis data: ' + ret.z); }, - fail: function(data, code) { - console.error('Subscription failed. Code: ' + code + '; Data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); }, }); ``` @@ -60,13 +60,13 @@ unsubscribeAccelerometer(): void Unsubscribes from data changes of the acceleration sensor. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Required permissions**: ohos.permission.ACCELEROMETER (a system permission) **Example** -```js +```ts sensor.unsubscribeAccelerometer(); ``` @@ -76,7 +76,7 @@ sensor.unsubscribeAccelerometer(); Subscribes to data changes of the compass sensor. If this API is called multiple times for the same application, the last call takes effect. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Parameters** @@ -86,13 +86,13 @@ Subscribes to data changes of the compass sensor. If this API is called multiple **Example** -```js +```ts sensor.subscribeCompass({ - success: function(ret) { - console.log('Get data direction:' + ret.direction); + success: function (ret) { + console.info('Succeeded in subscribing. Get data direction:' + ret.direction); }, - fail: function(data, code) { - console.error('Subscription failed. Code: ' + code + '; Data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); }, }); ``` @@ -106,11 +106,11 @@ unsubscribeCompass(): void Unsubscribes from data changes of the compass sensor. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Example** -```js +```ts sensor.unsubscribeCompass(); ``` @@ -120,7 +120,7 @@ sensor.unsubscribeCompass(); Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Parameters** @@ -130,13 +130,14 @@ Subscribes to data changes of the proximity sensor. If this API is called multip **Example** -```js +```ts sensor.subscribeProximity({ - success: function(ret) { - console.log('Get data distance:' + ret.distance); + success: function (ret) { + console.info('Succeeded in subscribing. Get data distance:' + ret.distance); }, - fail: function(data, code) { - console.error('Subscription failed. Code: ' + code + '; Data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); + }, }); ``` @@ -150,11 +151,11 @@ unsubscribeProximity(): void Unsubscribes from data changes of the proximity sensor. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Example** -```js +```ts sensor.unsubscribeProximity(); ``` @@ -164,7 +165,7 @@ sensor.unsubscribeProximity(); Subscribes to data changes of the ambient light sensor. If this API is called multiple times, the last call takes effect. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Parameters** @@ -174,13 +175,13 @@ Subscribes to data changes of the ambient light sensor. If this API is called mu **Example** -```js +```ts sensor.subscribeLight({ - success: function(ret) { - console.log('Get data intensity:' + ret.intensity); + success: function (ret) { + console.info('Succeeded in subscribing. Get data intensity:' + ret.intensity); }, - fail: function(data, code) { - console.error('Subscription failed. Code: ' + code + '; Data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); }, }); ``` @@ -194,11 +195,11 @@ unsubscribeLight(): void Unsubscribes from data changes of the ambient light sensor. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Example** -```js +```ts sensor.unsubscribeLight(); ``` @@ -208,7 +209,7 @@ sensor.unsubscribeLight(); Subscribes to data changes of the step counter sensor. If this API is called multiple times for the same application, the last call takes effect. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Required permissions**: ohos.permission.ACTIVITY_MOTION @@ -220,13 +221,13 @@ Subscribes to data changes of the step counter sensor. If this API is called mul **Example** -```js +```ts sensor.subscribeStepCounter({ - success: function(ret) { - console.log('Get step value:' + ret.steps); + success: function (ret) { + console.info('Succeeded in subscribing. Get step value:' + ret.steps); }, - fail: function(data, code) { - console.log('Subscription failed. Code: ' + code + '; Data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); }, }); ``` @@ -240,13 +241,13 @@ unsubscribeStepCounter(): void Unsubscribes from data changes of the step counter sensor. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Required permissions**: ohos.permission.ACTIVITY_MOTION **Example** -```js +```ts sensor.unsubscribeStepCounter(); ``` @@ -257,7 +258,7 @@ subscribeBarometer(options: SubscribeBarometerOptions): 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. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Parameters** @@ -267,13 +268,13 @@ Subscribes to data changes of the barometer sensor. If this API is called multip **Example** -```js +```ts sensor.subscribeBarometer({ - success: function(ret) { - console.log('Get data value:' + ret.pressure); + success: function (ret) { + console.info('Succeeded in subscribing. Get data value:' + ret.pressure); }, - fail: function(data, code) { - console.log('Subscription failed. Code: ' + code + '; Data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); }, }); ``` @@ -288,11 +289,11 @@ unsubscribeBarometer(): void Unsubscribes from data changes of the barometer sensor. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Example** -```js +```ts sensor.unsubscribeBarometer(); ``` @@ -303,7 +304,7 @@ sensor.unsubscribeBarometer(); Subscribes to data changes of the heart rate sensor. If this API is called multiple times for the same application, the last call takes effect. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Required permissions**: ohos.permission.READ_HEALTH_DATA @@ -315,13 +316,13 @@ Subscribes to data changes of the heart rate sensor. If this API is called multi **Example** -```js +```ts sensor.subscribeHeartRate({ - success: function(ret) { - console.log('Get heartrate value:' + ret.heartRate); + success: function (ret) { + console.info('Succeeded in subscribing. Get heartrate value:' + ret.heartRate); }, - fail: function(data, code) { - console.log('Subscription failed. Code: ' + code + '; Data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); }, }); ``` @@ -336,13 +337,13 @@ unsubscribeHeartRate(): void Unsubscribes from data changes of the heart rate sensor. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Required permissions**: ohos.permission.READ_HEALTH_DATA **Example** -```js +```ts sensor.unsubscribeHeartRate(); ``` @@ -352,7 +353,7 @@ sensor.unsubscribeHeartRate(); Subscribes to changes of the wearing state of a wearable device. If this API is called multiple times for the same application, the last call takes effect. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Parameters** @@ -362,13 +363,13 @@ Subscribes to changes of the wearing state of a wearable device. If this API is **Example** -```js +```ts sensor.subscribeOnBodyState({ - success: function(ret) { - console.log('Get on-body state value:' + ret.value); + success: function (ret) { + console.info('Succeeded in subscribing. Get on-body state value:' + ret.value); }, - fail: function(data, code) { - console.log('Subscription failed. Code: ' + code + '; Data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); }, }); ``` @@ -382,11 +383,11 @@ unsubscribeOnBodyState(): void Unsubscribes from changes of the wearing state of a wearable device. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Example** -```js +```ts sensor.unsubscribeOnBodyState(); ``` @@ -396,7 +397,7 @@ sensor.unsubscribeOnBodyState(); Obtains the wearing state of a wearable device. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Parameters** @@ -406,13 +407,13 @@ Obtains the wearing state of a wearable device. **Example** -```js +```ts sensor.getOnBodyState({ - success: function(ret) { - console.log('On body state: ' + ret.value); + success: function (ret) { + console.info('Succeeded in subscribing. On body state: ' + ret.value); }, - fail: function(data, code) { - console.log('Subscription failed. Code: ' + code + '; Data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); }, }); ``` @@ -425,7 +426,7 @@ Subscribes to data changes of the device orientation sensor. If this API is called multiple times for the same application, the last call takes effect. However, this API cannot be called multiple times in one click event. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Parameters** @@ -435,17 +436,17 @@ If this API is called multiple times for the same application, the last call tak **Example** -```js +```ts sensor.subscribeDeviceOrientation({ interval: 'normal', - success: function(ret) { - console.log('Alpha data: ' + ret.alpha); - console.log('Beta data: ' + ret.beta); - console.log('Gamma data: ' + ret.gamma); + success: function (ret) { + console.info('Succeeded in subscribing. Alpha data: ' + ret.alpha); + console.info('Succeeded in subscribing. Beta data: ' + ret.beta); + console.info('Succeeded in subscribing. Gamma data: ' + ret.gamma); }, - fail: function(data, code) { - console.error('Subscription failed. Code: ' + code + '; Data: ' + data); - } + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); + } }); ``` @@ -458,11 +459,11 @@ unsubscribeDeviceOrientation(): void Unsubscribes from data changes of the device orientation sensor. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Example** -```js +```ts sensor.unsubscribeDeviceOrientation(); ``` @@ -474,7 +475,7 @@ Subscribes to data changes of the gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect. However, this API cannot be called multiple times in one click event. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Required permissions**: ohos.permission.GYROSCOPE (a system permission) @@ -486,16 +487,16 @@ If this API is called multiple times for the same application, the last call tak **Example** -```js +```ts sensor.subscribeGyroscope({ interval: 'normal', - success: function(ret) { - console.log('X-axis data: ' + ret.x); - console.log('Y-axis data: ' + ret.y); - console.log('Z-axis data: ' + ret.z); + success: function (ret) { + console.info('Succeeded in subscribing. X-axis data: ' + ret.x); + console.info('Succeeded in subscribing. Y-axis data: ' + ret.y); + console.info('Succeeded in subscribing. Z-axis data: ' + ret.z); }, - fail: function(data, code) { - console.error('Subscription failed. Code: ' + code + '; data: ' + data); + fail: function (data, code) { + console.error(`Failed to subscription. Code: ${code}, data: ${data}`); } }); ``` @@ -509,13 +510,13 @@ unsubscribeGyroscope(): void Unsubscribes from data changes of the gyroscope sensor. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite **Required permissions**: ohos.permission.GYROSCOPE (a system permission) **Example** -```js +```ts sensor.unsubscribeGyroscope(); ``` @@ -525,7 +526,7 @@ Defines the type of data to return for a subscription to the acceleration sensor **Required permissions**: ohos.permission.ACCELEROMETER -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | @@ -539,7 +540,7 @@ Defines the type of data to include in an **AccelerometerResponse** object. **Required permissions**: ohos.permission.ACCELEROMETER -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name| Type | Mandatory| Description | | ---- | ------ | ---- | ------------- | @@ -551,7 +552,7 @@ Defines the type of data to include in an **AccelerometerResponse** object. Defines the type of data to return for a subscription to the compass sensor data. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ------- | ----------------------------------- | ---- | ------------------------------ | @@ -562,7 +563,7 @@ Defines the type of data to return for a subscription to the compass sensor data Defines the type of data to include in a **CompassResponse** object. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | --------- | ------ | ---- | -------------------- | @@ -572,7 +573,7 @@ Defines the type of data to include in a **CompassResponse** object. Defines the type of data to return for a subscription to the proximity sensor data. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ------- | --------------------------------------- | ---- | ---------------------------------- | @@ -583,7 +584,7 @@ Defines the type of data to return for a subscription to the proximity sensor da Defines the type of data to include in a **ProximityResponse** object. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------ | @@ -593,18 +594,18 @@ Defines the type of data to include in a **ProximityResponse** object. Defines the type of data to return for a subscription to the ambient light sensor data. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ------- | ------------------------------- | ---- | ------------------------------ | -| success | [LightResponse](#lightresponse) | Yes | Called when the ambient light sensor data changes| +| success | [LightResponse](#lightresponse) | Yes | Called when the ambient light sensor data changes.| | fail | Function | No | Callback upon an API call failure. | ## LightResponse Defines the type of data to include in a **LightResponse** object. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | --------- | ------ | ---- | --------------------- | @@ -616,7 +617,7 @@ Defines the type of data to return for a subscription to the step counter sensor **Required permissions**: ohos.permission.ACTIVITY_MOTION -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ------- | ------------------------------------------- | ---- | -------------------------------- | @@ -629,7 +630,7 @@ Defines the type of data to include in a **StepCounterResponse** object. **Required permissions**: ohos.permission.ACTIVITY_MOTION -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ----- | ------ | ---- | -------------------------------- | @@ -639,7 +640,7 @@ Defines the type of data to include in a **StepCounterResponse** object. Defines the type of data to return for a subscription to the barometer sensor data. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ------- | --------------------------------------- | ---- | -------------------------------- | @@ -650,7 +651,7 @@ Defines the type of data to return for a subscription to the barometer sensor da Defines the type of data to include in a **BarometerResponse** object. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ---------------------- | @@ -662,7 +663,7 @@ Defines the type of data to return for a subscription to the heart rate sensor d **Required permissions**: ohos.permission.READ_HEALTH_DATA -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ------- | --------------------------------------- | ---- | ----------------------------------------------- | @@ -675,7 +676,7 @@ Defines the type of data to include in a **HeartRateResponse** object. **Required permissions**: ohos.permission.READ_HEALTH_DATA -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | --------- | ------ | ---- | -------- | @@ -685,7 +686,7 @@ Defines the type of data to include in a **HeartRateResponse** object. Defines the type of data to return for a subscription to the wearing state changes. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ------- | ------------------------------------------- | ---- | -------------------------- | @@ -696,7 +697,7 @@ Defines the type of data to return for a subscription to the wearing state chang Defines the wearing state. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ----- | ------- | ---- | ------------ | @@ -706,7 +707,7 @@ Defines the wearing state. Defines the type of data to return for obtaining the wearing state. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | -------- | ------------------------------------------- | ---- | ------------------------ | @@ -718,7 +719,7 @@ Defines the wearing state. Defines the type of data to return for a subscription to the device orientation sensor data. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | @@ -730,7 +731,7 @@ Defines the type of data to return for a subscription to the device orientation Defines the type of data to include in a **DeviceOrientationResponse** object. -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | ----- | ------ | ---- | ------------------------------------------------------------ | @@ -744,7 +745,7 @@ Defines the type of data to return for a subscription to the gyroscope sensor da **Required permissions**: ohos.permission.GYROSCOPE -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name | Type | Mandatory| Description | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | @@ -758,7 +759,7 @@ Defines the type of data to include in a **GyroscopeResponse** object. **Required permissions**: ohos.permission.GYROSCOPE -**System capability**: SystemCapability.Sensors.Sensor +**System capability**: SystemCapability.Sensors.Sensor.Lite | Name| Type | Mandatory| Description | | ---- | ------ | ---- | ----------------- | diff --git a/en/application-dev/reference/apis/js-apis-system-vibrate.md b/en/application-dev/reference/apis/js-apis-system-vibrate.md index a48f2f453f5c1de2d55e23f7005ea5a28b941684..b90befa1729a6d0e38289ae189acc2ca2958ebb4 100644 --- a/en/application-dev/reference/apis/js-apis-system-vibrate.md +++ b/en/application-dev/reference/apis/js-apis-system-vibrate.md @@ -26,7 +26,7 @@ Triggers device vibration. **Required permissions**: ohos.permission.VIBRATE -**System capability**: SystemCapability.Sensors.MiscDevice +**System capability**: SystemCapability.Sensors.MiscDevice.Lite **Parameters** @@ -36,17 +36,17 @@ Triggers device vibration. **Example** -```js +```ts vibrator.vibrate({ mode: 'short', success: function() { - console.log('vibrate is successful'); + console.info('Succeed in vibrating'); }, fail: function(data, code) { - console.log("vibrate is failed, data: " + data + ", code: " + code); + console.info(`Failed to vibrate. Data: ${data}, code: ${code}`); }, complete: function() { - console.log('vibrate is completed'); + console.info('completed in vibrating'); } }); ``` @@ -57,7 +57,7 @@ Defines the vibration options. **Required permissions**: ohos.permission.VIBRATE -**System capability**: SystemCapability.Sensors.MiscDevice +**System capability**: SystemCapability.Sensors.MiscDevice.Lite | Name | Type | Mandatory| Description | | -------- | -------- | ---- | ------------------------------------------------------------ | diff --git a/en/application-dev/reference/apis/js-apis-vibrator.md b/en/application-dev/reference/apis/js-apis-vibrator.md index c0e2de3e09ae03dfb4a5e76c0e727e37856e807c..c7f5d755d5ddbfd78768a8754933619ba63031ae 100644 --- a/en/application-dev/reference/apis/js-apis-vibrator.md +++ b/en/application-dev/reference/apis/js-apis-vibrator.md @@ -9,7 +9,7 @@ The **vibrator** module provides APIs for starting or stopping vibration. ## Modules to Import -```js +```ts import vibrator from '@ohos.vibrator'; ``` @@ -41,24 +41,25 @@ For details about the error codes, see [Vibrator Error Codes](../errorcodes/erro **Example** -```js +```ts import vibrator from '@ohos.vibrator'; + try { - vibrator.startVibration({ - type: 'time', - duration: 1000, - }, { - id: 0, - usage: 'alarm' - }, (error) => { - if (error) { - console.error('Vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message); - return; - } - console.log('Callback returned to indicate a successful vibration.'); - }); + vibrator.startVibration({ + type: 'time', + duration: 1000, + }, { + id: 0, + usage: 'alarm' + }, (error) => { + if (error) { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in starting vibration'); + }); } catch (err) { - console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + console.error(`An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); } ``` @@ -95,24 +96,25 @@ For details about the error codes, see [Vibrator Error Codes](../errorcodes/erro **Example** - ```js +```ts import vibrator from '@ohos.vibrator'; + try { - vibrator.startVibration({ - type: 'time', - duration: 1000 - }, { - id: 0, - usage: 'alarm' - }).then(() => { - console.log('Promise returned to indicate a successful vibration'); - }, (error) => { - console.error('error.code' + error.code + 'error.message' + error.message); - }); + vibrator.startVibration({ + type: 'time', + duration: 1000 + }, { + id: 0, + usage: 'alarm' + }).then(() => { + console.info('Succeed in starting vibration'); + }, (error) => { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + }); } catch (err) { - console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + console.error(`An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); } - ``` +``` ## vibrator.stopVibration9+ @@ -133,40 +135,41 @@ Stops vibration in the specified mode. This API uses an asynchronous callback to **Example** - ```js +```ts import vibrator from '@ohos.vibrator'; + try { - // Start vibration at a fixed duration. - vibrator.startVibration({ - type: 'time', - duration: 1000, - }, { - id: 0, - usage: 'alarm' - }, (error) => { - if (error) { - console.error('Vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message); - return; - } - console.log('Callback returned to indicate a successful vibration.'); - }); + // Start vibration at a fixed duration. + vibrator.startVibration({ + type: 'time', + duration: 1000, + }, { + id: 0, + usage: 'alarm' + }, (error) => { + if (error) { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in starting vibration'); + }); } catch (err) { - console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + console.error(`An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); } try { - // Stop vibration in VIBRATOR_STOP_MODE_TIME mode. - vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, function (error) { - if (error) { - console.log('error.code' + error.code + 'error.message' + error.message); - return; - } - console.log('Callback returned to indicate successful.'); - }) + // Stop vibration in VIBRATOR_STOP_MODE_TIME mode. + vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME, function (error) { + if (error) { + console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in stopping vibration'); + }) } catch (err) { - console.info('errCode: ' + err.code + ' ,msg: ' + err.message); + console.error(`An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); } - ``` +``` ## vibrator.stopVibration9+ @@ -192,36 +195,37 @@ Stops vibration in the specified mode. This API uses a promise to return the res **Example** - ```js +```ts import vibrator from '@ohos.vibrator'; + try { - // Start vibration at a fixed duration. - vibrator.startVibration({ - type: 'time', - duration: 1000 - }, { - id: 0, - usage: 'alarm' - }).then(() => { - console.log('Promise returned to indicate a successful vibration'); - }, (error) => { - console.error('error.code' + error.code + 'error.message' + error.message); - }); + // Start vibration at a fixed duration. + vibrator.startVibration({ + type: 'time', + duration: 1000 + }, { + id: 0, + usage: 'alarm' + }).then(() => { + console.info('Succeed in starting vibration'); + }, (error) => { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + }); } catch (err) { - console.error('errCode: ' + err.code + ' ,msg: ' + err.message); + console.error(`An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); } try { - // Stop vibration in VIBRATOR_STOP_MODE_TIME mode. - vibrator.stopVibration(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); - }); + // Stop vibration in VIBRATOR_STOP_MODE_TIME mode. + vibrator.stopVibration(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(() => { + console.info('Succeed in stopping vibration'); + }, (error) => { + console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); + }); } catch (err) { - console.info('errCode: ' + err.code + ' ,msg: ' + err.message); + console.error(`An unexpected error occurred. Code: ${err.code}, message: ${err.message}`); } - ``` +``` ## vibrator.stopVibration10+ @@ -241,40 +245,41 @@ Stops vibration in all modes. This API uses an asynchronous callback to return t **Example** - ```js +```ts import vibrator from '@ohos.vibrator'; + try { - // Start vibration at a fixed duration. - vibrator.startVibration({ - type: 'time', - duration: 1000, - }, { - id: 0, - usage: 'alarm' - }, (error) => { - if (error) { - console.error('Vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message); - return; - } - console.log('Callback returned to indicate a successful vibration.'); - }); + // Start vibration at a fixed duration. + vibrator.startVibration({ + type: 'time', + duration: 1000, + }, { + id: 0, + usage: 'alarm' + }, (error) => { + if (error) { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in starting vibration'); + }); } catch (error) { - console.error('errCode: ' + error.code + ' ,msg: ' + error.message); + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } try { - // Stop vibration in all modes. - vibrator.stopVibration(function (error) { - if (error) { - console.log('error.code' + error.code + 'error.message' + error.message); - return; - } - console.log('Callback returned to indicate successful.'); - }) + // Stop vibration in all modes. + vibrator.stopVibration(function (error) { + if (error) { + console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); + return; + } + console.info('Succeed in stopping vibration'); + }) } catch (error) { - console.info('errCode: ' + error.code + ' ,msg: ' + error.message); + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } - ``` +``` ## vibrator.stopVibration10+ @@ -294,36 +299,37 @@ Stops vibration in all modes. This API uses a promise to return the result. **Example** - ```js +```ts import vibrator from '@ohos.vibrator'; + try { - // Start vibration at a fixed duration. - vibrator.startVibration({ - type: 'time', - duration: 1000 - }, { - id: 0, - usage: 'alarm' - }).then(() => { - console.log('Promise returned to indicate a successful vibration'); - }, (error) => { - console.error('error.code' + error.code + 'error.message' + error.message); - }); + // Start vibration at a fixed duration. + vibrator.startVibration({ + type: 'time', + duration: 1000 + }, { + id: 0, + usage: 'alarm' + }).then(() => { + console.info('Succeed in starting vibration'); + }, (error) => { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + }); } catch (error) { - console.error('errCode: ' + error.code + ' ,msg: ' + error.message); + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } try { - // Stop vibration in all modes. - vibrator.stopVibration().then(() => { - console.log('Promise returned to indicate a successful vibration.'); - }, (error) => { - console.log('error.code' + error.code + 'error.message' + error.message); - }); + // Stop vibration in all modes. + vibrator.stopVibration().then(() => { + console.info('Succeed in stopping vibration'); + }, (error) => { + console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); + }); } catch (error) { - console.info('errCode: ' + error.code + ' ,msg: ' + error.message); + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } - ``` +``` ## vibrator.isSupportEffect10+ @@ -342,40 +348,41 @@ Checks whether the passed effect ID is supported. This API uses an asynchronous **Example** - ```js +```ts import vibrator from '@ohos.vibrator'; + try { - // Check whether 'haptic.clock.timer' is supported. - vibrator.isSupportEffect('haptic.clock.timer', function (err, state) { - if (err) { - console.error('isSupportEffect failed, error:' + JSON.stringify(err)); - return; - } - console.log('The effectId is ' + (state ? 'supported' : 'unsupported')); - if (state) { - try { - vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission. - type: 'preset', - effectId: 'haptic.clock.timer', - count: 1, - }, { - usage: 'unknown' - }, (error) => { - if(error) { - console.error('haptic.clock.timer vibrator error:' + JSON.stringify(error)); - } else { - console.log('haptic.clock.timer vibrator success'); - } - }); - } catch (error) { - console.error('Exception in, error:' + JSON.stringify(error)); - } - } - }) + // Check whether 'haptic.clock.timer' is supported. + vibrator.isSupportEffect('haptic.clock.timer', function (err, state) { + if (err) { + console.error(`Failed to query effect. Code: ${err.code}, message: ${err.message}`); + return; + } + console.info('Succeed in querying effect'); + if (state) { + try { + vibrator.startVibration({ // To use startVibration, you must configure the ohos.permission.VIBRATE permission. + type: 'preset', + effectId: 'haptic.clock.timer', + count: 1, + }, { + usage: 'unknown' + }, (error) => { + if (error) { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + } else { + console.info('Succeed in starting vibration'); + } + }); + } catch (error) { + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); + } + } + }) } catch (error) { - console.error('Exception in, error:' + JSON.stringify(error)); + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } - ``` +``` ## vibrator.isSupportEffect10+ @@ -399,36 +406,37 @@ Checks whether the passed effect ID is supported. This API uses a promise to ret **Example** - ```js +```ts import vibrator from '@ohos.vibrator'; + try { - // Check whether 'haptic.clock.timer' is supported. - vibrator.isSupportEffect('haptic.clock.timer').then((state) => { - console.log('The effectId is ' + (state ? 'supported' : 'unsupported')); - if (state) { - try { - vibrator.startVibration({ - type: 'preset', - effectId: 'haptic.clock.timer', - count: 1, - }, { - usage: 'unknown' - }).then(()=>{ - console.log('Promise returned to indicate a successful vibration'); - }).catch((error)=>{ - console.error('Promise returned to indicate a failed vibration:' + JSON.stringify(error)); - }); - } catch (error) { - console.error('Exception in, error:' + JSON.stringify(error)); - } - } - }, (error) => { - console.error('isSupportEffect failed, error:' + JSON.stringify(error)); - }) + // Check whether 'haptic.clock.timer' is supported. + vibrator.isSupportEffect('haptic.clock.timer').then((state) => { + console.info(`The query result is ${state}`); + if (state) { + try { + vibrator.startVibration({ + type: 'preset', + effectId: 'haptic.clock.timer', + count: 1, + }, { + usage: 'unknown' + }).then(() => { + console.info('Succeed in starting vibration'); + }).catch((error) => { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + }); + } catch (error) { + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); + } + } + }, (error) => { + console.error(`Failed to query effect. Code: ${error.code}, message: ${error.message}`); + }) } catch (error) { - console.error('Exception in, error:' + JSON.stringify(error)); + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } - ``` +``` ## EffectId @@ -489,7 +497,7 @@ Describes the vibration with a preset effect. ## VibrateFromFile10+ -Describes the custom vibration type, which is supported only by certain devices. +Describes the custom vibration type, which is supported only by certain devices. If a device does not support this vibration type, [an error code indicating unsupported device](../errorcodes/errorcode-universal.md) is returned. **System capability**: SystemCapability.Sensors.MiscDevice @@ -565,13 +573,13 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta **Example** - ```js +```ts vibrator.vibrate(1000).then(() => { - console.log('Promise returned to indicate a successful vibration.'); + console.info('Succeed in vibrating'); }, (error) => { - console.log('error.code' + error.code + 'error.message' + error.message); + console.error(`Failed to vibrate. Code: ${error.code}, message: ${error.message}`); }); - ``` +``` ## vibrator.vibrate(deprecated) @@ -594,15 +602,15 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta **Example** - ```js +```ts 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.'); - } + if (error) { + console.error(`Failed to vibrate. Code: ${error.code}, message: ${error.message}`); + } else { + console.info('Succeed in vibrating'); + } }) - ``` +``` ## vibrator.vibrate(deprecated) @@ -631,13 +639,13 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta **Example** - ```js +```ts vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(() => { - console.log('Promise returned to indicate a successful vibration.'); + console.info('Succeed in vibrating'); }, (error) => { - console.log('error.code' + error.code + 'error.message' + error.message); + console.error(`Failed to vibrate. Code: ${error.code}, message: ${error.message}`); }); - ``` +``` ## vibrator.vibrate(deprecated) @@ -661,15 +669,15 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sta **Example** - ```js +```ts 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.'); - } + if (error) { + console.error(`Failed to vibrate. Code: ${error.code}, message: ${error.message}`); + } else { + console.info('Succeed in vibrating'); + } }) - ``` +``` ## vibrator.stop(deprecated) @@ -697,22 +705,22 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sto **Example** - ```js +```ts // Start vibration based on the specified effect ID. 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.'); - } + if (error) { + console.error(`Failed to vibrate. Code: ${error.code}, message: ${error.message}`); + } else { + console.info('Succeed in vibrating'); + } }) // Stop vibration in VIBRATOR_STOP_MODE_PRESET mode. vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then(() => { - console.log('Promise returned to indicate a successful vibration.'); + console.info('Succeed in stopping'); }, (error) => { - console.log('error.code' + error.code + 'error.message' + error.message); + console.error(`Failed to stop. Code: ${error.code}, message: ${error.message}`); }); - ``` +``` ## vibrator.stop(deprecated) @@ -736,21 +744,21 @@ This API is deprecated since API version 9. You are advised to use [vibrator.sto **Example** - ```js +```ts // Start vibration based on the specified effect ID. 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.'); - } + if (error) { + console.error(`Failed to vibrate. Code: ${error.code}, message: ${error.message}`); + } else { + console.info('Succeed in vibrating'); + } }) // Stop vibration in VIBRATOR_STOP_MODE_PRESET mode. 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 successful.'); - } + if (error) { + console.error(`Failed to stop. Code: ${error.code}, message: ${error.message}`); + } else { + onsole.info('Succeed in stopping'); + } }) - ``` +```