提交 3cddad11 编写于 作者: L lixiangpeng5

Fix issue by review and scan

Signed-off-by: Nlixiangpeng5 <lixiangpeng5@huawei.com>
Change-Id: If02f072e8575c2c7d77e6fb0c68813eebab20be1
上级 a69e598f
......@@ -226,46 +226,43 @@ 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 {
// 启动自定义振动
vibrator.startVibration({
type: "file",
hapticFd: { fd: fileDescriptor.fd, offset: fileDescriptor.offset, length: fileDescriptor.length }
}, {
usage: "alarm"
}).then(() => {
console.info('Succeed in starting vibration');
}, (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}`);
return;
}
console.info('Succeed in stopping vibration');
})
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
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: rawFd.fd, offset: rawFd.offset, length: rawFd.length }
}, {
usage: "alarm"
}).then(() => {
console.info('Succeed in starting vibration');
}, (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}`);
return;
}
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 {
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.
先完成此消息的编辑!
想要评论请 注册