diff --git a/en/application-dev/device/figures/001.png b/en/application-dev/device/figures/001.png new file mode 100644 index 0000000000000000000000000000000000000000..0b173958ed943fb9ecebd686b4f378d93fa2a7b0 Binary files /dev/null and b/en/application-dev/device/figures/001.png differ diff --git a/en/application-dev/device/figures/002.png b/en/application-dev/device/figures/002.png new file mode 100644 index 0000000000000000000000000000000000000000..34af38f77c66cbef900a1a4e536e3873bd0d94aa Binary files /dev/null and b/en/application-dev/device/figures/002.png differ diff --git a/en/application-dev/device/figures/003.png b/en/application-dev/device/figures/003.png new file mode 100644 index 0000000000000000000000000000000000000000..3c95c64ccb305ec25b1927733615ec4553505f97 Binary files /dev/null and b/en/application-dev/device/figures/003.png differ diff --git a/en/application-dev/device/sensor-guidelines.md b/en/application-dev/device/sensor-guidelines.md index 6ff5eb7405027da0853737ba64959cec4e59ad3a..21e1b55296ac46606bf1e4c91859f4c1f03ce030 100644 --- a/en/application-dev/device/sensor-guidelines.md +++ b/en/application-dev/device/sensor-guidelines.md @@ -15,65 +15,64 @@ For details about the APIs, see [Sensor](../reference/apis/js-apis-sensor.md). | ohos.sensor | sensor.on(sensorId, callback:AsyncCallback<Response>): void | Subscribes to data changes of a type of sensor.| | ohos.sensor | sensor.once(sensorId, callback:AsyncCallback<Response>): void | Subscribes to only one data change of a type of sensor.| | ohos.sensor | sensor.off(sensorId, callback?:AsyncCallback<void>): void | Unsubscribes from sensor data changes.| +| ohos.sensor | sensor.getSensorList(callback: AsyncCallback\>): void| Obtains information about all sensors on the device. This API uses an asynchronous callback to return the result.| ## How to Develop -1. Before obtaining data from a type of sensor, check whether the required permission has been configured.
- The system provides the following sensor-related permissions: - - ohos.permission.ACCELEROMETER +The acceleration sensor is used as an example. - - ohos.permission.GYROSCOPE +1. Import the module. - - ohos.permission.ACTIVITY_MOTION - - - ohos.permission.READ_HEALTH_DATA - - 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. - ```ts import sensor from "@ohos.sensor"; - - 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. - }); ``` - - ![171e6f30-a8d9-414c-bafa-b430340305fb](figures/171e6f30-a8d9-414c-bafa-b430340305fb.png) -3. Unsubscribe from sensor data changes. - - ```ts - import sensor from "@ohos.sensor"; - sensor.off(sensor.SensorId.ACCELEROMETER); - ``` - - ![65d69983-29f6-4381-80a3-f9ef2ec19e53](figures/65d69983-29f6-4381-80a3-f9ef2ec19e53.png) +2. Obtain information about all sensors on the device. + + ```ts + sensor.getSensorList(function (error, data) { + if (error) { + console.info('getSensorList failed'); + } else { + console.info('getSensorList success'); + for (let i = 0; i < data.length; i++) { + console.info(JSON.stringify(data[i])); + } + } + }); + ``` -4. Subscribe to only one data change of a type of sensor. - - ```ts - import sensor from "@ohos.sensor"; + ![](figures/001.png) - 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. - }); - ``` - - ![db5d017d-6c1c-4a71-a2dd-f74b7f23239e](figures/db5d017d-6c1c-4a71-a2dd-f74b7f23239e.png) + The minimum and the maximum sampling periods supported by the sensor are 5000000 ns and 200000000 ns, respectively. Therefore, the value of **interval** must be within this range. + +3. Check whether the corresponding permission has been configured. For details, see [Applying for Permissions](../security/accesstoken-guidelines.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: +4. Register a listener. You can call **on()** or **once()** to listen for sensor data changes. + +- The **on()** API is used to continuously listen for data changes of the sensor. The sensor reporting interval is set to 100000000 ns. + + ```ts + sensor.on(sensor.SensorId.ACCELEROMETER, function (data) { + console.info("Succeeded in obtaining data. x: " + data.x + " y: " + data.y + " z: " + data.z); + }, {'interval': 100000000}); + ``` + + ![](figures/002.png) + +- The **once()** API is used to listen for only one data change of the sensor. ```ts - import sensor from "@ohos.sensor"; + sensor.once(sensor.SensorId.ACCELEROMETER, function (data) { + console.info("Succeeded in obtaining data. x: " + data.x + " y: " + data.y + " z: " + data.z); + }); + ``` + + ![](figures/003.png) - 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}`); - } +5. Cancel continuous listening. + + ```ts + sensor.off(sensor.SensorId.ACCELEROMETER); ``` diff --git a/en/application-dev/device/vibrator-guidelines.md b/en/application-dev/device/vibrator-guidelines.md index 7d3434d680d0d1a369d4f0ccd0bc8f720bd71349..4619a52a2f91c94b06e529be68d78330b4a4719f 100644 --- a/en/application-dev/device/vibrator-guidelines.md +++ b/en/application-dev/device/vibrator-guidelines.md @@ -76,9 +76,9 @@ This JSON file contains two attributes: **MetaData** and **Channels**. - **Create**: time when the file was created. This parameter is optional. - **Description**: additional information such as the vibration effect and creation information. This parameter is optional. - **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. + - **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 + - **transient**: short vibration - **continuous**: long vibration The table below describes the parameters under **Event**. @@ -89,7 +89,7 @@ The table below describes the parameters under **Event**. | StartTime | Start time of the vibration. This parameter is mandatory.| [0, 1800 000], in ms, without overlapping| | Duration | Duration of the vibration. This parameter is valid only when **Type** is **continuous**.| (10, 1600), in ms| | Intensity | Intensity of the vibration. This parameter is mandatory.| [0, 100], a relative value that does not represent the actual vibration strength.| -| Frequency | Frequency of the vibration. This parameter is mandatory.| [0, 100], a relative value that does not represent the actual vibration frequency| +| Frequency | Frequency of the vibration. This parameter is mandatory.| [0, 100], a relative value that does not represent the actual vibration frequency.| The following requirements must be met: @@ -221,45 +221,42 @@ The following requirements must be met: ```ts import vibrator from '@ohos.vibrator'; - const FILE_NAME = "xxx.json"; - // Obtain the file descriptor of the vibration configuration file. - 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: 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.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); + async function getRawfileFd(fileName) { + let rawFd = await globalThis.getContext().resourceManager.getRawFd(fileName); + return rawFd; + } + + // Close the file descriptor of the vibration configuration file. + async function closeRawfileFd(fileName) { + await globalThis.getContext().resourceManager.closeRawFd(fileName) + } + + // Play the custom vibration. To use startVibration and stopVibration, you must configure the ohos.permission.VIBRATE permission. + async function playCustomHaptic(fileName) { + try { + let rawFd = await getRawfileFd(fileName); + vibrator.startVibration({ + type: "file", + hapticFd: { fd: rawFd.fd, offset: rawFd.offset, length: rawFd.length } + }, { + usage: "alarm" + }).then(() => { + console.info('Succeed in starting vibration'); + }, (error) => { + console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); + }); + 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'); + }) + await closeRawfileFd(fileName); + } catch (error) { + console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); + } } - // 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 e2058f68ea5d50766c17fa4381fbf6453aa19b4e..bf7ca4b511fe27cfb4f4d60084bcc40032d058c2 100644 --- a/en/application-dev/reference/apis/js-apis-sensor.md +++ b/en/application-dev/reference/apis/js-apis-sensor.md @@ -24,7 +24,7 @@ Subscribes to data of the color sensor. **System API**: This is a system API. -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -63,7 +63,7 @@ Subscribes to data of the Sodium Adsorption Ratio (SAR) sensor. **System API**: This is a system API. -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -109,7 +109,7 @@ Subscribes to data of the acceleration sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -149,7 +149,7 @@ Subscribes to data of the uncalibrated acceleration sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -190,7 +190,7 @@ Subscribes to data of the ambient light sensor. | 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** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -226,7 +226,7 @@ Subscribes to data of the ambient temperature sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -262,7 +262,7 @@ Subscribes to data of the barometer sensor. | 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** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -298,7 +298,7 @@ Subscribes to data of the gravity sensor. | 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** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -338,7 +338,7 @@ Subscribes to data of the gyroscope sensor. | 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** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -379,7 +379,7 @@ Subscribes to data of the uncalibrated gyroscope sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -420,7 +420,7 @@ Subscribes to data of the Hall effect sensor. | 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** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -458,7 +458,7 @@ Subscribes to data of the heart rate sensor. | 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** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -494,7 +494,7 @@ Subscribes to data of the humidity sensor. | 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** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -533,7 +533,7 @@ Subscribes to data of the linear acceleration sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -571,7 +571,7 @@ Subscribes to data of the magnetic field sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -609,7 +609,7 @@ Subscribes to data of the uncalibrated magnetic field sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -642,7 +642,7 @@ Subscribes to data of the orientation sensor. **System capability**: SystemCapability.Sensors.Sensor -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -682,7 +682,7 @@ Subscribes to data of the pedometer sensor. **System capability**: SystemCapability.Sensors.Sensor -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -729,7 +729,7 @@ Subscribes to data of the pedometer detection sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -765,7 +765,7 @@ Subscribes to data of the proximity sensor. | 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** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -802,7 +802,7 @@ Subscribes to data of the rotation vector sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -842,7 +842,7 @@ Subscribes to data of the significant motion sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -879,7 +879,7 @@ Subscribes to data of the wear detection sensor. | 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. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -918,7 +918,7 @@ Obtains data of the acceleration sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -957,7 +957,7 @@ Obtains data of the uncalibrated acceleration sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -997,7 +997,7 @@ Obtains data of the ambient light sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1032,7 +1032,7 @@ Obtains data of the temperature sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1067,7 +1067,7 @@ Obtains data of the barometer sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1102,7 +1102,7 @@ Obtains data of the gravity sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1141,7 +1141,7 @@ Obtains to data of the gyroscope sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1182,7 +1182,7 @@ Obtains data of the uncalibrated gyroscope sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1222,7 +1222,7 @@ Obtains data of the Hall effect sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1259,7 +1259,7 @@ Obtains data of the heart rate sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1294,7 +1294,7 @@ Obtains data of the humidity sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1331,7 +1331,7 @@ Obtains data of the linear acceleration sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1368,7 +1368,7 @@ Obtains data of the magnetic field sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1405,7 +1405,7 @@ Obtains data of the uncalibrated magnetic field sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1445,7 +1445,7 @@ Obtains data of the orientation sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1484,7 +1484,7 @@ Obtains data of the pedometer sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1521,7 +1521,7 @@ Obtains data of the pedometer sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1556,7 +1556,7 @@ Obtains data of the proximity sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1591,7 +1591,7 @@ Obtains data of the rotation vector sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1629,7 +1629,7 @@ Obtains data of the significant motion sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -1664,7 +1664,7 @@ Obtains data of the wear detection sensor once. | 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.| -**Error code** +**Error codes** For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). @@ -2596,7 +2596,7 @@ Obtains the geomagnetic field of a geographic location at a certain time. This A | timeMillis | number | Yes | Time when the magnetic declination is obtained. The value is a Unix timestamp, in ms.| | callback | AsyncCallback<[GeomagneticResponse](#geomagneticresponse)> | Yes | Callback used to return the geomagnetic field. | -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getGeomagneticInfo](../errorcodes/errorcode-sensor.md). @@ -2647,7 +2647,7 @@ Obtains the geomagnetic field of a geographic location at a certain time. This A | ---------------------------------------------------------- | -------------- | | Promise<[GeomagneticResponse](#geomagneticresponse)> | Promise used to return the geomagnetic field.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getGeomagneticInfo](../errorcodes/errorcode-sensor.md). @@ -2692,7 +2692,7 @@ Obtains the altitude based on the atmospheric pressure. This API uses an asynchr | currentPressure | number | Yes | Specified atmospheric pressure, in hPa.| | callback | AsyncCallback<number> | Yes | Callback used to return the altitude, in meters. | -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getDeviceAltitude](../errorcodes/errorcode-sensor.md). @@ -2739,7 +2739,7 @@ Obtains the altitude based on the atmospheric pressure. This API uses a promise | --------------------- | ------------------------------------ | | Promise<number> | Promise used to return the altitude, in meters.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getDeviceAltitude](../errorcodes/errorcode-sensor.md). @@ -2779,7 +2779,7 @@ Obtains the magnetic dip based on the inclination matrix. This API uses an async | inclinationMatrix | Array<number> | Yes | Inclination matrix. | | callback | AsyncCallback<number> | Yes | Callback used to return the magnetic dip, in radians.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getInclination](../errorcodes/errorcode-sensor.md). @@ -2829,7 +2829,7 @@ Obtains the magnetic dip based on the inclination matrix. This API uses a promis | --------------------- | ---------------------------- | | Promise<number> | Promise used to return the magnetic dip, in radians.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getInclination](../errorcodes/errorcode-sensor.md). @@ -2875,7 +2875,7 @@ Obtains the angle change between two rotation matrices. This API uses an asynchr | preRotationMatrix | Array<number> | Yes | The other rotation matrix. | | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the angle change around the z, x, and y axes.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getAngleVariation](../errorcodes/errorcode-sensor.md). @@ -2936,7 +2936,7 @@ Obtains the angle change between two rotation matrices. This API uses a promise | ---------------------------------- | --------------------------------- | | Promise<Array<number>> | Promise used to return the angle change around the z, x, and y axes.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getAngleVariation](../errorcodes/errorcode-sensor.md). @@ -2990,7 +2990,7 @@ Obtains the rotation matrix from a rotation vector. This API uses an asynchronou | rotationVector | Array<number> | Yes | Rotation vector.| | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation matrix.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3037,7 +3037,7 @@ Obtains the rotation matrix from a rotation vector. This API uses a promise to r | ---------------------------------- | -------------- | | Promise<Array<number>> | Promise used to return the rotation matrix.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3132,7 +3132,7 @@ Transforms a rotation vector based on the coordinate system. This API uses a pro | ---------------------------------- | ---------------------- | | Promise<Array<number>> | Promise used to return the rotation vector after being transformed.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.transformRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3177,7 +3177,7 @@ Obtains the quaternion from a rotation vector. This API uses an asynchronous cal | rotationVector | Array<number> | Yes | Rotation vector.| | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the quaternion. | -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getQuaternion](../errorcodes/errorcode-sensor.md). @@ -3224,7 +3224,7 @@ Obtains the quaternion from a rotation vector. This API uses a promise to return | ---------------------------------- | ------------ | | Promise<Array<number>> | Promise used to return the quaternion.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getQuaternion](../errorcodes/errorcode-sensor.md). @@ -3265,7 +3265,7 @@ Obtains the device direction based on the rotation matrix. This API uses an asyn | rotationMatrix | Array<number> | Yes | Rotation matrix. | | callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation angle around the z, x, and y axes.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getOrientation](../errorcodes/errorcode-sensor.md). @@ -3319,7 +3319,7 @@ Obtains the device direction based on the rotation matrix. This API uses a promi | ---------------------------------- | --------------------------------- | | Promise<Array<number>> | Promise used to return the rotation angle around the z, x, and y axes.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getOrientation](../errorcodes/errorcode-sensor.md). @@ -3365,7 +3365,7 @@ Obtains the rotation matrix based on a gravity vector and geomagnetic vector. Th | geomagnetic | Array<number> | Yes | Geomagnetic vector.| | callback | AsyncCallback<[RotationMatrixResponse](#rotationmatrixresponse)> | Yes | Callback used to return the rotation matrix.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3387,7 +3387,7 @@ try { console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data)); }) } catch (error) { -console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`); + console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`); } ``` @@ -3412,7 +3412,7 @@ Obtains the rotation matrix based on a gravity vector and geomagnetic vector. Th | ------------------------------------------------------------ | -------------- | | Promise<[RotationMatrixResponse](#rotationmatrixresponse)> | Promise used to return the rotation matrix.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). @@ -3451,7 +3451,7 @@ Obtains information about all sensors on the device. This API uses an asynchrono | -------- | ---------------------------------------------- | ---- | ---------------- | | callback | AsyncCallback<Array<[Sensor](#sensor9)>> | Yes | Callback used to return the sensor list.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getSensorList](../errorcodes/errorcode-sensor.md). @@ -3491,7 +3491,7 @@ Obtains information about all sensors on the device. This API uses a promise to | ------- | ---------------------------------------- | ---- | ---------------- | | promise | Promise<Array<[Sensor](#sensor9)>> | Yes | Promise used to return the sensor list.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getSensorList](../errorcodes/errorcode-sensor.md). @@ -3530,7 +3530,7 @@ Obtains information about the sensor of a specific type. This API uses an asynch | type | [SensorId](#sensorid9) | Yes | Sensor type. | | callback | AsyncCallback<[Sensor](#sensor9)> | Yes | Callback used to return the sensor information.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getSingleSensor](../errorcodes/errorcode-sensor.md). @@ -3574,7 +3574,7 @@ Obtains information about the sensor of a specific type. This API uses a promise | ------- | --------------------------------- | ---- | ---------------- | | promise | Promise<[Sensor](#sensor9)> | Yes | Promise used to return the sensor information.| -**Error code** +**Error codes** For details about the following error codes, see [Error Codes of sensor.getSingleSensor](../errorcodes/errorcode-sensor.md). @@ -3612,6 +3612,8 @@ Enumerates the sensor types. | HALL | 10 | Hall effect sensor. | | PROXIMITY | 12 | Proximity sensor. | | HUMIDITY | 13 | Humidity sensor. | +| COLOR10+ | 14 | Color sensor.
System API: This is a system API. | +| SAR10+ | 15 | Sodium Adsorption Ratio (SAR) sensor.
System API: This is a system API.| | ORIENTATION | 256 | Orientation sensor. | | GRAVITY | 257 | Gravity sensor. | | LINEAR_ACCELEROMETER | 258 | Linear acceleration sensor. | @@ -4912,7 +4914,7 @@ 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** - + ```ts sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function (data) { console.info('Succeeded in invoking once. Steps: ' + data.steps); @@ -6211,7 +6213,7 @@ promise.then((data) => { }).catch((reason) => { console.info("Succeeded in getting promise::catch", reason); }) -``` + ``` ## sensor.createQuaternion(deprecated) @@ -6410,4 +6412,4 @@ promise.then((data) => { }).catch((err) => { console.info(`Failed to get promise.`); }) - ``` +```