ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:19.82KB ,
资源ID:11189927      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11189927.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Linux下HID 设备.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Linux下HID 设备.docx

1、Linux下HID 设备Linux下HID 设备,如果非标准的输入设备(Keypad/MOUSE/JoyStick/input event device).将会把信息转入hid device的设备结点。这一点可以参见内核的关于hiddev的文档 http:/lxr.free- 它在 Documentation/usb/hiddev.txt 目录下,大致有这样一个流程, usb.c - hid-core.c - hid-input.c - keyboard/mouse/joystick/event | | - hiddev.c - POWER / MONITOR CONTROL 关于操作非标准的

2、HID设备,可以参见如下文档. 在设备文件系统中,会产生的/dev/hiddev0这样的结点,这类设备主设备号为 180,从设备号最低为96Cat /proc/device | grep hiddevmknod /dev/hiddev0 c 180 96mknod /dev/hiddev1 c 180 97mknod /dev/hiddev2 c 180 98mknod /dev/hiddev3 c 180 99 .mknod /dev/hiddev15 c 180 111对此设备结点的处理有两种接口,一种是read(),另一种是ioctl(); read(): This is the eve

3、nt interface. When the HID device performs an interrupt transfer, indicating a change of state, data will be made available at the associated hiddev device with the content of a struct hiddev_event:struct hiddev_event unsigned hid; signed int value; ; containing the HID usage identifier for the stat

4、us that changed, and the value that it was changed to. ioctl(): This is the control interface. There are a number of controls:HIDIOCGVERSIONint (read)Gets the version code out of the hiddev driver.HIDIOCAPPLICATION(none)This ioctl call returns the HID application usage associated with the hid device

5、. The third argument to ioctl() specifies which application index to get. This is useful when the device has more than one application collection. If the index is invalid (greater or equal to the number of application collections this device has) the ioctl returns -1. You can find out beforehand how

6、 many application collections the device has from the num_applications field from the hiddev_devinfo structure.HIDIOCGDEVINFOstruct hiddev_devinfo (read)Gets a hiddev_devinfo structure which describes the device.HIDIOCGSTRINGstruct struct hiddev_string_descriptor (read/write)Gets a string descriptor

7、 from the device. The caller must fill in the index field to indicate which descriptor should be returned.HIDIOCINITREPORT Instructs the kernel to retrieve all input and feature report values from the device. At this point, all the usage structures will contain current values for the device, and wil

8、l maintain it as the device changes.HIDIOCGNAMEstring (variable length)Gets the device nameHIDIOCGREPORTstruct hiddev_report_info (write)Instructs the kernel to get a feature or input report from the device, in order to selectively update the usage structures (in contrast to INITREPORT).HIDIOCSREPOR

9、Tstruct hiddev_report_info (write)Instructs the kernel to send a report to the device. This report can be filled in by the user throughHIDIOCSUSAGE calls (below) to fill in individual usage values in the report before sending the report in full to the device.HIDIOCGREPORTINFOstruct hiddev_report_inf

10、o (read/write)Fills in a hiddev_report_info structure for the user. The report is looked up by type (input, output or feature) and id, so these fields must be filled in by the user. The ID can be absolute - the actual report id as reported by the device - or relative - HID_REPORT_ID_FIRST for the fi

11、rst report, and (HID_REPORT_ID_NEXT | report_id) for the next report after report_id. Without a-priori information about report ids, the right way to use this ioctl is to use the relative IDs above to enumerate the valid IDs. The ioctl returns non-zero when there is no more next ID. The real report

12、ID is filled into the returned hiddev_report_info structure.HIDIOCGFIELDINFOstruct hiddev_field_info (read/write)Returns the field information associated with a report in a hiddev_field_info structure. The user must fill in report_id and report_type in this structure, as above. The field_index shoul

13、d also be filled in, which should be a number from 0 and maxfield-1, as returned from a previous HIDIOCGREPORTINFO call.HIDIOCGUCODEstruct hiddev_usage_ref (read/write)Returns the usage_code in a hiddev_usage_ref structure, given that given its report type, report id, field index, and index within t

14、he field have already been filled into the structure.HIDIOCGUSAGEstruct hiddev_usage_ref (read/write)Returns the value of a usage in a hiddev_usage_ref structure. The usage to be retrieved can be specified as above, or the user can choose to fill in the report_type field and specify the report_id as

