-
Notifications
You must be signed in to change notification settings - Fork 0
/
knob.c
52 lines (42 loc) · 958 Bytes
/
knob.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
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/input.h>
#include <signal.h>
int running = 1;
void quit(int sig)
{
printf("Closing.\n");
running = 0;
}
int main(int argc, char *argv[])
{
int fid;
int rc;
struct input_event evt[8];
int nevts;
int e;
signal(SIGINT, quit);
fid = open(
"/dev/input/by-path/platform-soc:knob1-event",
O_RDONLY | O_NONBLOCK);
running = 1;
while (running) {
rc = read(fid, evt, sizeof(struct input_event) * 8);
if (rc != -1) {
nevts = rc / sizeof(struct input_event);
for (e = 0; e < nevts; e++) {
if (evt[e].type) {
fprintf(stdout, "%d\n", evt[e].value);
fflush(stdout);
}
}
}
usleep(10);
}
close(fid);
return 0;
}