-
Notifications
You must be signed in to change notification settings - Fork 1
/
evls.c
196 lines (186 loc) · 8.19 KB
/
evls.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>
#include <errno.h>
#include <string.h>
#include "input.generated.h"
#define die(...) fprintf(stderr, __VA_ARGS__), exit(1)
// true if bit b is set in byte array a
#define set(a, b) (a[(b)/8] & (1 << ((b) & 7)))
int main(int argc, char *argv[])
{
for (int ev = 0; ev < 32; ev++)
{
char device[32];
sprintf(device, "/dev/input/event%d", ev);
int fd = open(device, O_RDONLY);
if (fd < 0)
{
if (errno != ENOENT) die("Can't open %s: %s\n", device, strerror(errno));
goto next;
}
printf("%s:\n", device);
char name[64];
if (ioctl(fd, EVIOCGNAME(sizeof name), name) < 0) *name = 0;
printf(" Name \"%s\"\n", *name ? name : "Name unknown");
int version;
if (ioctl(fd, EVIOCGVERSION, &version))
{
printf(" EVIOCGVERSION failed\n");
goto next;
}
else if (version != EV_VERSION)
{
printf(" Unexpected stack version %d\n", version);
goto next;
}
struct input_id id;
if (ioctl(fd, EVIOCGID, &id))
{
printf(" EVIOCGID failed\n");
goto next;
}
printf(" Vendor %d\n", id.vendor);
printf(" Product %d\n", id.product);
printf(" Version %d\n", id.version);
printf(" Bus type %d is %s\n", id.bustype, ed_BUS(id.bustype)?:"unknown");
uint8_t capabilities[(EV_MAX+7)/8];
if (ioctl(fd, EVIOCGBIT(0, sizeof capabilities), capabilities) != sizeof capabilities)
{
printf(" EVIOCGBIT(0) failed\n");
goto next;
}
for (int bit = 1; bit < EV_MAX; bit++) // note, skip bit 0 = EV_SYN
if (set(capabilities, bit))
{
printf(" Capability %d is %s\n", bit, ed_EV(bit)?:"unknown");
switch(bit)
{
case EV_KEY:
{
uint32_t repeat[2];
if (!ioctl(fd, EVIOCGREP, &repeat))
{
printf(" Repeat delay %d mS\n", repeat[0]);
printf(" Repeat period %d mS\n", repeat[1]);
}
uint8_t supported[(KEY_MAX+7)/8];
if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(supported)), supported) == sizeof supported)
{
int8_t status[(KEY_MAX+7)/8];
bool valid = (ioctl(fd, EVIOCGKEY(sizeof(status)), status) == sizeof status);
for (int bit = 0; bit < KEY_MAX; bit++)
if (set(supported, bit))
{
if (valid && set(status, bit))
printf(" Active key %d is %s\n", bit, ed_KEY(bit)?:ed_BTN(bit)?:"unknown");
else
printf(" Key %d is %s\n", bit, ed_KEY(bit)?:ed_BTN(bit)?:"unknown");
}
}
break;
}
case EV_REL:
{
uint8_t supported[(REL_MAX+7)/8];
if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof supported), supported) == sizeof supported)
for (int bit = 0; bit < REL_MAX; bit++)
if (set(supported, bit))
printf(" Relative event %d is %s\n", bit, ed_REL(bit)?:"unknown");
break;
}
case EV_ABS:
{
uint8_t supported[(ABS_MAX+7)/8];
if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(supported)), supported) == sizeof supported)
for (int bit = 0; bit < ABS_MAX; bit++)
if (set(supported, bit))
{
printf(" Axis %d is %s\n", bit, ed_ABS(bit)?:"unknown");
struct input_absinfo i;
if (!ioctl(fd, EVIOCGABS(bit), &i))
{
printf(" Value : %d\n", i.value);
printf(" Minimum : %d\n", i.minimum);
printf(" Maximum : %d\n", i.maximum);
printf(" Fuzz : %d\n", i.fuzz);
printf(" Flat : %d\n", i.flat);
printf(" Resolution: %d\n", i.resolution);
}
}
break;
}
case EV_MSC:
{
uint8_t supported[(MSC_MAX+7)/8];
if (ioctl(fd, EVIOCGBIT(EV_MSC, sizeof supported), supported) == sizeof supported)
for (int bit = 0; bit < MSC_MAX; bit++)
if (set(supported, bit))
printf(" Misc event %d is %s\n", bit, ed_MSC(bit)?:"unknown");
break;
}
case EV_SW:
{
uint8_t supported[(SW_MAX+7)/8];
if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof supported), supported) == sizeof supported)
{
uint8_t status[sizeof supported];
bool valid = (ioctl(fd, EVIOCGSW(sizeof(status)), status) == sizeof status);
for (int bit = 0; bit < SW_MAX; bit++)
if (set(supported, bit))
{
if (valid && set(status, bit))
printf(" Active switch %d is %s\n", bit, ed_SW(bit)?:"unknown");
else
printf(" Switch %d is %s\n", bit, ed_SW(bit)?:"unknown");
}
}
}
case EV_LED:
{
uint8_t supported[(LED_MAX+7)/8];
if (ioctl(fd, EVIOCGBIT(EV_LED, sizeof supported), supported) == sizeof supported)
{
uint8_t status[sizeof supported];
bool valid = (ioctl(fd, EVIOCGLED(sizeof(status)), status) == sizeof status);
for (int bit = 0; bit < LED_MAX; bit++)
if (set(supported, bit))
{
if (valid && set(status, bit))
printf(" Active LED %d is %s\n", bit, ed_LED(bit)?:"unknown");
else
printf(" LED %d is %s\n", bit, ed_LED(bit)?:"unknown");
}
}
break;
}
case EV_SND:
{
uint8_t supported[(SND_MAX+7)/8];
if (ioctl(fd, EVIOCGBIT(EV_SND, sizeof supported), supported) == sizeof supported)
{
uint8_t status[sizeof supported];
bool valid = (ioctl(fd, EVIOCGSND(sizeof(status)), status) == sizeof status);
for (int bit = 0; bit < SND_MAX; bit++)
if (set(supported, bit))
{
if (valid && set(status, bit))
printf(" Active sound %d is %s\n", bit, ed_SND(bit)?:"unknown");
else
printf(" Sound %d is %s\n", bit, ed_SND(bit)?:"unknown");
}
}
break;
}
}
}
next: close(fd);
}
}