From 157c3cd7cd8dcfd07b0de3d446caafc1b0f6f7fc Mon Sep 17 00:00:00 2001 From: cff-gite Date: Wed, 13 Apr 2022 17:25:58 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- README.md | 7 ++++--- README_zh.md | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 480a59f7..70b35f2d 100755 --- a/README.md +++ b/README.md @@ -120,17 +120,17 @@ The sensor JS APIs listen for sensor data changes. If an API is called multiple -

on(type: SensorType, callback: AsyncCallback<Response>, options?: Options)

+

on(type: SensorType, callback: Callback<Response>, options?: Options)

Subscribes to a type of sensor that listens for changes of sensor data. SensorType indicates the type of the sensor that can be subscribed to. callback specifies whether the subscription is successful. options indicates the interval for reporting sensor data.

-

once(type: SensorType, callback: AsyncCallback<Response>)

+

once(type: SensorType, callback: Callback<Response>)

Subscribes to a type of sensor that listens for the sensor data change once. SensorType indicates the type of the sensor that can be subscribed to. callback specifies whether the subscription is successful.

-

off(type: SensorType, callback: AsyncCallback<void>)

+

off(type: SensorType, callback: Callback<void>)

Unsubscribes from a type of sensor that listens for data changes. SensorType indicates the type of the sensor that can be unsubscribed from. callback specifies whether the unsubscription is successful.

@@ -138,6 +138,7 @@ The sensor JS APIs listen for sensor data changes. If an API is called multiple + ### How to Use 1. Import the sensor package. diff --git a/README_zh.md b/README_zh.md index 62323e6e..80db8271 100755 --- a/README_zh.md +++ b/README_zh.md @@ -120,17 +120,17 @@ sensor导入模块的示例代码如下: -

on(type: SensorType, callback: AsyncCallback<Response>, options?: Options)

+

on(type: SensorType, callback: Callback<Response>, options?: Options)

监听传感器数据变化。SensorType为支持订阅的传感器类型,callback表示订阅传感器的回调函数,options为设置传感器数据上报的时间间隔。

-

once(type: SensorType, callback: AsyncCallback<Response>)

+

once(type: SensorType, callback: Callback<Response>)

监听传感器数据变化一次。SensorType为支持订阅的传感器类型,callback表示订阅传感器的回调函数。

-

off(type: SensorType, callback: AsyncCallback<void>)

+

off(type: SensorType, callback: Callback<void>)

取消订阅传感器数据。SensorType为支持的取消订阅的传感器类型,callback表示取消订阅传感器是否成功。

@@ -138,6 +138,7 @@ sensor导入模块的示例代码如下: + ### 使用说明 1. 导包。 -- Gitee From 96b24365384a0f481ae421953b6f4d29996c51d7 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Thu, 14 Apr 2022 10:07:57 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- README.md | 23 ++++++----------------- README_zh.md | 23 ++++++----------------- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 70b35f2d..d08b10c7 100755 --- a/README.md +++ b/README.md @@ -154,29 +154,18 @@ import sensor from '@ohos.sensor'; export default { onCreate() { // Step 2 Subscribe to and listen for data changes of a type of sensor. - sensor.on(sensor.SENSOR_TYPE_ID_ACCELEROMETER, (error, data) => { - if (error) { - console.error("Failed to subscribe to acceleration data. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); }, {'interval':200000000}); // Step 3 Unsubscribe from data changes of the sensor 10 seconds later. setTimeout(function(){ - sensor.off(sensor.SENSOR_TYPE_ID_ACCELEROMETER, function(error) { - if (error) { - console.error("Failed to unsubscribe from acceleration data. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info("Succeeded in unsubscribe from sensor data"); - }); + function callback(data) { + console.info("Succeeded in unsubscribe from sensor data" + data); + } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback); } ,10000); // Step 4 Subscribe to and listen for a data change of a type of sensor. - sensor.once(sensor.SENSOR_TYPE_ID_ACCELEROMETER, (error, data) => { - if (error) { - console.error("Failed to subscribe to gravity data. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); }); } diff --git a/README_zh.md b/README_zh.md index 80db8271..e2ba91c6 100755 --- a/README_zh.md +++ b/README_zh.md @@ -154,29 +154,18 @@ import sensor from '@ohos.sensor'; export default { onCreate() { //步骤2 监听传感器数据变化,并注册传感器类型 - sensor.on(sensor.SENSOR_TYPE_ID_ACCELEROMETER, (error, data) => { - if (error) { - console.error("Failed to subscribe to acceleration data. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); }, {'interval':200000000}); //步骤3 设置10秒后取消订阅传感器数据 setTimeout(function(){ - sensor.off(sensor.SENSOR_TYPE_ID_ACCELEROMETER, function(error) { - if (error) { - console.error("Failed to unsubscribe from acceleration data. Error code: " + error.code + "; message: " + error.message); - return; - } - console.info("Succeeded in unsubscribe from sensor data"); - }); + function callback(data) { + console.info("Succeeded in unsubscribe from sensor data" + data); + } + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback); } ,10000); //步骤4 监听传感器数据变化一次,并注册传感器类型 - sensor.once(sensor.SENSOR_TYPE_ID_ACCELEROMETER, (error, data) => { - if (error) { - console.error("Failed to subscribe to gravity data. Error code: " + error.code + "; message: " + error.message); - return; - } + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); }); } -- Gitee From 07d8156311a70b738c338b9aa5dad2390b98b854 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 18 Apr 2022 14:11:28 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- README.md | 3 ++- README_zh.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d08b10c7..07e383e2 100755 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ The sensor JS APIs listen for sensor data changes. If an API is called multiple

