diff --git a/en/application-dev/media/audio-overview.md b/en/application-dev/media/audio-overview.md index 5aac5895bc5d0fc7db7ae0351095b1acf265f8e0..c313e9315eb46c440efb116e318148a666d44012 100755 --- a/en/application-dev/media/audio-overview.md +++ b/en/application-dev/media/audio-overview.md @@ -1,8 +1,8 @@ # Audio Overview -OpenHarmony provides the audio module for your application to implement audio-related features, including audio playback and volume management. +You can use APIs provided by the audio module to implement audio-related features, including audio playback and volume management. ->![](../public_sys-resources/icon-note.gif) **NOTE:** +>![](../public_sys-resources/icon-note.gif) **NOTE** >Due to permission issues, the above features are temporarily unavailable for the standard system. ## Basic Concepts diff --git a/en/application-dev/reference/apis/js-apis-sensor.md b/en/application-dev/reference/apis/js-apis-sensor.md index 440a79eab1934eba07f7ca2c90cdc20c96fafe62..8b9cf97f184547b9f5ce59da96bf85a6021bee55 100644 --- a/en/application-dev/reference/apis/js-apis-sensor.md +++ b/en/application-dev/reference/apis/js-apis-sensor.md @@ -1,6 +1,6 @@ # Sensor -> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -1172,9 +1172,72 @@ Unsubscribes from sensor data changes. console.info("Succeeded in unsubscribing from acceleration sensor data."); } ); - ``` +## sensor.transformCoordinateSystem + +transformCoordinateSystem(inRotationVector: Array<number>, coordinates: CoordinatesOptions, callback: AsyncCallback<Array<number>>): void + +Rotates a rotation vector so that it can represent the coordinate system in different ways. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | ---------------- | ----------------------------------------- | ---- | ---------------------- | + | inRotationVector | Array<number> | Yes| Rotation vector to rotate.| + | coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes| Direction of the coordinate system.| + | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the rotation vector after being rotated.| + +- Example + + ``` + sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {'axisX':2, 'axisY':3}, function(err, data) { + if (err) { + console.error("Operation failed. Error code: " + err.code + ", message: " + err.message); + return; + } + console.info("Operation successed. Data obtained: " + data.x); + for (var i=0; i < data.length; i++) { + console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]); + } + }) + ``` + +## sensor.transformCoordinateSystem + +transformCoordinateSystem(inRotationVector: Array<number>, coordinates: CoordinatesOptions): Promise<Array<number>> + +Rotates a rotation vector so that it can represent the coordinate system in different ways. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | ---------------- | ----------------------------------------- | ---- | ---------------- | + | inRotationVector | Array<number> | Yes| Rotation vector to rotate.| + | coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes| Direction of the coordinate system.| + +- Return value + + | Type| Description| + | ---------------------------------- | ---------------------- | + | Promise<Array<number>> | Promise used to return the rotation vector after being converted.| + +- Example + + ``` + const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {'axisX':2, 'axisY':3}); + promise.then((data) => { + console.info("Operation successed."); + for (var i=0; i < data.length; i++) { + console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]); + } + }).catch((err) => { + console.info("Operation failed"); + }) + ``` + + + ## sensor.getGeomagneticField @@ -1207,7 +1270,7 @@ Obtains the geomagnetic field of a geographic location. This method uses a callb getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise<GeomagneticResponse> -Obtains the geomagnetic field of a geographic location. This method uses a callback to return the result. +Obtains the geomagnetic field of a geographic location. This method uses a promise to return the result. - Parameters | Name| Type| Mandatory| Description| @@ -1218,7 +1281,7 @@ Obtains the geomagnetic field of a geographic location. This method uses a callb - Return value | Type| Description| | -------- | -------- | - | Promise<[GeomagneticResponse](#geomagneticresponse)> | Callback used to return the geomagnetic field.| + | Promise<[GeomagneticResponse](#geomagneticresponse)> | Promise used to return the geomagnetic field.| - Example ``` @@ -1232,6 +1295,437 @@ Obtains the geomagnetic field of a geographic location. This method uses a callb }) ``` +## sensor.getAltitude + +getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback<number>): void + +Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | --------------- | --------------------------- | ---- | ------------------------------------- | + | seaPressure | number | Yes| Sea-level atmospheric pressure, in hPa.| + | currentPressure | number | Yes| Current atmospheric pressure at the altitude where the device is located, in hPa.| + | callback | AsyncCallback<number> | Yes| Callback used to return the altitude, in meters.| + +- Example + + ``` + sensor.getAltitude(0, 200, function(err, data) { + if (err) { + console.error( + "Operation failed. Error code: " + err.code + ", message: " + err.message); + return; + } + console.info("Successed to get getAltitude interface get data: " + data); + }); + ``` + +## sensor.getAltitude + +getAltitude(seaPressure: number, currentPressure: number): Promise<number> + +Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | --------------- | ------ | ---- | ------------------------------------- | + | seaPressure | number | Yes| Sea-level atmospheric pressure, in hPa.| + | currentPressure | number | Yes| Atmospheric pressure at the altitude where the device is located, in hPa.| + +- Return value + + | Type| Description| + | --------------------- | ------------------------------------ | + | Promise<number> | Promise used to return the altitude, in meters.| + +- Example + + ``` + const promise = sensor.getAltitude(0, 200); + promise.then((data) => { + console.info(' sensor_getAltitude_Promise success', data); + }).catch((err) => { + console.error("Operation failed"); + }) + ``` + + +## sensor.getGeomagneticDip + +getGeomagneticDip(inclinationMatrix: Array<number>, callback: AsyncCallback<number>): void + +Obtains the magnetic dip based on the inclination matrix. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | ----------------- | --------------------------- | ---- | ---------------------------- | + | inclinationMatrix | Array<number> | Yes| Inclination matrix.| + | callback | AsyncCallback<number> | Yes| Callback used to return the magnetic dip, in radians.| + +- Example + + ``` + sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data) { + if (err) { + console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + + err.message); + return; + } + console.info(Successed to get getGeomagneticDip interface get data: " + data); + }) + ``` + +## sensor.getGeomagneticDip + +getGeomagneticDip(inclinationMatrix: Array<number>): Promise<number> + +Obtains the magnetic dip based on the inclination matrix. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | ----------------- | ------------------- | ---- | -------------- | + | inclinationMatrix | Array<number> | Yes| Inclination matrix.| + +- Return value + + | Type| Description| + | --------------------- | ---------------------------- | + | Promise<number> | Promise used to return the magnetic dip, in radians.| + +- Example + + ``` + const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]); + promise.then((data) => { + console.info(' getGeomagneticDip_promise successed', data); + }).catch((err) => { + console.error("Operation failed"); + }) + ``` + +## sensor. getAngleModify + +getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>, callback: AsyncCallback<Array<number>>): void + +Obtains the angle change between two rotation matrices. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | --------------------- | ---------------------------------------- | ---- | --------------------------------- | + | currentRotationMatrix | Array<number> | Yes| Current rotation matrix.| + | 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.| + +- Example + + ``` + sensor. getAngleModify([1,0,0,0,1,0,0,0,1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function(err, data) { + if (err) { + console.error(LABEL + 'Failed to register data, error code is: ' + err.code + ', message: ' + + err.message); + return; + } + console.info("SensorJsAPI--->Successed to get getAngleModifiy interface get data: " + data.x); + for (var i=0; i < data.length; i++) { + console.info(LABEL + "data[" + i + "]: " + data[i]); + } + }) + ``` + + +## sensor. getAngleModify + +getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>): Promise<Array<number>> + +Obtains the angle change between two rotation matrices. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | --------------------- | ------------------- | ---- | ------------------ | + | currentRotationMatrix | Array<number> | Yes| Current rotation matrix.| + | preRotationMatrix | Array<number> | Yes| The other rotation matrix.| + +- Return value + + | Type| Description| + | ---------------------------------- | --------------------------------- | + | Promise<Array<number>> | Promise used to return the angle change around the z, x, and y axes.| + +- Example + + ``` + const promise = sensor.getAngleModify([1,0,0,0,1,0,0,0,1], [1,0,0,0,0.87,-0.50,0,0.50,0.87]); + promise.then((data) => { + console.info(LABEL + 'getAngleModifiy_promise success'); + for (var i=0; i < data.length; i++) { + console.info(LABEL + "data[" + i + "]: " + data[i]); + } + }).catch((reason) => { + console.info(LABEL + "promise::catch", reason); + }) + ``` + + +## sensor.createRotationMatrix + +createRotationMatrix(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void + +Converts a rotation vector into a rotation matrix. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------------- | ---------------------------------------- | ---- | -------------- | + | rotationVector | Array<number> | Yes| Rotation vector to convert.| + | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the rotation matrix.| + +- Example + + ``` + sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) { + if (err) { + console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + + err.message); + return; + } + console.info("SensorJsAPI--->Successed to get createRotationMatrix interface get data: " + data.x); + for (var i=0; i < data.length; i++) { + console.info(LABEL + "data[" + i + "]: " + data[i]); + } + }) + ``` + + +## sensor.createRotationMatrix + +createRotationMatrix(rotationVector: Array<number>): Promise<Array<number>> + +Converts a rotation vector into a rotation matrix. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------------- | ------------------- | ---- | -------------- | + | rotationVector | Array<number> | Yes| Rotation vector to convert.| + +- Return value + + | Type| Description| + | ---------------------------------- | -------------- | + | Promise<Array<number>> | Promise used to return the rotation matrix.| + +- Example + + ``` + const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]); + promise.then((data) => { + console.info(LABEL + 'createRotationMatrix_promise success'); + for (var i=0; i < data.length; i++) { + console.info(LABEL + "data[" + i + "]: " + data[i]); + } + }).catch((reason) => { + console.info(LABEL + "promise::catch", reason); + }) + ``` + + +## sensor.createQuaternion + +createQuaternion(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void + +Converts a rotation vector into a quaternion. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------------- | ---------------------------------------- | ---- | -------------- | + | rotationVector | Array<number> | Yes| Rotation vector to convert.| + | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the quaternion.| + +- Example + + ``` + sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) { + if (err) { + console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + + err.message); + return; + } + console.info("SensorJsAPI--->Successed to get createQuaternion interface get data: " + data.x); + for (var i=0; i < data.length; i++) { + console.info(LABEL + "data[" + i + "]: " + data[i]); + } + }) + ``` + + +## sensor.createQuaternion + +createQuaternion(rotationVector: Array<number>): Promise<Array<number>> + +Converts a rotation vector into a quaternion. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------------- | ------------------- | ---- | -------------- | + | rotationVector | Array<number> | Yes| Rotation vector to convert.| + +- Return value + + | Type| Description| + | ---------------------------------- | ------------ | + | Promise<Array<number>> | Promise used to return the quaternion.| + +- Example + + ``` + const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]); + promise.then((data) => { + console.info('createQuaternion_promise successed'); + for (var i=0; i < data.length; i++) { + console.info(LABEL + "data[" + i + "]: " + data[i]); + } + }).catch((err) => { + console.info('promise failed'); + }) + ``` + + +## sensor.getDirection + +getDirection(rotationMatrix: Array<number>, callback: AsyncCallback<Array<number>>): void + +Obtains the device direction based on the rotation matrix. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------------- | ---------------------------------------- | ---- | --------------------------------- | + | 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.| + +- Example + + ``` + sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data) { + if (err) { + console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + + err.message); + return; + } + console.info(LABEL + "SensorJsAPI--->Successed to get getDirection interface get data: " + data.x); + for (var i = 1; i < data.length; i++) { + console.info(TAG +"sensor_getDirection_callback" + data[i]); + } + }) + ``` + + +## sensor.getDirection + +getDirection(rotationMatrix: Array<number>): Promise<Array<number>> + +Obtains the device direction based on the rotation matrix. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------------- | ------------------- | ---- | -------------- | + | rotationMatrix | Array<number> | Yes| Rotation matrix.| + +- Return value + + | Type| Description| + | ---------------------------------- | --------------------------------- | + | Promise<Array<number>> | Promise used to return the rotation angle around the z, x, and y axes.| + +- Example + + ``` + const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]); + promise.then((data) => { + console.info(' sensor_getAltitude_Promise success', data.x); + for (var i = 1; i < data.length; i++) { + console.info(TAG +"sensor_getDirection_promise" + data[i]); + } + }).catch((err) => { + console.info('promise failed'); + }) + ``` + + +## sensor.createRotationMatrix + +createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>, callback: AsyncCallback<RotationMatrixResponse>): void + +Creates a rotation matrix based on the gravity vector and geomagnetic vector. This method uses a callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | ----------- | ------------------------------------------------------------ | ---- | -------------- | + | gravity | Array<number> | Yes| Gravity vector.| + | geomagnetic | Array<number> | Yes| Geomagnetic vector.| + | callback | AsyncCallback<[RotationMatrixResponse](#rotationmatrixresponse)> | Yes| Callback used to return the rotation matrix.| + +- Example + + ``` + sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data) { + if (err) { + console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + + err.message); + return; + } + console.info("SensorJsAPI--->Successed to get createRotationMatrix interface get data: " + data.x); + for (var i=0; i < data.length; i++) { + console.info(LABEL + "data[" + i + "]: " + data[i]) + } + }) + ``` + + +## sensor.createRotationMatrix + +createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>,): Promise<RotationMatrixResponse> + +Creates a rotation matrix based on the gravity vector and geomagnetic vector. This method uses a promise to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | ----------- | ------------------- | ---- | -------------- | + | gravity | Array<number> | Yes| Gravity vector.| + | geomagnetic | Array<number> | Yes| Geomagnetic vector.| + +- Return value + + | Type| Description| + | ------------------------------------------------------------ | -------------- | + | Promise<[RotationMatrixResponse](#rotationmatrixresponse)> | Promise used to return the rotation matrix.| + +- Example + + ``` + const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]); + promise.then((data) => { + console.info(LABEL + 'createRotationMatrix_promise successed'); + for (var i=0; i < data.length; i++) { + console.info(LABEL + "data[" + i + "]: " + data[i]); + } + }).catch((err) => { + console.info(LABEL + 'promise failed'); + }) + ``` + ## SensorType @@ -1519,6 +2013,25 @@ Describes the sensor data reporting frequency. | -------- | -------- | -------- | | interval | number | Frequency at which a sensor reports data. The default value is 200,000,000 ns.| +## RotationMatrixResponse + +Describes the response for setting the rotation matrix. + +| Name| Type| Readable| Writable| Description| +| ----------- | ------------------- | ---- | ---- | ---------- | +| rotation | Array<number> | Yes| Yes| Rotation matrix.| +| inclination | Array<number> | Yes| Yes| Inclination matrix.| + + +## CoordinatesOptions + +Describes the coordinate options. + +| Name| Type| Readable| Writable| Description| +| ---- | -------- | ---- | ---- | ----------- | +| x | number | Yes| Yes| X coordinate direction.| +| y | number | Yes| Yes| Y coordinate direction.| + ## GeomagneticResponse diff --git a/zh-cn/application-dev/reference/apis/js-apis-sensor.md b/zh-cn/application-dev/reference/apis/js-apis-sensor.md index 660c64edcd258e76548e2299655ad61f6f7ac9b5..315cf74f9f2439e245b012adfa5a588b834ad1a3 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-sensor.md +++ b/zh-cn/application-dev/reference/apis/js-apis-sensor.md @@ -1450,7 +1450,7 @@ getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Ar | 参数名 | 类型 | 必填 | 说明 | | --------------------- | ------------------- | ---- | ------------------ | | currentRotationMatrix | Array<number> | 是 | 表示当前旋转矩阵。 | - | preRotationMatrix | Array<number> | 是 | 表示当前旋转矩阵。 | + | preRotationMatrix | Array<number> | 是 | 表示旋转矩阵。 | - 返回值