6 #include "../linux/in_evdev.h"
18 #define IN_MAX_DEVS 10
20 static in_dev_t in_devices[IN_MAX_DEVS];
21 static int in_dev_count = 0;
23 static int in_bind_count(int drv_id)
26 if (drv_id == IN_DRVID_EVDEV)
27 count = in_evdev_bind_count();
29 printf("input: failed to get bind count for drv %d\n", drv_id);
34 static int *in_alloc_binds(int drv_id)
38 count = in_bind_count(drv_id);
40 printf("input: failed to get bind count for drv %d\n", drv_id);
44 ret = malloc(count * sizeof(*ret));
48 static void in_free(in_dev_t *dev)
51 if (dev->drv_id == IN_DRVID_EVDEV)
52 in_evdev_free(dev->drv_data);
62 /* to be called by drivers */
63 void in_register(const char *nname, int drv_id, void *drv_data)
65 int i, dupe_count = 0, *binds;
66 char name[256], *name_end, *tmp;
68 strncpy(name, nname, sizeof(name));
69 name[sizeof(name)-12] = 0;
70 name_end = name + strlen(name);
72 for (i = 0; i < in_dev_count; i++)
74 if (in_devices[i].name == NULL)
76 if (strcmp(in_devices[i].name, name) == 0)
78 if (in_devices[i].probed) {
80 sprintf(name_end, " [%d]", dupe_count);
89 /* try to find unused device */
90 for (i = 0; i < IN_MAX_DEVS; i++)
91 if (!in_devices[i].probed) break;
92 if (i >= IN_MAX_DEVS) {
93 printf("input: too many devices, can't add %s\n", name);
96 in_free(&in_devices[i]);
103 binds = in_alloc_binds(drv_id);
109 in_devices[i].name = tmp;
110 in_devices[i].binds = binds;
111 if (i + 1 > in_dev_count)
112 in_dev_count = i + 1;
114 printf("input: new device #%d \"%s\"\n", i, name);
116 in_devices[i].probed = 1;
117 in_devices[i].drv_id = drv_id;
118 in_devices[i].drv_data = drv_data;
124 for (i = 0; i < in_dev_count; i++)
125 in_devices[i].probed = 0;
129 /* get rid of devs without binds and probes */
130 for (i = 0; i < in_dev_count; i++) {
131 if (!in_devices[i].probed && in_devices[i].binds == NULL) {
133 if (i < in_dev_count) {
134 free(in_devices[i].name);
135 memmove(&in_devices[i], &in_devices[i+1],
136 (in_dev_count - i) * sizeof(in_devices[0]));
142 void in_clear_binds(const char *devname)
146 count = in_bind_count(drv_id);
148 printf("input: failed to get bind count for drv %d\n", dev->drv_id);
158 for (i = 0; i < in_dev_count; i++) {
159 if (in_devices[i].probed && in_devices[i].binds != NULL) {
160 if (in_devices[i].drv_id == IN_DRVID_EVDEV)
161 result |= in_evdev_update(in_devices[i].drv_data, in_devices[i].binds);
169 * update with wait for a press, return bitfield of BTN_*
170 * only can use 1 drv here..
172 int in_update_menu(void)
176 void *data[IN_MAX_DEVS];
179 for (i = 0; i < in_dev_count; i++) {
180 if (in_devices[i].probed)
181 data[count++] = in_devices[i].drv_data;
185 /* don't deadlock, fail */
186 printf("input: failed to find devices to read\n");
190 result = in_evdev_update_menu(data, count);
192 #error no menu read handlers
200 memset(in_devices, 0, sizeof(in_devices));
212 ret = in_update_menu();
213 printf("%08x\n", ret);