提交 80756b25 编写于 作者: L li-yaoyao777

整改docs规范扫描

Signed-off-by: Nli-yaoyao777 <liyaoyao7@huawei.com>
上级 6bf41849
...@@ -33,10 +33,11 @@ ...@@ -33,10 +33,11 @@
2. 以下场景以加速度传感器ACCELEROMETER为例。展示持续监听传感器接口的调用结果。 2. 以下场景以加速度传感器ACCELEROMETER为例。展示持续监听传感器接口的调用结果。
```js ```ts
import sensor from "@ohos.sensor"; 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); // 获取数据成功 sensor.on(sensor.SensorId.ACCELEROMETER, function (data) {
console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // 获取数据成功
}); });
``` ```
...@@ -44,7 +45,7 @@ ...@@ -44,7 +45,7 @@
3. 注销传感器数据监听。 3. 注销传感器数据监听。
```js ```ts
import sensor from "@ohos.sensor"; import sensor from "@ohos.sensor";
sensor.off(sensor.SensorId.ACCELEROMETER); sensor.off(sensor.SensorId.ACCELEROMETER);
``` ```
...@@ -53,10 +54,11 @@ ...@@ -53,10 +54,11 @@
4. 获取一次传感器数据变化。 4. 获取一次传感器数据变化。
```js ```ts
import sensor from "@ohos.sensor"; 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); // 获取数据成功 sensor.once(sensor.SensorId.ACCELEROMETER, function (data) {
console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // 获取数据成功
}); });
``` ```
...@@ -64,15 +66,16 @@ ...@@ -64,15 +66,16 @@
若接口调用不成功,建议使用try/catch语句捕获代码中可能出现的错误信息。例如: 若接口调用不成功,建议使用try/catch语句捕获代码中可能出现的错误信息。例如:
```js ```ts
import sensor from "@ohos.sensor"; import sensor from "@ohos.sensor";
try {
sensor.once(sensor.SensorId.ACCELEROMETER, function(data) { try {
console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // 获取数据成功 sensor.once(sensor.SensorId.ACCELEROMETER, function (data) {
}); console.info("Succeeded in obtaining data. x: " + data.x + "y: " + data.y + "z: " + data.z); // 获取数据成功
} catch (error) { });
console.error("Get sensor data error. data:" + error.data, " msg:", error.message); } catch (error) {
} console.error(`Failed to get sensor data. Code: ${error.code}, message: ${error.message}`);
}
``` ```
## 相关实例 ## 相关实例
......
...@@ -37,16 +37,16 @@ import sensor from '@system.sensor'; ...@@ -37,16 +37,16 @@ import sensor from '@system.sensor';
**示例:** **示例:**
```js ```ts
sensor.subscribeAccelerometer({ sensor.subscribeAccelerometer({
interval: 'normal', interval: 'normal',
success: function(ret) { success: function (ret) {
console.log('X-axis data: ' + ret.x); console.info('Succeeded in subscribing. X-axis data: ' + ret.x);
console.log('Y-axis data: ' + ret.y); console.info('Succeeded in subscribing. Y-axis data: ' + ret.y);
console.log('Z-axis data: ' + ret.z); console.info('Succeeded in subscribing. Z-axis data: ' + ret.z);
}, },
fail: function(data, code) { fail: function (data, code) {
console.error('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
}, },
}); });
``` ```
...@@ -66,7 +66,7 @@ unsubscribeAccelerometer(): void ...@@ -66,7 +66,7 @@ unsubscribeAccelerometer(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeAccelerometer(); sensor.unsubscribeAccelerometer();
``` ```
...@@ -86,13 +86,13 @@ sensor.unsubscribeAccelerometer(); ...@@ -86,13 +86,13 @@ sensor.unsubscribeAccelerometer();
**示例:** **示例:**
```js ```ts
sensor.subscribeCompass({ sensor.subscribeCompass({
success: function(ret) { success: function (ret) {
console.log('Get data direction:' + ret.direction); console.info('Succeeded in subscribing. Get data direction:' + ret.direction);
}, },
fail: function(data, code) { fail: function (data, code) {
console.error('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
}, },
}); });
``` ```
...@@ -110,7 +110,7 @@ unsubscribeCompass(): void ...@@ -110,7 +110,7 @@ unsubscribeCompass(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeCompass(); sensor.unsubscribeCompass();
``` ```
...@@ -130,13 +130,14 @@ sensor.unsubscribeCompass(); ...@@ -130,13 +130,14 @@ sensor.unsubscribeCompass();
**示例:** **示例:**
```js ```ts
sensor.subscribeProximity({ sensor.subscribeProximity({
success: function(ret) { success: function (ret) {
console.log('Get data distance:' + ret.distance); console.info('Succeeded in subscribing. Get data distance:' + ret.distance);
}, },
fail: function(data, code) { fail: function (data, code) {
console.error('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
}, },
}); });
``` ```
...@@ -154,7 +155,7 @@ unsubscribeProximity(): void ...@@ -154,7 +155,7 @@ unsubscribeProximity(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeProximity(); sensor.unsubscribeProximity();
``` ```
...@@ -174,13 +175,13 @@ sensor.unsubscribeProximity(); ...@@ -174,13 +175,13 @@ sensor.unsubscribeProximity();
**示例:** **示例:**
```js ```ts
sensor.subscribeLight({ sensor.subscribeLight({
success: function(ret) { success: function (ret) {
console.log('Get data intensity:' + ret.intensity); console.info('Succeeded in subscribing. Get data intensity:' + ret.intensity);
}, },
fail: function(data, code) { fail: function (data, code) {
console.error('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
}, },
}); });
``` ```
...@@ -198,7 +199,7 @@ unsubscribeLight(): void ...@@ -198,7 +199,7 @@ unsubscribeLight(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeLight(); sensor.unsubscribeLight();
``` ```
...@@ -220,13 +221,13 @@ sensor.unsubscribeLight(); ...@@ -220,13 +221,13 @@ sensor.unsubscribeLight();
**示例:** **示例:**
```js ```ts
sensor.subscribeStepCounter({ sensor.subscribeStepCounter({
success: function(ret) { success: function (ret) {
console.log('Get step value:' + ret.steps); console.info('Succeeded in subscribing. Get step value:' + ret.steps);
}, },
fail: function(data, code) { fail: function (data, code) {
console.log('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
}, },
}); });
``` ```
...@@ -246,7 +247,7 @@ unsubscribeStepCounter(): void ...@@ -246,7 +247,7 @@ unsubscribeStepCounter(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeStepCounter(); sensor.unsubscribeStepCounter();
``` ```
...@@ -267,13 +268,13 @@ subscribeBarometer(options: SubscribeBarometerOptions): void ...@@ -267,13 +268,13 @@ subscribeBarometer(options: SubscribeBarometerOptions): void
**示例:** **示例:**
```js ```ts
sensor.subscribeBarometer({ sensor.subscribeBarometer({
success: function(ret) { success: function (ret) {
console.log('Get data value:' + ret.pressure); console.info('Succeeded in subscribing. Get data value:' + ret.pressure);
}, },
fail: function(data, code) { fail: function (data, code) {
console.log('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
}, },
}); });
``` ```
...@@ -292,7 +293,7 @@ unsubscribeBarometer(): void ...@@ -292,7 +293,7 @@ unsubscribeBarometer(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeBarometer(); sensor.unsubscribeBarometer();
``` ```
...@@ -315,13 +316,13 @@ sensor.unsubscribeBarometer(); ...@@ -315,13 +316,13 @@ sensor.unsubscribeBarometer();
**示例:** **示例:**
```js ```ts
sensor.subscribeHeartRate({ sensor.subscribeHeartRate({
success: function(ret) { success: function (ret) {
console.log('Get heartrate value:' + ret.heartRate); console.info('Succeeded in subscribing. Get heartrate value:' + ret.heartRate);
}, },
fail: function(data, code) { fail: function (data, code) {
console.log('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
}, },
}); });
``` ```
...@@ -342,7 +343,7 @@ unsubscribeHeartRate(): void ...@@ -342,7 +343,7 @@ unsubscribeHeartRate(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeHeartRate(); sensor.unsubscribeHeartRate();
``` ```
...@@ -362,13 +363,13 @@ sensor.unsubscribeHeartRate(); ...@@ -362,13 +363,13 @@ sensor.unsubscribeHeartRate();
**示例:** **示例:**
```js ```ts
sensor.subscribeOnBodyState({ sensor.subscribeOnBodyState({
success: function(ret) { success: function (ret) {
console.log('Get on-body state value:' + ret.value); console.info('Succeeded in subscribing. Get on-body state value:' + ret.value);
}, },
fail: function(data, code) { fail: function (data, code) {
console.log('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
}, },
}); });
``` ```
...@@ -386,7 +387,7 @@ unsubscribeOnBodyState(): void ...@@ -386,7 +387,7 @@ unsubscribeOnBodyState(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeOnBodyState(); sensor.unsubscribeOnBodyState();
``` ```
...@@ -406,13 +407,13 @@ sensor.unsubscribeOnBodyState(); ...@@ -406,13 +407,13 @@ sensor.unsubscribeOnBodyState();
**示例:** **示例:**
```js ```ts
sensor.getOnBodyState({ sensor.getOnBodyState({
success: function(ret) { success: function (ret) {
console.log('On body state: ' + ret.value); console.info('Succeeded in subscribing. On body state: ' + ret.value);
}, },
fail: function(data, code) { fail: function (data, code) {
console.log('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
}, },
}); });
``` ```
...@@ -435,17 +436,17 @@ sensor.getOnBodyState({ ...@@ -435,17 +436,17 @@ sensor.getOnBodyState({
**示例:** **示例:**
```js ```ts
sensor.subscribeDeviceOrientation({ sensor.subscribeDeviceOrientation({
interval: 'normal', interval: 'normal',
success: function(ret) { success: function (ret) {
console.log('Alpha data: ' + ret.alpha); console.info('Succeeded in subscribing. Alpha data: ' + ret.alpha);
console.log('Beta data: ' + ret.beta); console.info('Succeeded in subscribing. Beta data: ' + ret.beta);
console.log('Gamma data: ' + ret.gamma); console.info('Succeeded in subscribing. Gamma data: ' + ret.gamma);
}, },
fail: function(data, code) { fail: function (data, code) {
console.error('Subscription failed. Code: ' + code + '; Data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
} }
}); });
``` ```
...@@ -462,7 +463,7 @@ unsubscribeDeviceOrientation(): void ...@@ -462,7 +463,7 @@ unsubscribeDeviceOrientation(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeDeviceOrientation(); sensor.unsubscribeDeviceOrientation();
``` ```
...@@ -486,16 +487,16 @@ sensor.unsubscribeDeviceOrientation(); ...@@ -486,16 +487,16 @@ sensor.unsubscribeDeviceOrientation();
**示例:** **示例:**
```js ```ts
sensor.subscribeGyroscope({ sensor.subscribeGyroscope({
interval: 'normal', interval: 'normal',
success: function(ret) { success: function (ret) {
console.log('X-axis data: ' + ret.x); console.info('Succeeded in subscribing. X-axis data: ' + ret.x);
console.log('Y-axis data: ' + ret.y); console.info('Succeeded in subscribing. Y-axis data: ' + ret.y);
console.log('Z-axis data: ' + ret.z); console.info('Succeeded in subscribing. Z-axis data: ' + ret.z);
}, },
fail: function(data, code) { fail: function (data, code) {
console.error('Subscription failed. Code: ' + code + '; data: ' + data); console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
} }
}); });
``` ```
...@@ -515,7 +516,7 @@ unsubscribeGyroscope(): void ...@@ -515,7 +516,7 @@ unsubscribeGyroscope(): void
**示例:** **示例:**
```js ```ts
sensor.unsubscribeGyroscope(); sensor.unsubscribeGyroscope();
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册