a34fd83277723d9397905669bc8a47451ef10a1b
3 #include <linux/input.h>
12 typedef struct event_s
{
27 int main(int argc
, char *argv
[]) {
30 event_t events
[EVENTS
];
33 while((optch
= getopt(argc
, argv
, "hv")) != -1) {
36 printf("Usage: %s [-v|-h]\n", argv
[0]);
45 signal(SIGINT
, sigint
);
47 printf("Press CTRL-C to exit.\n\n");
49 memset(events
, 0, sizeof(events
));
52 for(i
= 0; i
< EVENTS
; i
++) {
55 sprintf(device
, "/dev/input/event%i", i
);
56 events
[i
].fd
= open(device
, O_RDONLY
);
58 if(events
[i
].fd
!= -1) {
59 ioctl(events
[i
].fd
, EVIOCGNAME(sizeof(events
[i
].name
)), events
[i
].name
);
60 if(verbose
) printf("event%i: %s\n", i
, events
[i
].name
);
69 for(i
= 0; i
< EVENTS
; i
++) {
70 if(events
[i
].fd
!= -1) {
71 FD_SET(events
[i
].fd
, &set
);
75 if(select(FD_SETSIZE
, &set
, NULL
, NULL
, NULL
) > 0) {
77 struct input_event event
;
79 for(i
= 0; i
< EVENTS
; i
++) {
80 if(events
[i
].fd
== -1 || !FD_ISSET(events
[i
].fd
, &set
)) {
84 bytes
= read(events
[i
].fd
, &event
, sizeof(event
));
86 if(bytes
!= sizeof(event
)) {
90 if(event
.type
== EV_REL
) {
94 time
= event
.time
.tv_sec
* 1000 + event
.time
.tv_usec
/ 1000;
95 hz
= 1000 / (time
- events
[i
].prvtime
);
101 events
[i
].hz
[events
[i
].count
& (HZ_LIST
- 1)] = hz
;
105 for(j
= 0; j
< HZ_LIST
; j
++) {
106 events
[i
].avghz
+= events
[i
].hz
[j
];
109 events
[i
].avghz
/= (events
[i
].count
> HZ_LIST
) ? HZ_LIST
: events
[i
].count
;
111 if(verbose
) printf("%s: Latest % 5iHz, Average % 5iHz\n", events
[i
].name
, hz
, events
[i
].avghz
);
114 events
[i
].prvtime
= time
;
120 for(i
= 0; i
< EVENTS
; i
++) {
121 if(events
[i
].fd
!= -1) {
122 if (events
[i
].avghz
!= 0) {
123 printf("\nAverage for %s: % 5iHz\n", events
[i
].name
, events
[i
].avghz
);