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

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

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