一、获取/dev/input/event16设备的vid和pid
testhid.c
- #include <linux/types.h>
- #include <linux/input.h>
- #include <linux/hidraw.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <poll.h>
- #include <time.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- #include <stdlib.h>
- #include <errno.h>
- int main(){
- char filename[64];
- strcpy(filename,"/dev/input/event16");
- char name[80];
- int fd = open(filename, O_RDWR /*| O_NONBLOCK*/);
- if(fd <= 0) {
- printf("TK----------->>>>open error ");
- return -1;
- }
- /////////
- struct input_id inputId;
- int rc = ioctl(fd, EVIOCGID, &inputId);
- printf("TK-------->>>>info.vendor is 0x%x ",inputId.vendor);
- printf("TK-------->>>>info.product is 0x%x ",inputId.product);
- printf("TK-------->>>>info.bustype is 0x%x ",inputId.bustype);
- /*
- struct hidraw_devinfo info;
- int rc = ioctl(fd, HIDIOCGRAWINFO, &info);
- printf("TK-------->>>>info.vendor is 0x%x ",info.vendor);
- printf("TK-------->>>>info.product is 0x%x ",info.product);
- printf("TK-------->>>>info.bustype is 0x%x ",info.bustype);
- */
- ///////////
- struct hidraw_report_descriptor descriptor;
- rc = ioctl(fd, HIDIOCGRDESC, &descriptor);
- printf("TK-------->>>>descriptor.size is 0x%04x ",descriptor.size);
- //////
- int descriptorSize=0;
- rc = ioctl(fd, HIDIOCGRDESCSIZE, &descriptorSize);
- printf("TK-------->>>>descriptorSize is 0x%04x ",descriptorSize);
- //////
- name[sizeof(name) - 1] = ' ';
- if(ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
- name[0] = ' ';
- }
- printf("TK------->>>name is %s ",name);
- //////
- close(fd);
- return 0;
- }
二、编译
Android.mk
- LOCAL_PATH:= $(call my-dir)
- include $(CLEAR_VARS)
- LOCAL_SRC_FILES:=
- testhid.c
- LOCAL_SHARED_LIBRARIES :=
- libutils
- LOCAL_MODULE:= testinput
- LOCAL_MODULE_TAGS := optional
- include $(BUILD_EXECUTABLE)
三、运行
- TK-------->>>>info.vendor is 0x0
- TK-------->>>>info.product is 0x1
- TK-------->>>>info.bustype is 0x19
- TK-------->>>>descriptor.size is 0x0000
- TK-------->>>>descriptorSize is 0x0000
- TK------->>>name is Power Button