forked from xboxdrv/xboxdrv
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathevtestplus.cpp
82 lines (70 loc) · 1.77 KB
/
evtestplus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <dirent.h>
#include <fcntl.h>
#include <linux/input.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
void process_device(int fd) {
int version;
if (ioctl(fd, EVIOCGVERSION, &version) < 0) {
perror("evtest: can't get version");
exit(1);
}
if (1) {
char phys[1024];
if (ioctl(fd, EVIOCGNAME(sizeof(phys)), &phys) < 0) {
perror("evtest: can't get name");
exit(1);
}
std::cout << "Name: " << phys << std::endl;
}
if (1) {
char phys[1024];
if (ioctl(fd, EVIOCGPHYS(sizeof(phys)), &phys) < 0) {
perror("evtest: can't get phys");
exit(1);
}
std::cout << "Phys: " << phys << std::endl;
}
if (0) {
char phys[1024];
if (ioctl(fd, EVIOCGUNIQ(sizeof(phys)), &phys) < 0) {
perror("evtest: can't get uniq");
exit(1);
}
std::cout << "Uniq: " << phys << std::endl;
}
std::cout << "Version: " << (version >> 16) << "." << ((version >> 8) & 0xff)
<< "." << (version & 0xff) << std::endl;
/* unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
ioctl(fd, EVIOCGID, id);
ioctl(fd, EVIOCGNAME(sizeof(name)), name);
memset(bit, 0, sizeof(bit));
ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]);*/
}
/**
evtestplus
--list List available devices
--test DEVICE Test device
--info DEVICE List properties of device
*/
int main(int argc, char** argv) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " DEVICE" << std::endl;
exit(EXIT_FAILURE);
} else {
const char* filename = argv[1];
int fd;
if ((fd = open(filename, O_RDONLY)) < 0) {
perror(filename);
} else {
process_device(fd);
close(fd);
}
}
return 0;
}
/* EOF */