15、HID_REPORT_ID_UNKNOWN. In this case, the hiddev_usage_ref will be filled in with the report and field infomation associated with this usage if it is found.HIDIOCSUSAGEstruct hiddev_usage_ref (write)Sets the value of a usage in an output report.1 测试代码/*2 Author : Andrew Huang 3 4 http:/lxr.free-5 6 *

16、/7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 17 static void showReports(int fd, unsigned report_type);18 static void show_all_report(int fd);19 static int read_event(int fd);20 21 int main()22 23 char dev_name64 = /dev/hiddev0;24 int fd

17、 = -1;25 int version;26 char name100;27 struct hiddev_devinfo dinfo;28 29 30 fd = open(dev_name,O_RDWR);31 if(fd = -1)32 33 fprintf(stderr,open %s failuren,dev_name);34 return -1;35 36 37 38 printf(%s inforn,dev_name); 39 40 if (ioctl(fd, HIDIOCGVERSION, &version) 16) & 0xFFFF, version & 0xFFFF);45

18、if (version != HID_VERSION)46 printf(WARNING: version does not match compile-time versionn);47 48 49 if (ioctl(fd, HIDIOCGDEVINFO, &dinfo) 0)50 perror(HIDIOCGDEVINFO);51 else52 53 printf(HIDIOCGDEVINFO: bustype=%d busnum=%d devnum=%d ifnum=%dn54 tvendor=0x%04hx product=0x%04hx version=0x%04hxn55 tnu

19、m_applications=%dn,56 dinfo.bustype, dinfo.busnum, dinfo.devnum, dinfo.ifnum,57 dinfo.vendor, dinfo.product, dinfo.version, dinfo.num_applications);58 59 60 if (ioctl(fd, HIDIOCGNAME(99), name) = 0)97 98 printf(HIDIOCGREPORTINFO: report_id=0x%X (%u fields)n,99 rinfo.report_id, rinfo.num_fields);100

20、for (i = 0; i rinfo.num_fields; i+)101 102 finfo.report_type = rinfo.report_type;103 finfo.report_id = rinfo.report_id;104 finfo.field_index = i;105 ioctl(fd, HIDIOCGFIELDINFO, &finfo);106 107 printf(HIDIOCGFIELDINFO: field_index=%u maxusage=%u flags=0x%Xn108 tphysical=0x%X logical=0x%X application=

21、0x%Xn109 tlogical_minimum=%d,maximum=%d physical_minimum=%d,maximum=%dn,110 finfo.field_index, finfo.maxusage, finfo.flags,111 finfo.physical, finfo.logical, finfo.application,112 finfo.logical_minimum, finfo.logical_maximum,113 finfo.physical_minimum, finfo.physical_maximum);114 115 for (j = 0; j u

22、sage_index=%u usage_code=0x%X () value=%dn,125 uref.usage_index,126 uref.usage_code,127 / controlName(uref.usage_code),128 uref.value);129 130 131 132 printf(n);133 134 rinfo.report_id |= HID_REPORT_ID_NEXT;135 ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);136 137 138 139 140 void show_all_report(int f

23、d)141 142 143 struct hiddev_report_info rinfo;144 struct hiddev_field_info finfo;145 struct hiddev_usage_ref uref;146 int rtype, i, j;147 char *rtype_str;148 149 for (rtype = HID_REPORT_TYPE_MIN; rtype = 0) 161 fprintf(stdout, Report id: %d (%d fields)n,162 rinfo.report_id, rinfo.num_fields);163 for

24、 (i = 0; i rinfo.num_fields; i+) 164 memset(&finfo, 0, sizeof(finfo);165 finfo.report_type = rinfo.report_type;166 finfo.report_id = rinfo.report_id;167 finfo.field_index = i;168 ioctl(fd, HIDIOCGFIELDINFO, &finfo);169 fprintf(stdout, Field: %d: app: %04x phys %04x 170 flags %x (%d usages) unit %x exp %dn, 171 i, finfo.application, finfo.physical, finfo.flags,172 finfo.maxusage, finfo.unit, finfo.unit_exponent);173 memset(&uref, 0, sizeof(uref);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1