193185ae16f22f5a46d94eca46720ff9aaec4a60
3 #include <linux/input.h>
10 typedef struct event_s
{
20 signal(SIGINT
, sigint
);
24 int main(int argc
, char **argv
) {
26 event_t events
[EVENTS
];
28 signal(SIGINT
, sigint
);
30 printf("Press CTRL-C to exit.\n\n");
32 memset(events
, 0, sizeof(events
));
34 for(i
= 0; i
< EVENTS
; i
++) {
37 sprintf(device
, "/dev/input/event%i", i
);
38 events
[i
].fd
= open(device
, O_RDONLY
);
40 if(events
[i
].fd
!= -1) {
42 ioctl(events
[i
].fd
, EVIOCGNAME(sizeof(name
)), name
);
43 printf("event%i: %s\n", i
, name
);
52 for(i
= 0; i
< EVENTS
; i
++) {
53 if(events
[i
].fd
!= -1) {
54 FD_SET(events
[i
].fd
, &set
);
58 if(select(FD_SETSIZE
, &set
, NULL
, NULL
, NULL
) > 0) {
60 struct input_event event
;
62 for(i
= 0; i
< EVENTS
; i
++) {
63 if(events
[i
].fd
== -1) {
67 if(!FD_ISSET(events
[i
].fd
, &set
)) {
71 bytes
= read(events
[i
].fd
, &event
, sizeof(event
));
73 if(bytes
!= sizeof(event
)) {
77 if(event
.type
== EV_REL
) {
81 time
= event
.time
.tv_sec
* 1000 + event
.time
.tv_usec
/ 1000;
82 hz
= 1000 / (time
- events
[i
].prvtime
);
89 events
[i
].hz
[events
[i
].count
& (HZ_LIST
- 1)] = hz
;
93 for(j
= 0; j
< HZ_LIST
; j
++) {
94 avghz
+= events
[i
].hz
[j
];
97 avghz
/= (events
[i
].count
> HZ_LIST
) ? HZ_LIST
: events
[i
].count
;
99 printf("event%i: latest hz = %i (average hz = %i)\n", i
, hz
, avghz
);
102 events
[i
].prvtime
= time
;
108 for(i
= 0; i
< EVENTS
; i
++) {
109 if(events
[i
].fd
!= -1) {