Created
June 16, 2013 02:48
-
-
Save z4yx/5790563 to your computer and use it in GitHub Desktop.
ir test on swiftboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/time.h> | |
#include <linux/input.h> | |
#include <stdlib.h> | |
//根据实际情况修改 | |
const char *input_dev = "/dev/input/event1"; | |
char *type_name(__u16 type) | |
{ | |
static char *name[6] = {"EV_SYN","EV_KEY","EV_REL","EV_ABS","EV_MSC","EV_SW"}; | |
if(type > 5) | |
return NULL; | |
return name[type]; | |
} | |
int main() | |
{ | |
FILE *fp; | |
struct input_event event; | |
fp = fopen(input_dev, "r"); | |
if(!fp){ | |
printf("can't open %s\n", input_dev); | |
return 1; | |
} | |
for(;;){ | |
if(1 != fread(&event, sizeof(event), 1, fp)){ | |
perror("fread"); | |
break; | |
} | |
printf("time=%ld.%06ld type=%s code=%hu value=%d\n", | |
event.time.tv_sec, | |
event.time.tv_usec, | |
type_name(event.type), | |
event.code, | |
event.value | |
); | |
} | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment