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
|
/* See LICENSE file for copyright and license details. */
#include "libgamepad.h"
#include <sys/stat.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <math.h>
#include <poll.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <unistd.h>
#include <libsha2.h>
#include <libudev.h>
#if defined(__GNUC__)
# define LIBGAMEPAD_CONST__ __attribute__((__const__))
#else
# define LIBGAMEPAD_CONST__
#endif
#define READ_(ARR, I) ((ARR)[(I) / BITSOF(*(ARR))])
#define SHIFT_(ARR, I) ((I) % BITSOF(*(ARR)))
#define ELEMSOF(A) (sizeof(A) / sizeof(*(A)))
#define BITSOF(T) (8 * sizeof(T))
#define XORBIT(ARR, I) (READ_(ARR, I) ^= 1 << SHIFT_(ARR, I))
#define SETBIT(ARR, I) (READ_(ARR, I) |= 1 << SHIFT_(ARR, I))
#define GETBIT(ARR, I) ((READ_(ARR, I) >> SHIFT_(ARR, I)) & 1)
#define ELEMS_REQUIRED(BITS, TYPE) ((BITS + BITSOF(TYPE) - 1) / BITSOF(TYPE))
#define DEFER_EINTR_(DEVICE, ERROR_CONDITION, GOTO_ON_FAILURE)\
do {\
while (ERROR_CONDITION) {\
if (errno != EINTR)\
goto GOTO_ON_FAILURE;\
(DEVICE)->internals->deferred_error = EINTR;\
}\
} while (0)
struct libgamepad_attachment_monitor {
struct udev *udev;
struct udev_monitor *monitor;
};
struct libgamepad_device_internals {
int deferred_error;
int close_fd;
int require_sync;
struct input_absinfo *absinfo;
uint8_t *buttons;
struct input_event *evbuf;
size_t evbuf_size;
size_t ev_queued;
};
extern const char *libgamepad_button_names__[
#include "button.count"
];
extern const char *libgamepad_absolute_axis_names__[
#include "absolute-axis.count"
];
extern const char *libgamepad_relative_axis_names__[
#include "relative-axis.count"
];
int libgamepad_drain__(struct libgamepad_device *device);
|