Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
figures/ | 12-May-2024 | - | ||||
hal/ | 12-May-2024 | - | 336 | 257 | ||
hdi_service/ | 12-May-2024 | - | 339 | 254 | ||
interfaces/include/ | 12-May-2024 | - | 191 | 41 | ||
test/ | 12-May-2024 | - | 1,067 | 694 | ||
BUILD.gn | D | 12-May-2024 | 969 | 27 | 25 | |
README_zh.md | D | 12-May-2024 | 4.1 KiB | 122 | 98 | |
bundle.json | D | 12-May-2024 | 1.4 KiB | 56 | 55 |
README_zh.md
1# vibrator 2 3- [简介](##简介) 4- [目录](##目录) 5- [说明](##说明) 6 - [接口说明](###接口说明) 7 - [使用说明](###使用说明) 8 9- [相关仓](##相关仓) 10 11## 简介 12 13Vibrator驱动模型主要包含Vibrator(传感器)相关的HDI接口与实现,提供Vibrator HDI(Hardware Driver Interface)能力接口,支持静态HCS配置的时间序列和动态配置持续时间两种振动效果。调用StartOnce接口动态配置持续振动时间;调用StartEffect接口启动静态配置的振动效果。 14 15**图 1** Vibrator驱动模型图 16 17 18 19## 目录 20 21Vibraor驱动下源代码目录结构如下所示: 22 23``` 24/drivers/peripheral/misc/vibrator 25├── hal # vibrator模块hal层代码 26│ ├── include # vibrator模块hal层内部头文件 27│ └── src # vibrator模块hal层代码的实现 28├── interfaces # vibrator模块对上层服务提供的驱动能力接口 29│ └── include # vibrator模块对外提供的接口定义 30└── test # vibrator模块测试代码 31 └── unittest # vibrator模块单元测试代码 32``` 33 34## 说明 35 36### 接口说明 37 38马达主要提供的功能:触发震动,停止震动。开发能力如下表1: 39 40**表 1**马达的主要接口 41 42| 接口名 | 功能描述 | 43| -------------------------------------- | ---------------------------------------------------------- | 44| int32_t StartOnce(uint32_t duration) | 按照指定持续时间触发震动,duration为振动持续时长。 | 45| int32_t Start(const char *effectType) | 按照指定预置效果启动马达,effectType表示预置的振动效果串。 | 46| int32_t Stop(enum VibratorMode mode) | 按照指定的振动模式停止震动。 | 47 48### 使用说明 49 50代码示例 51 52``` 53#include "vibrator_if.h" 54 55enum VibratorMode { 56 VIBRATOR_MODE_ONCE = 0, // 指定时间内的一次振动 57 VIBRATOR_MODE_PRESET = 1, // 指定预置效果的周期性振动 58}; 59 60void VibratorSample(void) 61{ 62 int32_t startRet; 63 int32_t endRet; 64 uint32_t g_duration = 1000; 65 uint32_t g_sleepTime1 = 2000; 66 uint32_t g_sleepTime2 = 5000; 67 const char *g_timeSequence = "haptic.clock.timer"; 68 /* 创建传感器接口实例 */ 69 struct VibratorInterface *g_vibratorDev = NewVibratorInterfaceInstance(); 70 if (g_vibratorDev == NULL) { 71 return; 72 } 73 /* 按照指定持续时间触发震动*/ 74 startRet = g_vibratorDev->StartOnce(g_duration); 75 if (startRet != 0) { 76 return; 77 } 78 OsalMSleep(g_sleepTime1); 79 /* 按照指定的振动模式停止震动 */ 80 endRet = g_vibratorDev->Stop(VIBRATOR_MODE_ONCE); 81 if (endRet != 0) { 82 return; 83 } 84 /* 释放传感器接口实例 */ 85 ret = FreeVibratorInterfaceInstance(); 86 if (ret != 0) { 87 return; 88 } 89 /* 创建传感器接口实例 */ 90 struct VibratorInterface *g_vibratorDev = NewVibratorInterfaceInstance(); 91 if (g_vibratorDev == NULL) { 92 return; 93 } 94 /* 按照指定预置效果启动马达 */ 95 startRet = g_vibratorDev->Start(g_timeSequence); 96 if (endRet != 0) { 97 return; 98 } 99 OsalMSleep(g_sleepTime2); 100 /* 按照指定的振动模式停止震动 */ 101 endRet = g_vibratorDev->Stop(VIBRATOR_MODE_PRESET); 102 if (endRet != 0) { 103 return; 104 } 105 /* 释放传感器接口实例 */ 106 ret = FreeVibratorInterfaceInstance(); 107 if (ret != 0) { 108 return; 109 } 110} 111``` 112 113## 相关仓 114 115[驱动子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E9%A9%B1%E5%8A%A8%E5%AD%90%E7%B3%BB%E7%BB%9F.md) 116 117[drivers_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md) 118 119[drivers_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md) 120 121[drivers_adapter_khdf_linuk](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md) 122drivers_peripheral