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

整改docs规范扫描

Signed-off-by: Nli-yaoyao777 <liyaoyao7@huawei.com>
上级 6bf41849
......@@ -33,10 +33,11 @@
2. 以下场景以加速度传感器ACCELEROMETER为例。展示持续监听传感器接口的调用结果。
```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); // 获取数据成功
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 @@
3. 注销传感器数据监听。
```js
```ts
import sensor from "@ohos.sensor";
sensor.off(sensor.SensorId.ACCELEROMETER);
```
......@@ -53,10 +54,11 @@
4. 获取一次传感器数据变化。
```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); // 获取数据成功
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 @@
若接口调用不成功,建议使用try/catch语句捕获代码中可能出现的错误信息。例如:
```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); // 获取数据成功
});
} 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); // 获取数据成功
});
} catch (error) {
console.error(`Failed to get sensor data. Code: ${error.code}, message: ${error.message}`);
}
```
## 相关实例
......
......@@ -9,7 +9,7 @@ sensor模块提供了获取传感器数据的能力,包括获取传感器属
## 导入模块
```js
```ts
import sensor from '@ohos.sensor';
```
## sensor.on
......@@ -42,14 +42,14 @@ on(type: SensorId.COLOR, callback: Callback\<ColorResponse>,options?: Options):
**示例:**
```js
```ts
try {
sensor.on(sensor.SensorId.COLOR, function (data) {
console.info('The intensity of light: ' + data.lightIntensity);
console.info('The color temperature: ' + data.colorTemperature);
}, { interval: 100000000 });
} catch (err) {
console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
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}`);
}
```
......@@ -81,13 +81,13 @@ on(type: SensorId.SAR, callback: Callback\<SarResponse>,options?: Options): void
**示例:**
```js
```ts
try {
sensor.on(sensor.SensorId.SAR, function (data) {
console.info('Specific absorption rate : ' + data.absorptionRatio);
}, { interval: 100000000 });
} catch (err) {
console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
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}`);
}
```
......@@ -119,15 +119,15 @@ on(type: SensorId.ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;
**示例:**
```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}`);
}
```
......@@ -159,18 +159,18 @@ on(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;Acceleromete
**示例:**
```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}`);
}
```
......@@ -200,13 +200,13 @@ on(type: SensorId.AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;, option
**示例:**
```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}`);
}
```
......@@ -236,13 +236,13 @@ on(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback&lt;AmbientTemperatureR
**示例:**
```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}`);
}
```
......@@ -272,13 +272,13 @@ on(type: SensorId.BAROMETER, callback: Callback&lt;BarometerResponse&gt;, option
**示例:**
```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}`);
}
```
......@@ -308,15 +308,15 @@ on(type: SensorId.GRAVITY, callback: Callback&lt;GravityResponse&gt;,options?: O
**示例:**
```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}`);
}
```
......@@ -348,15 +348,15 @@ on(type: SensorId.GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;,options
**示例:**
```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}`);
}
```
......@@ -389,18 +389,18 @@ on(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback&lt;GyroscopeUncalib
**示例:**
```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}`);
}
```
......@@ -430,13 +430,13 @@ on(type: SensorId.HALL, callback: Callback&lt;HallResponse&gt;, options?: Option
**示例:**
```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}`);
}
```
......@@ -468,13 +468,13 @@ on(type: SensorId.HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;,option
**示例:**
```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}`);
}
```
......@@ -504,13 +504,13 @@ on(type: SensorId.HUMIDITY, callback: Callback&lt;HumidityResponse&gt;,options?:
**示例:**
```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}`);
}
```
......@@ -543,15 +543,15 @@ on(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback&lt;LinearAcceleromete
**示例:**
```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}`);
}
```
......@@ -581,15 +581,15 @@ on(type: SensorId.MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt
**示例:**
```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}`);
}
```
......@@ -619,18 +619,18 @@ on(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticFie
**示例:**
```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}`);
}
```
......@@ -660,15 +660,15 @@ on(type: SensorId.ORIENTATION, callback: Callback&lt;OrientationResponse&gt;,opt
**示例:**
```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}`);
}
```
......@@ -700,13 +700,13 @@ on(type: SensorId.PEDOMETER, callback: Callback&lt;PedometerResponse&gt;, option
**示例:**
```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}`);
}
```
......@@ -739,13 +739,13 @@ on(type: SensorId.PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionR
**示例:**
```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}`);
}
```
......@@ -775,13 +775,13 @@ on(type: SensorId.PROXIMITY, callback: Callback&lt;ProximityResponse&gt;, option
**示例:**
```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}`);
}
```
......@@ -812,16 +812,16 @@ on(type: SensorId.ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&
**示例:**
```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}`);
}
```
......@@ -852,13 +852,13 @@ on(type: SensorId.SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionRes
**示例:**
```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}`);
}
```
......@@ -889,13 +889,13 @@ on(type: SensorId.WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt
**示例:**
```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}`);
}
```
......@@ -928,15 +928,15 @@ once(type: SensorId.ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&g
**示例:**
```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}`);
}
```
......@@ -967,18 +967,18 @@ once(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;Accelerome
**示例:**
```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}`);
}
```
......@@ -1007,13 +1007,13 @@ once(type: SensorId.AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): voi
**示例:**
```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}`);
}
```
......@@ -1042,13 +1042,13 @@ once(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback&lt;AmbientTemperatur
**示例:**
```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}`);
}
```
......@@ -1077,13 +1077,13 @@ once(type: SensorId.BAROMETER, callback: Callback&lt;BarometerResponse&gt;): voi
**示例:**
```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}`);
}
```
......@@ -1112,15 +1112,15 @@ once(type: SensorId.GRAVITY, callback: Callback&lt;GravityResponse&gt;): void
**示例:**
```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}`);
}
```
......@@ -1151,15 +1151,17 @@ once(type: SensorId.GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): voi
**示例:**
```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}`);
}
```
......@@ -1190,18 +1192,18 @@ once(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback&lt;GyroscopeUncal
**示例:**
```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}`);
}
```
......@@ -1230,13 +1232,13 @@ once(type: SensorId.HALL, callback: Callback&lt;HallResponse&gt;): void
**示例:**
```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}`);
}
```
......@@ -1267,13 +1269,13 @@ once(type: SensorId.HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;): vo
**示例:**
```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}`);
}
```
......@@ -1302,13 +1304,13 @@ once(type: SensorId.HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void
**示例:**
```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}`);
}
```
......@@ -1339,15 +1341,15 @@ once(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback&lt;LinearAccelerome
**示例:**
```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}`);
}
```
......@@ -1376,15 +1378,15 @@ once(type: SensorId.MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&
**示例:**
```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}`);
}
```
......@@ -1413,18 +1415,18 @@ once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticF
**示例:**
```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}`);
}
```
......@@ -1453,15 +1455,15 @@ once(type: SensorId.ORIENTATION, callback: Callback&lt;OrientationResponse&gt;):
**示例:**
```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}`);
}
```
......@@ -1492,13 +1494,13 @@ once(type: SensorId.PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): voi
**示例:**
```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}`);
}
```
......@@ -1529,13 +1531,13 @@ once(type: SensorId.PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectio
**示例:**
```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}`);
}
```
......@@ -1564,13 +1566,13 @@ once(type: SensorId.PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): voi
**示例:**
```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}`);
}
```
......@@ -1599,16 +1601,16 @@ once(type: SensorId.ROTATION_VECTOR, callback: Callback&lt;RotationVectorRespons
**示例:**
```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}`);
}
```
......@@ -1637,13 +1639,13 @@ once(type: SensorId.SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionR
**示例:**
```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}`);
}
```
......@@ -1672,13 +1674,13 @@ once(type: SensorId.WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&
**示例:**
```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}`);
}
```
......@@ -1703,22 +1705,24 @@ off(type: SensorId.COLOR, callback?: Callback\<ColorResponse>): void
**示例:**
```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.COLOR, callback1);
sensor.on(sensor.SensorId.COLOR, callback2);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.COLOR, callback1);
// 取消注册SensorId.COLOR的所有回调
sensor.off(sensor.SensorId.COLOR);
} catch (err) {
console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
sensor.on(sensor.SensorId.COLOR, callback1);
sensor.on(sensor.SensorId.COLOR, callback2);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.COLOR, callback1);
// 取消注册SensorId.COLOR的所有回调
sensor.off(sensor.SensorId.COLOR);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -1741,22 +1745,24 @@ off(type: SensorId.SAR, callback?: Callback\<SarResponse>): void
**示例:**
```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.SAR, callback1);
sensor.on(sensor.SensorId.SAR, callback2);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.SAR, callback1);
// 取消注册SensorId.SAR的所有回调
sensor.off(sensor.SensorId.SAR);
} catch (err) {
console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
sensor.on(sensor.SensorId.SAR, callback1);
sensor.on(sensor.SensorId.SAR, callback2);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.SAR, callback1);
// 取消注册SensorId.SAR的所有回调
sensor.off(sensor.SensorId.SAR);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -1779,22 +1785,24 @@ off(type: SensorId.ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&g
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.ACCELEROMETER, callback1);
// 取消SensorId.ACCELEROMETER类型的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.ACCELEROMETER, callback1);
// 取消SensorId.ACCELEROMETER类型的所有回调
sensor.off(sensor.SensorId.ACCELEROMETER);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -1817,22 +1825,24 @@ off(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;Accelerome
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1);
// 取消注册SensorId.ACCELEROMETER_UNCALIBRATED类型的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1);
// 取消注册SensorId.ACCELEROMETER_UNCALIBRATED类型的所有回调
sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -1853,22 +1863,24 @@ off(type: SensorId.AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): voi
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback1);
// 取消注册SensorId.AMBIENT_LIGHT的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback1);
// 取消注册SensorId.AMBIENT_LIGHT
sensor.off(sensor.SensorId.AMBIENT_LIGHT);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -1889,22 +1901,24 @@ off(type: SensorId.AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatur
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE, callback1);
// 取消注册SensorId.AMBIENT_TEMPERATURE的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE, callback1);
// 取消注册SensorId.AMBIENT_TEMPERATURE的所有回调
sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -1925,13 +1939,15 @@ off(type: SensorId.BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): voi
**示例:**
```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);
......@@ -1939,8 +1955,8 @@ try {
sensor.off(sensor.SensorId.BAROMETER, callback1);
// 取消注册SensorId.BAROMETER的所有回调
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}`);
}
```
......@@ -1961,22 +1977,24 @@ off(type: SensorId.GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.GRAVITY, callback1);
// 取消注册SensorId.GRAVITY的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.GRAVITY, callback1);
// 取消注册SensorId.GRAVITY的所有回调
sensor.off(sensor.SensorId.GRAVITY);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -1999,22 +2017,24 @@ off(type: SensorId.GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): voi
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.GYROSCOPE, callback1);
// 取消注册SensorId.GYROSCOPE的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.GYROSCOPE, callback1);
// 取消注册SensorId.GYROSCOPE的所有回调
sensor.off(sensor.SensorId.GYROSCOPE);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2037,22 +2057,24 @@ off(type: SensorId.GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncal
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1);
// 取消注册SensorId.GYROSCOPE_UNCALIBRATED的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1);
// 取消注册SensorId.GYROSCOPE_UNCALIBRATED的所有回调
sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2073,22 +2095,24 @@ off(type: SensorId.HALL, callback?: Callback&lt;HallResponse&gt;): void
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.HALL, callback1);
// 取消注册SensorId.HALL的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.HALL, callback1);
// 取消注册SensorId.HALL的所有回调
sensor.off(sensor.SensorId.HALL);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2111,22 +2135,24 @@ off(type: SensorId.HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): vo
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.HEART_RATE, callback1);
// 取消注册SensorId.HEART_RATE的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.HEART_RATE, callback1);
// 取消注册SensorId.HEART_RATE的所有回调
sensor.off(sensor.SensorId.HEART_RATE);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2147,22 +2173,24 @@ off(type: SensorId.HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.HUMIDITY, callback1);
// 取消注册SensorId.HUMIDITY的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.HUMIDITY, callback1);
// 取消注册SensorId.HUMIDITY的所有回调
sensor.off(sensor.SensorId.HUMIDITY);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2185,22 +2213,24 @@ off(type: SensorId.LINEAR_ACCELEROMETER, callback?: Callback&lt;LinearAccelerome
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback1);
// 取消注册SensorId.LINEAR_ACCELEROMETER的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback1);
// 取消注册SensorId.LINEAR_ACCELEROMETER的所有回调
sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2221,22 +2251,24 @@ off(type: SensorId.MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback1);
// 取消注册SensorId.MAGNETIC_FIELD的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback1);
// 取消注册SensorId.MAGNETIC_FIELD的所有回调
sensor.off(sensor.SensorId.MAGNETIC_FIELD);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2257,22 +2289,24 @@ off(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticF
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1);
// 取消注册SensorId.MAGNETIC_FIELD_UNCALIBRATED的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1);
// 取消注册SensorId.MAGNETIC_FIELD_UNCALIBRATED的所有回调
sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2293,22 +2327,24 @@ off(type: SensorId.ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;):
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.ORIENTATION, callback1);
// 取消注册SensorId.ORIENTATION的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.ORIENTATION, callback1);
// 取消注册SensorId.ORIENTATION的所有回调
sensor.off(sensor.SensorId.ORIENTATION);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2331,22 +2367,24 @@ off(type: SensorId.PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): voi
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.PEDOMETER, callback1);
// 取消注册SensorId.PEDOMETER的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.PEDOMETER, callback1);
// 取消注册SensorId.PEDOMETER的所有回调
sensor.off(sensor.SensorId.PEDOMETER);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2369,22 +2407,24 @@ off(type: SensorId.PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectio
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback1);
// 取消注册SensorId.PEDOMETER_DETECTION的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback1);
// 取消注册SensorId.PEDOMETER_DETECTION的所有回调
sensor.off(sensor.SensorId.PEDOMETER_DETECTION);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2405,22 +2445,24 @@ off(type: SensorId.PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): voi
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.PROXIMITY, callback1);
// 取消注册SensorId.PROXIMITY的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.PROXIMITY, callback1);
// 取消注册SensorId.PROXIMITY的所有回调
sensor.off(sensor.SensorId.PROXIMITY);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2441,22 +2483,24 @@ off(type: SensorId.ROTATION_VECTOR, callback?: Callback&lt;RotationVectorRespons
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.ROTATION_VECTOR, callback1);
// 取消注册SensorId.ROTATION_VECTOR的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.ROTATION_VECTOR, callback1);
// 取消注册SensorId.ROTATION_VECTOR的所有回调
sensor.off(sensor.SensorId.ROTATION_VECTOR);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2477,22 +2521,24 @@ off(type: SensorId.SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionR
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback1);
// 取消注册SensorId.SIGNIFICANT_MOTION的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback1);
// 取消注册SensorId.SIGNIFICANT_MOTION的所有回调
sensor.off(sensor.SensorId.SIGNIFICANT_MOTION);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2513,22 +2559,24 @@ off(type: SensorId.WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&
**示例:**
```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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.WEAR_DETECTION, callback1);
// 取消注册SensorId.WEAR_DETECTION的所有回调
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);
// 仅取消callback1的注册
sensor.off(sensor.SensorId.WEAR_DETECTION, callback1);
// 取消注册SensorId.WEAR_DETECTION的所有回调
sensor.off(sensor.SensorId.WEAR_DETECTION);
} catch (error) {
console.error(`Failed to invoke off. Code: ${error.code}, message: ${error.message}`);
}
```
......@@ -2558,23 +2606,23 @@ getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number, callbac
**示例:**
```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}`);
}
```
......@@ -2609,22 +2657,22 @@ getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number): Promis
**示例:**
```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}`);
}
```
......@@ -2654,19 +2702,19 @@ getDeviceAltitude(seaPressure: number, currentPressure: number, callback: AsyncC
**示例:**
```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}`);
}
```
......@@ -2701,18 +2749,18 @@ getDeviceAltitude(seaPressure: number, currentPressure: number): Promise&lt;numb
**示例:**
```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}`);
}
```
......@@ -2741,23 +2789,23 @@ getInclination(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&l
**示例:**
```js
```ts
try {
// inclinationMatrix可以为3*3,或者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可以为3*3,或者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}`);
}
```
......@@ -2791,22 +2839,22 @@ try {
**示例:**
```js
```ts
try {
// inclinationMatrix可以为3*3,或者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可以为3*3,或者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}`);
}
```
......@@ -2837,33 +2885,33 @@ try {
**示例:**
```js
```ts
try {
// 旋转矩阵可以为3*3,或者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);
// 旋转矩阵可以为3*3,或者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}`);
}
```
......@@ -2898,32 +2946,32 @@ getAngleVariation(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix:
**示例:**
```js
```ts
try {
// 旋转矩阵可以为3*3,或者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);
// 旋转矩阵可以为3*3,或者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}`);
}
```
......@@ -2952,20 +3000,20 @@ getRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&l
**示例:**
```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}`);
}
```
......@@ -2999,19 +3047,19 @@ getRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;numb
**示例:**
```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}`);
}
```
......@@ -3042,24 +3090,24 @@ transformRotationMatrix(inRotationVector: Array&lt;number&gt;, coordinates: Coor
**示例:**
```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}`);
}
```
......@@ -3094,23 +3142,23 @@ transformRotationMatrix(inRotationVector: Array&lt;number&gt;, coordinates: Coor
**示例:**
```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}`);
}
```
......@@ -3139,20 +3187,20 @@ getQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Ar
**示例:**
```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}`);
}
```
......@@ -3186,19 +3234,19 @@ getQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&g
**示例:**
```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}`);
}
```
......@@ -3227,27 +3275,27 @@ getOrientation(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;A
**示例:**
```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}`);
}
```
......@@ -3281,23 +3329,23 @@ getOrientation(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&
**示例:**
```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}`);
}
```
......@@ -3327,19 +3375,19 @@ getRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;
**示例:**
```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}`);
}
```
......@@ -3374,18 +3422,18 @@ getRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;
**示例:**
```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}`);
}
```
......@@ -3413,19 +3461,19 @@ getSensorList(callback: AsyncCallback&lt;Array&lt;Sensor&gt;&gt;): void
**示例:**
```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}`);
}
```
......@@ -3453,17 +3501,17 @@ try {
**示例:**
```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}`);
}
```
......@@ -3492,17 +3540,17 @@ getSingleSensor(type: SensorId, callback: AsyncCallback&lt;Sensor&gt;): void
**示例:**
```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}`);
}
```
......@@ -3536,15 +3584,15 @@ try {
**示例:**
```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}`);
}
```
......@@ -4033,15 +4081,15 @@ on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;Acceler
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4084,18 +4132,19 @@ on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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}
);
```
```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<sup>(deprecated)</sup>
......@@ -4117,15 +4166,15 @@ on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityRespons
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4148,15 +4197,16 @@ on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeRes
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4179,18 +4229,19 @@ on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback&lt;G
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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}
);
```
```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<sup>(deprecated)</sup>
......@@ -4211,13 +4262,14 @@ on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback&lt;Sig
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4240,13 +4292,14 @@ on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback&lt;Pe
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4269,13 +4322,14 @@ on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerRes
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4297,13 +4351,13 @@ on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback&lt;Ambi
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4325,15 +4379,15 @@ on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;Magneti
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4354,18 +4408,19 @@ on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callbac
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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}
);
```
```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<sup>(deprecated)</sup>
......@@ -4386,13 +4441,14 @@ on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityRes
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4414,13 +4470,13 @@ on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityRespo
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4442,13 +4498,13 @@ on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerRes
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4469,13 +4525,14 @@ on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;,
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4497,13 +4554,13 @@ on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightRes
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4524,15 +4581,16 @@ on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;Orientatio
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4573,16 +4631,17 @@ on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback&lt;Rotatio
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4603,13 +4662,14 @@ on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDet
| options | [Options](#options) | 否 | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4633,14 +4693,14 @@ once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;Accele
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是 | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4681,17 +4741,17 @@ once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callba
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是 | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
**示例:**
```
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<sup>(deprecated)</sup>
......@@ -4711,14 +4771,14 @@ once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityRespo
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是 | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4740,14 +4800,14 @@ once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeR
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是 | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4769,17 +4829,16 @@ once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback&l
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是 | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4799,12 +4858,12 @@ once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback&lt;Si
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是 | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4826,12 +4885,12 @@ once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback&lt;P
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是 | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4853,12 +4912,12 @@ once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerR
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是 | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4878,12 +4937,12 @@ once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback&lt;A
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是 | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4903,14 +4962,14 @@ once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;Magne
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是 | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4930,17 +4989,17 @@ once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callb
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是 | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4960,12 +5019,13 @@ once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityR
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是 | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -4985,12 +5045,12 @@ once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityRes
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是 | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5010,12 +5070,12 @@ once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerR
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是 | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5035,12 +5095,12 @@ once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是 | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5061,12 +5121,11 @@ once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightR
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5086,14 +5145,14 @@ once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;Orientat
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是 | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5113,15 +5172,15 @@ once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback&lt;Rota
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是 | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5160,12 +5219,11 @@ once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearD
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是 | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5190,12 +5248,13 @@ off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback&lt;Accele
**示例:**
```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);
```
......@@ -5220,15 +5279,16 @@ off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callb
**示例:**
```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);
```
......@@ -5251,10 +5311,11 @@ off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightR
**示例:**
```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);
```
......@@ -5277,10 +5338,11 @@ off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;
**示例:**
```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);
```
......@@ -5303,10 +5365,11 @@ off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerR
**示例:**
```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);
```
......@@ -5329,13 +5392,14 @@ off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityRespo
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5359,12 +5423,13 @@ off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeR
**示例:**
```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);
```
......@@ -5389,12 +5454,13 @@ off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&
**示例:**
```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);
```
......@@ -5417,10 +5483,11 @@ off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt
**示例:**
```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);
```
......@@ -5462,10 +5529,11 @@ off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityRes
**示例:**
```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);
```
......@@ -5507,12 +5575,13 @@ off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;
**示例:**
```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);
```
......@@ -5535,15 +5604,16 @@ sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
**示例:**
```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);
```
......@@ -5566,12 +5636,13 @@ sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callbac
**示例:**
```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);
```
......@@ -5596,10 +5667,11 @@ off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerR
**示例:**
```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);
```
......@@ -5624,10 +5696,11 @@ off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;
**示例:**
```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);
```
......@@ -5650,10 +5723,11 @@ off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityR
**示例:**
```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);
```
......@@ -5676,13 +5750,14 @@ off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;Rota
**示例:**
```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);
```
......@@ -5705,10 +5780,11 @@ off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;S
**示例:**
```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);
```
......@@ -5731,10 +5807,11 @@ off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearD
**示例:**
```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);
```
......@@ -5758,17 +5835,17 @@ transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: Co
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5795,15 +5872,15 @@ transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: Co
**示例:**
```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.`);
})
```
......@@ -5826,15 +5903,16 @@ getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callba
| callback | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 是 | 返回磁场信息。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5860,16 +5938,17 @@ getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promi
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5891,16 +5970,15 @@ getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallbac
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5927,14 +6005,14 @@ getAltitude(seaPressure: number, currentPressure: number): Promise&lt;number&gt;
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5956,16 +6034,15 @@ getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallbac
**示例:**
```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<sup>(deprecated)</sup>
......@@ -5991,14 +6068,14 @@ getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6020,19 +6097,17 @@ getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Ar
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6059,18 +6134,17 @@ getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Ar
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6091,19 +6165,17 @@ createRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallbac
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6129,18 +6201,17 @@ createRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;n
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6161,19 +6232,17 @@ createQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6199,18 +6268,17 @@ createQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;numbe
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6231,20 +6299,18 @@ getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Arr
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6270,18 +6336,17 @@ getDirection(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6303,16 +6368,15 @@ createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&
**示例:**
```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<sup>(deprecated)</sup>
......@@ -6339,11 +6403,11 @@ createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&
**示例:**
```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.`);
})
```
......@@ -37,16 +37,16 @@ import sensor from '@system.sensor';
**示例:**
```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}`);
},
});
```
......@@ -66,7 +66,7 @@ unsubscribeAccelerometer(): void
**示例:**
```js
```ts
sensor.unsubscribeAccelerometer();
```
......@@ -86,13 +86,13 @@ sensor.unsubscribeAccelerometer();
**示例:**
```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}`);
},
});
```
......@@ -110,7 +110,7 @@ unsubscribeCompass(): void
**示例:**
```js
```ts
sensor.unsubscribeCompass();
```
......@@ -130,13 +130,14 @@ sensor.unsubscribeCompass();
**示例:**
```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}`);
},
});
```
......@@ -154,7 +155,7 @@ unsubscribeProximity(): void
**示例:**
```js
```ts
sensor.unsubscribeProximity();
```
......@@ -174,13 +175,13 @@ sensor.unsubscribeProximity();
**示例:**
```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}`);
},
});
```
......@@ -198,7 +199,7 @@ unsubscribeLight(): void
**示例:**
```js
```ts
sensor.unsubscribeLight();
```
......@@ -220,13 +221,13 @@ sensor.unsubscribeLight();
**示例:**
```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}`);
},
});
```
......@@ -246,7 +247,7 @@ unsubscribeStepCounter(): void
**示例:**
```js
```ts
sensor.unsubscribeStepCounter();
```
......@@ -267,13 +268,13 @@ subscribeBarometer(options: SubscribeBarometerOptions): void
**示例:**
```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}`);
},
});
```
......@@ -292,7 +293,7 @@ unsubscribeBarometer(): void
**示例:**
```js
```ts
sensor.unsubscribeBarometer();
```
......@@ -315,13 +316,13 @@ sensor.unsubscribeBarometer();
**示例:**
```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}`);
},
});
```
......@@ -342,7 +343,7 @@ unsubscribeHeartRate(): void
**示例:**
```js
```ts
sensor.unsubscribeHeartRate();
```
......@@ -362,13 +363,13 @@ sensor.unsubscribeHeartRate();
**示例:**
```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}`);
},
});
```
......@@ -386,7 +387,7 @@ unsubscribeOnBodyState(): void
**示例:**
```js
```ts
sensor.unsubscribeOnBodyState();
```
......@@ -406,13 +407,13 @@ sensor.unsubscribeOnBodyState();
**示例:**
```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}`);
},
});
```
......@@ -435,17 +436,17 @@ sensor.getOnBodyState({
**示例:**
```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}`);
}
});
```
......@@ -462,7 +463,7 @@ unsubscribeDeviceOrientation(): void
**示例:**
```js
```ts
sensor.unsubscribeDeviceOrientation();
```
......@@ -486,16 +487,16 @@ sensor.unsubscribeDeviceOrientation();
**示例:**
```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}`);
}
});
```
......@@ -515,7 +516,7 @@ unsubscribeGyroscope(): void
**示例:**
```js
```ts
sensor.unsubscribeGyroscope();
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册