未验证 提交 f3dc2845 编写于 作者: O openharmony_ci 提交者: Gitee

!21038 【泛Sensor】修复文档描述、代码示例

Merge pull request !21038 from lixiangpeng5/master-lxp
...@@ -226,46 +226,43 @@ try { ...@@ -226,46 +226,43 @@ try {
```ts ```ts
import vibrator from '@ohos.vibrator'; import vibrator from '@ohos.vibrator';
const FILE_NAME = "xxx.json";
// 获取振动文件资源描述符 // 获取振动文件资源描述符
let fileDescriptor = undefined; async function getRawfileFd(fileName) {
getContext().resourceManager.getRawFd(FILE_NAME).then(value => { let rawFd = await globalThis.getContext().resourceManager.getRawFd(fileName);
fileDescriptor = { fd: value.fd, offset: value.offset, length: value.length }; return rawFd;
console.info('Succeed in getting resource file descriptor'); }
}).catch(error => {
console.error(`Failed to get resource file descriptor. Code: ${error.code}, message: ${error.message}`); // 关闭振动文件资源描述符
}); async function closeRawfileFd(fileName) {
// 使用startVibration、stopVibration需要添加ohos.permission.VIBRATE权限 await globalThis.getContext().resourceManager.closeRawFd(fileName)
try { }
// 启动自定义振动
vibrator.startVibration({ // 播放自定义振动,使用startVibration、stopVibration需要添加ohos.permission.VIBRATE权限
type: "file", async function playCustomHaptic(fileName) {
hapticFd: { fd: fileDescriptor.fd, offset: fileDescriptor.offset, length: fileDescriptor.length } try {
}, { let rawFd = await getRawfileFd(fileName);
usage: "alarm" vibrator.startVibration({
}).then(() => { type: "file",
console.info('Succeed in starting vibration'); hapticFd: { fd: rawFd.fd, offset: rawFd.offset, length: rawFd.length }
}, (error) => { }, {
console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); usage: "alarm"
}); }).then(() => {
// 停止所有类型的马达振动 console.info('Succeed in starting vibration');
vibrator.stopVibration(function (error) { }, (error) => {
if (error) { console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`);
console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`); });
return; vibrator.stopVibration(function (error) {
} if (error) {
console.info('Succeed in stopping vibration'); console.error(`Failed to stop vibration. Code: ${error.code}, message: ${error.message}`);
}) return;
} catch (error) { }
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); console.info('Succeed in stopping vibration');
})
await closeRawfileFd(fileName);
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
} }
// 关闭振动文件资源
getContext().resourceManager.closeRawFd(FILE_NAME).then(() => {
console.info('Succeed in closing resource file descriptor');
}).catch(error => {
console.error(`Failed to close resource file descriptor. Code: ${error.code}, message: ${error.message}`);
});
``` ```
......
...@@ -3387,7 +3387,7 @@ try { ...@@ -3387,7 +3387,7 @@ try {
console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data)); console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data));
}) })
} catch (error) { } catch (error) {
console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`); console.error(`Failed to get rotationMatrix. Code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -3612,6 +3612,8 @@ try { ...@@ -3612,6 +3612,8 @@ try {
| HALL | 10 | 霍尔传感器。 | | HALL | 10 | 霍尔传感器。 |
| PROXIMITY | 12 | 接近光传感器。 | | PROXIMITY | 12 | 接近光传感器。 |
| HUMIDITY | 13 | 湿度传感器。 | | HUMIDITY | 13 | 湿度传感器。 |
| COLOR<sup>10+</sup> | 14 | 颜色传感器。 |
| SAR<sup>10+</sup> | 15 | 吸收比率传感器。 |
| ORIENTATION | 256 | 方向传感器。 | | ORIENTATION | 256 | 方向传感器。 |
| GRAVITY | 257 | 重力传感器。 | | GRAVITY | 257 | 重力传感器。 |
| LINEAR_ACCELEROMETER | 258 | 线性加速度传感器。 | | LINEAR_ACCELEROMETER | 258 | 线性加速度传感器。 |
......
...@@ -1169,7 +1169,7 @@ usb服务 ...@@ -1169,7 +1169,7 @@ usb服务
## SystemCapability.Sensors.Sensor.Lite ## SystemCapability.Sensors.Sensor.Lite
传感器服务订阅 轻量级传感器服务订阅
| Default | 运动表 | 智能表 | 平板 | 车机 | 智慧屏 | Smart-Vision | Router | | Default | 运动表 | 智能表 | 平板 | 车机 | 智慧屏 | Smart-Vision | Router |
| ------- | ------ | ------ | ---- | ---- | ------ | ------------ | ------ | | ------- | ------ | ------ | ---- | ---- | ------ | ------------ | ------ |
...@@ -1185,7 +1185,7 @@ usb服务 ...@@ -1185,7 +1185,7 @@ usb服务
## SystemCapability.Sensors.MiscDevice.Lite ## SystemCapability.Sensors.MiscDevice.Lite
小器件-振感 轻量级小器件-振感
| Default | 运动表 | 智能表 | 平板 | 车机 | 智慧屏 | Smart-Vision | Router | | Default | 运动表 | 智能表 | 平板 | 车机 | 智慧屏 | Smart-Vision | Router |
| ------- | ------ | ------ | ---- | ---- | ------ | ------------ | ------ | | ------- | ------ | ------ | ---- | ---- | ------ | ------------ | ------ |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册