a7a42be54b81329e07cbdf353b172cb10871c02c
2 #include <linux/input.h>
9 typedef struct event_s
{
19 signal(SIGINT
, sigint
);
23 int main(int argc
, char **argv
) {
25 event_t events
[EVENTS
];
27 signal(SIGINT
, sigint
);
29 printf("Press CTRL-C to exit.\n\n");
31 memset(events
, 0, sizeof(events
));
33 for(i
= 0; i
< EVENTS
; i
++) {
36 sprintf(device
, "/dev/input/event%i", i
);
37 events
[i
].fd
= open(device
, O_RDONLY
);
39 if(events
[i
].fd
!= -1) {
41 ioctl(events
[i
].fd
, EVIOCGNAME(sizeof(name
)), name
);
42 printf("event%i: %s\n", i
, name
);
51 for(i
= 0; i
< EVENTS
; i
++) {
52 if(events
[i
].fd
!= -1) {
53 FD_SET(events
[i
].fd
, &set
);
57 if(select(FD_SETSIZE
, &set
, NULL
, NULL
, NULL
) > 0) {
59 struct input_event event
;
61 for(i
= 0; i
< EVENTS
; i
++) {
62 if(events
[i
].fd
== -1) {
66 if(!FD_ISSET(events
[i
].fd
, &set
)) {
70 bytes
= read(events
[i
].fd
, &event
, sizeof(event
));
72 if(bytes
!= sizeof(event
)) {
76 if(event
.type
== EV_REL
) {
80 time
= event
.time
.tv_sec
* 1000 + event
.time
.tv_usec
/ 1000;
81 hz
= 1000 / (time
- events
[i
].prvtime
);
88 events
[i
].hz
[events
[i
].count
& (HZ_LIST
- 1)] = hz
;
92 for(j
= 0; j
< HZ_LIST
; j
++) {
93 avghz
+= events
[i
].hz
[j
];
96 avghz
/= (events
[i
].count
> HZ_LIST
) ? HZ_LIST
: events
[i
].count
;
98 printf("event%i: latest hz = %i (average hz = %i)\n", i
, hz
, avghz
);
101 events
[i
].prvtime
= time
;
107 for(i
= 0; i
< EVENTS
; i
++) {
108 if(events
[i
].fd
!= -1) {