-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
64 lines (55 loc) · 1.53 KB
/
main.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
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <poll.h>
#include <time.h>
#include <string.h>
#include "config.h"
#include "event.c"
#include "driver_logic.c"
int main()
{
int event_count;
struct pollfd fds[1];
fds[0].fd = open(GAMEPAD_EVENT_PATH, O_RDONLY | O_NONBLOCK);
if (fds[0].fd < 0)
{
printf("Could not open device '%s'\n", GAMEPAD_EVENT_PATH);
return 1;
}
int event_fd = open_touchscreen_fd(TS_EVENT_PATH);
if (event_fd < 0)
{
printf("Could not open device '%s'\n", TS_EVENT_PATH);
return 1;
}
unsigned char input_data[GAMEPAD_EVENT_READ_SIZE];
memset(input_data, 0, GAMEPAD_EVENT_READ_SIZE);
fds[0].events = POLLIN;
while(true)
{
event_count = poll(fds, 1, POLL_TIMEOUT_MS);
if(event_count > 0)
{
if(!fds[0].revents)
{
printf("warn: Unexpected error: no events were available at fd[0]\n");
continue;
}
ssize_t byte_count = read(fds[0].fd, input_data, GAMEPAD_EVENT_READ_SIZE);
if (byte_count < 0)
{
printf("warn: Unexpected error: read failed\n");
continue;
}
input_event_t* event = (input_event_t*)input_data;
process_new_event(event_fd, event);
memset(input_data, 0, GAMEPAD_EVENT_READ_SIZE);
}
}
close(fds[0].fd);
close_touchscreen_fd(event_fd);
return 0;
}