Subscribes to a type of sensor that listens for the sensor data change once. SensorType indicates the type of the sensor that can be subscribed to. callback specifies whether the subscription is successful.

-

off(type: SensorType, callback: Callback<void>)

+

off(type: SensorType, callback: Callback<Response>)

Unsubscribes from a type of sensor that listens for data changes. SensorType indicates the type of the sensor that can be unsubscribed from. callback specifies whether the unsubscription is successful.

@@ -139,6 +139,7 @@ The sensor JS APIs listen for sensor data changes. If an API is called multiple + ### How to Use 1. Import the sensor package. diff --git a/README_zh.md b/README_zh.md index e2ba91c6..a82a80af 100755 --- a/README_zh.md +++ b/README_zh.md @@ -130,7 +130,7 @@ sensor导入模块的示例代码如下:

监听传感器数据变化一次。SensorType为支持订阅的传感器类型,callback表示订阅传感器的回调函数。

-

off(type: SensorType, callback: Callback<void>)

+

off(type: SensorType, callback: Callback<Response>)

取消订阅传感器数据。SensorType为支持的取消订阅的传感器类型,callback表示取消订阅传感器是否成功。

@@ -139,6 +139,7 @@ sensor导入模块的示例代码如下: + ### 使用说明 1. 导包。 -- Gitee From 123b9b8de7d8e9cc2f8f0343873788f4a52f5ff9 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 18 Apr 2022 15:41:33 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- README.md | 2 +- README_zh.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 07e383e2..3928f8df 100755 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ export default { function callback(data) { console.info("Succeeded in unsubscribe from sensor data" + data); } - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER); } ,10000); // Step 4 Subscribe to and listen for a data change of a type of sensor. sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { diff --git a/README_zh.md b/README_zh.md index a82a80af..660e0783 100755 --- a/README_zh.md +++ b/README_zh.md @@ -163,7 +163,7 @@ export default { function callback(data) { console.info("Succeeded in unsubscribe from sensor data" + data); } - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER); } ,10000); //步骤4 监听传感器数据变化一次,并注册传感器类型 sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { -- Gitee From e3650b0da87113c00f458ba7ab3d5ad517eec4f5 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Mon, 18 Apr 2022 16:38:47 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- README.md | 9 +++------ README_zh.md | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3928f8df..9ee46123 100755 --- a/README.md +++ b/README.md @@ -159,12 +159,9 @@ export default { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); }, {'interval':200000000}); // Step 3 Unsubscribe from data changes of the sensor 10 seconds later. - setTimeout(function(){ - function callback(data) { - console.info("Succeeded in unsubscribe from sensor data" + data); - } - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER); - } ,10000); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, (data) => { + console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); + }); // Step 4 Subscribe to and listen for a data change of a type of sensor. sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); diff --git a/README_zh.md b/README_zh.md index 660e0783..1913c5e1 100755 --- a/README_zh.md +++ b/README_zh.md @@ -159,12 +159,9 @@ export default { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); }, {'interval':200000000}); //步骤3 设置10秒后取消订阅传感器数据 - setTimeout(function(){ - function callback(data) { - console.info("Succeeded in unsubscribe from sensor data" + data); - } - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER); - } ,10000); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, (data) => { + console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); + }); //步骤4 监听传感器数据变化一次,并注册传感器类型 sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); -- Gitee From ccff92d0e893c0346993084a421b208f83d00469 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 19 Apr 2022 09:35:41 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- README.md | 4 +--- README_zh.md | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9ee46123..fe90d5a7 100755 --- a/README.md +++ b/README.md @@ -159,9 +159,7 @@ export default { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); }, {'interval':200000000}); // Step 3 Unsubscribe from data changes of the sensor 10 seconds later. - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, (data) => { - console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); - }); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION); // Step 4 Subscribe to and listen for a data change of a type of sensor. sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); diff --git a/README_zh.md b/README_zh.md index 1913c5e1..b9006123 100755 --- a/README_zh.md +++ b/README_zh.md @@ -159,9 +159,7 @@ export default { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); }, {'interval':200000000}); //步骤3 设置10秒后取消订阅传感器数据 - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, (data) => { - console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); - }); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION); //步骤4 监听传感器数据变化一次,并注册传感器类型 sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data) => { console.info("Acceleration data obtained. x: " + data.x + "; y: " + data.y + "; z: " + data.z); -- Gitee