Skip to content

Instantly share code, notes, and snippets.

@z4yx
Created June 16, 2013 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z4yx/5790563 to your computer and use it in GitHub Desktop.
Save z4yx/5790563 to your computer and use it in GitHub Desktop.
ir test on swiftboard
#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