zoukankan      html  css  js  c++  java
  • 获取输入设备的vid和pid

    一、获取/dev/input/event16设备的vid和pid

    testhid.c

    1. #include <linux/types.h>  
    2. #include <linux/input.h>  
    3. #include <linux/hidraw.h>  
    4.   
    5. #include <sys/ioctl.h>  
    6. #include <sys/types.h>  
    7. #include <sys/stat.h>  
    8. #include <fcntl.h>  
    9. #include <unistd.h>  
    10. #include <poll.h>  
    11. #include <time.h>  
    12. #include <math.h>  
    13.   
    14. #include <stdio.h>  
    15. #include <stdint.h>  
    16. #include <string.h>  
    17. #include <stdlib.h>  
    18. #include <errno.h>  
    19. int main(){  
    20.   char filename[64];  
    21.   strcpy(filename,"/dev/input/event16");  
    22.   char name[80];  
    23.   int fd = open(filename, O_RDWR /*| O_NONBLOCK*/);  
    24.   if(fd <= 0) {  
    25.     printf("TK----------->>>>open error ");  
    26.     return -1;  
    27.   }  
    28.   /////////  
    29.   struct input_id inputId;  
    30.   int rc = ioctl(fd, EVIOCGID, &inputId);  
    31.   printf("TK-------->>>>info.vendor is 0x%x ",inputId.vendor);  
    32.   printf("TK-------->>>>info.product is 0x%x ",inputId.product);  
    33.   printf("TK-------->>>>info.bustype is 0x%x ",inputId.bustype);  
    34.   /* 
    35.   struct hidraw_devinfo info; 
    36.   int rc = ioctl(fd, HIDIOCGRAWINFO, &info); 
    37.   printf("TK-------->>>>info.vendor is 0x%x ",info.vendor); 
    38.   printf("TK-------->>>>info.product is 0x%x ",info.product); 
    39.   printf("TK-------->>>>info.bustype is 0x%x ",info.bustype); 
    40.   */  
    41.   ///////////  
    42.   struct hidraw_report_descriptor descriptor;  
    43.   rc = ioctl(fd, HIDIOCGRDESC, &descriptor);  
    44.   printf("TK-------->>>>descriptor.size is 0x%04x ",descriptor.size);  
    45.   //////  
    46.   int descriptorSize=0;  
    47.   rc = ioctl(fd, HIDIOCGRDESCSIZE, &descriptorSize);  
    48.   printf("TK-------->>>>descriptorSize is 0x%04x ",descriptorSize);    
    49.   //////  
    50.   name[sizeof(name) - 1] = '';  
    51.   if(ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {  
    52.     name[0] = '';  
    53.   }  
    54.   printf("TK------->>>name is %s ",name);  
    55.   //////  
    56.   close(fd);  
    57.   return 0;  
    58. }  

    二、编译

    Android.mk

    [plain] view plain copy 在CODE上查看代码片派生到我的代码片
    1. LOCAL_PATH:= $(call my-dir)  
    2. include $(CLEAR_VARS)  
    3.   
    4. LOCAL_SRC_FILES:=   
    5.     testhid.c  
    6.   
    7. LOCAL_SHARED_LIBRARIES :=   
    8.     libutils   
    9.   
    10. LOCAL_MODULE:= testinput  
    11.   
    12. LOCAL_MODULE_TAGS := optional  
    13.   
    14. include $(BUILD_EXECUTABLE)  

    三、运行

    [plain] view plain copy 在CODE上查看代码片派生到我的代码片
      1. TK-------->>>>info.vendor is 0x0  
      2. TK-------->>>>info.product is 0x1  
      3. TK-------->>>>info.bustype is 0x19  
      4. TK-------->>>>descriptor.size is 0x0000  
      5. TK-------->>>>descriptorSize is 0x0000  
      6. TK------->>>name is Power Button 
  • 相关阅读:
    技术总监7年经验——论程序员的职业发展路线
    2.MySQL入门基本操作初体验
    1.MySQL的安装(linux Ubuntu环境下)
    Boot Petalinux Project Using a remote system
    字符设备驱动、平台设备驱动、设备驱动模型、sysfs的比较和关联
    linux采用模块方法,添加一个新的设备
    在远程服务器上完成本地设备的程序烧写和调试(基于vivado ,SDK软件)
    Linux Master/Baremetal Remote 配置下的裸机调试
    利用Xlinix SDK 建立Linux程序以及对该程序进行调试
    Vivado Launching SDK "Importing Hardware Specification" error的解决方法
  • 原文地址:https://www.cnblogs.com/senior-engineer/p/5598020.html
Copyright © 2011-2022 走看看