key combos for new input code
[picodrive.git] / platform / common / input.c
CommitLineData
e1f99f2b 1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
b6820926 5#include "common.h"
e1f99f2b 6#include "input.h"
0403eead 7#include "plat.h"
3b13ec65 8#include "../linux/in_evdev.h"
217d08bc 9#include "../gp2x/in_gp2x.h"
e1f99f2b 10
11typedef struct
12{
13 int drv_id;
7201dc73 14 int drv_fd_hnd;
e1f99f2b 15 void *drv_data;
e1f99f2b 16 char *name;
f484a9fe 17 int *binds;
e1f99f2b 18 int probed:1;
9025b931 19 int does_combos:1;
e1f99f2b 20} in_dev_t;
21
819ef025 22static in_drv_t in_drivers[IN_DRVID_COUNT];
e1f99f2b 23static in_dev_t in_devices[IN_MAX_DEVS];
24static int in_dev_count = 0;
217d08bc 25static int in_have_async_devs = 0;
e1f99f2b 26
819ef025 27#define DRV(id) in_drivers[(unsigned)(id) < IN_DRVID_COUNT ? (id) : 0]
28
217d08bc 29
e1f99f2b 30static int in_bind_count(int drv_id)
31{
819ef025 32 int count = DRV(drv_id).get_bind_count();
e1f99f2b 33 if (count <= 0)
34 printf("input: failed to get bind count for drv %d\n", drv_id);
35
36 return count;
37}
38
39static int *in_alloc_binds(int drv_id)
40{
819ef025 41 int count, *binds;
e1f99f2b 42
43 count = in_bind_count(drv_id);
819ef025 44 if (count <= 0)
e1f99f2b 45 return NULL;
e1f99f2b 46
819ef025 47 binds = calloc(count * 2, sizeof(binds[0]));
48 if (binds == NULL)
49 return NULL;
50
51 DRV(drv_id).get_def_binds(binds + count);
52 memcpy(binds, binds + count, count * sizeof(binds[0]));
53
54 return binds;
e1f99f2b 55}
56
57static void in_free(in_dev_t *dev)
58{
819ef025 59 if (dev->probed)
60 DRV(dev->drv_id).free(dev->drv_data);
e1f99f2b 61 dev->probed = 0;
62 dev->drv_data = NULL;
63 free(dev->name);
64 dev->name = NULL;
65 free(dev->binds);
66 dev->binds = NULL;
67}
68
217d08bc 69/* to be called by drivers
70 * async devices must set drv_fd_hnd to -1 */
9025b931 71void in_register(const char *nname, int drv_id, int drv_fd_hnd, void *drv_data, int combos)
e1f99f2b 72{
819ef025 73 int i, ret, dupe_count = 0, *binds;
e1f99f2b 74 char name[256], *name_end, *tmp;
75
76 strncpy(name, nname, sizeof(name));
77 name[sizeof(name)-12] = 0;
78 name_end = name + strlen(name);
79
80 for (i = 0; i < in_dev_count; i++)
81 {
82 if (in_devices[i].name == NULL)
83 continue;
84 if (strcmp(in_devices[i].name, name) == 0)
85 {
86 if (in_devices[i].probed) {
87 dupe_count++;
88 sprintf(name_end, " [%d]", dupe_count);
89 continue;
90 }
91 goto update;
92 }
93 }
94
95 if (i >= IN_MAX_DEVS)
96 {
97 /* try to find unused device */
98 for (i = 0; i < IN_MAX_DEVS; i++)
99 if (!in_devices[i].probed) break;
100 if (i >= IN_MAX_DEVS) {
101 printf("input: too many devices, can't add %s\n", name);
102 return;
103 }
104 in_free(&in_devices[i]);
105 }
106
107 tmp = strdup(name);
108 if (tmp == NULL)
109 return;
110
111 binds = in_alloc_binds(drv_id);
112 if (binds == NULL) {
113 free(tmp);
114 return;
115 }
116
117 in_devices[i].name = tmp;
118 in_devices[i].binds = binds;
119 if (i + 1 > in_dev_count)
120 in_dev_count = i + 1;
121
122 printf("input: new device #%d \"%s\"\n", i, name);
123update:
124 in_devices[i].probed = 1;
9025b931 125 in_devices[i].does_combos = combos;
e1f99f2b 126 in_devices[i].drv_id = drv_id;
7201dc73 127 in_devices[i].drv_fd_hnd = drv_fd_hnd;
e1f99f2b 128 in_devices[i].drv_data = drv_data;
819ef025 129
130 if (in_devices[i].binds != NULL) {
131 ret = DRV(drv_id).clean_binds(drv_data, in_devices[i].binds);
132 if (ret == 0) {
133 /* no useable binds */
134 free(in_devices[i].binds);
135 in_devices[i].binds = NULL;
136 }
137 }
e1f99f2b 138}
139
9025b931 140/* key combo handling, to be called by drivers that support it */
141void in_combos_find(int *binds, int last_key, int *combo_keys, int *combo_acts)
142{
143 int act, u;
144
145 *combo_keys = *combo_acts = 0;
146 for (act = 0; act < sizeof(binds[0]) * 8; act++)
147 {
148 int keyc = 0;
149 for (u = 0; u <= last_key; u++)
150 if (binds[u] & (1 << act))
151 keyc++;
152
153 if (keyc > 1)
154 {
155 // loop again and mark those keys and actions as combo
156 for (u = 0; u <= last_key; u++)
157 {
158 if (binds[u] & (1 << act)) {
159 *combo_keys |= 1 << u;
160 *combo_acts |= 1 << act;
161 }
162 }
163 }
164 }
165}
166
167int in_combos_do(int keys, int *binds, int last_key, int combo_keys, int combo_acts)
168{
169 int i, ret = 0;
170
171 for (i = 0; i <= last_key; i++)
172 {
173 int acts;
174 if (!(keys & (1 << i)))
175 continue;
176
177 acts = binds[i];
178 if (!acts)
179 continue;
180
181 if (combo_keys & (1 << i))
182 {
183 int acts_c = acts & combo_acts;
184 int u = last_key;
185 if (acts_c) {
186 // let's try to find the other one
187 for (u = i + 1; u <= last_key; u++)
188 if ( (keys & (1 << u)) && (binds[u] & acts_c) ) {
189 ret |= acts_c & binds[u];
190 keys &= ~((1 << i) | (1 << u));
191 break;
192 }
193 }
194 // add non-combo actions if combo ones were not found
195 if (u >= last_key)
196 ret |= acts & ~combo_acts;
197 } else
198 ret |= acts;
199 }
200
201 return ret;
202}
203
e1f99f2b 204void in_probe(void)
205{
206 int i;
217d08bc 207
208 in_have_async_devs = 0;
e1f99f2b 209 for (i = 0; i < in_dev_count; i++)
210 in_devices[i].probed = 0;
211
819ef025 212 for (i = 1; i < IN_DRVID_COUNT; i++)
213 in_drivers[i].probe();
e1f99f2b 214
215 /* get rid of devs without binds and probes */
216 for (i = 0; i < in_dev_count; i++) {
217 if (!in_devices[i].probed && in_devices[i].binds == NULL) {
218 in_dev_count--;
219 if (i < in_dev_count) {
220 free(in_devices[i].name);
221 memmove(&in_devices[i], &in_devices[i+1],
222 (in_dev_count - i) * sizeof(in_devices[0]));
223 }
217d08bc 224
225 continue;
e1f99f2b 226 }
217d08bc 227
228 if (in_devices[i].probed && in_devices[i].drv_fd_hnd == -1)
229 in_have_async_devs = 1;
e1f99f2b 230 }
217d08bc 231
232 if (in_have_async_devs)
233 printf("input: async-only devices detected..\n");
e1f99f2b 234}
235
7201dc73 236/* async update */
e1f99f2b 237int in_update(void)
238{
239 int i, result = 0;
240
241 for (i = 0; i < in_dev_count; i++) {
f484a9fe 242 in_dev_t *dev = &in_devices[i];
f484a9fe 243 if (dev->probed && dev->binds != NULL) {
244 switch (dev->drv_id) {
819ef025 245#ifdef IN_EVDEV
3427e573 246 case IN_DRVID_EVDEV:
483230c7 247 result |= in_evdev_update(dev->drv_data, dev->binds);
3427e573 248 break;
217d08bc 249#endif
250#ifdef IN_GP2X
251 case IN_DRVID_GP2X:
252 result |= in_gp2x_update(dev->drv_data, dev->binds);
253 break;
819ef025 254#endif
3427e573 255 }
e1f99f2b 256 }
257 }
258
259 return result;
260}
261
f484a9fe 262static int menu_key_state = 0;
263
3427e573 264void in_set_blocking(int is_blocking)
265{
217d08bc 266 int i, ret;
3427e573 267
217d08bc 268 /* have_async_devs means we will have to do all reads async anyway.. */
269 if (!in_have_async_devs) {
270 for (i = 0; i < in_dev_count; i++) {
271 if (in_devices[i].probed)
272 DRV(in_devices[i].drv_id).set_blocking(in_devices[i].drv_data, is_blocking);
273 }
3427e573 274 }
f484a9fe 275
276 menu_key_state = 0;
217d08bc 277
f484a9fe 278 /* flush events */
217d08bc 279 do {
280 ret = in_update_keycode(NULL, NULL, 0);
281 } while (ret >= 0);
3427e573 282}
283
217d08bc 284static int in_update_kc_async(int *dev_id_out, int *is_down_out, int timeout_ms)
285{
217d08bc 286 int i, is_down, result;
0403eead 287 unsigned int ticks;
217d08bc 288
0403eead 289 ticks = plat_get_ticks_ms();
217d08bc 290
291 while (1)
292 {
293 for (i = 0; i < in_dev_count; i++) {
294 in_dev_t *d = &in_devices[i];
295 if (!d->probed)
296 continue;
297
298 result = DRV(d->drv_id).update_keycode(d->drv_data, &is_down);
299 if (result == -1)
300 continue;
301
302 if (dev_id_out)
303 *dev_id_out = i;
304 if (is_down_out)
305 *is_down_out = is_down;
306 return result;
307 }
308
0403eead 309 if (timeout_ms >= 0 && (int)(plat_get_ticks_ms() - ticks) > timeout_ms)
310 break;
217d08bc 311
0403eead 312 plat_sleep_ms(10);
217d08bc 313 }
314
315 return -1;
316}
7201dc73 317
3b13ec65 318/*
217d08bc 319 * wait for a press, always return some keycode or -1 on timeout or error
3b13ec65 320 */
f484a9fe 321int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
3b13ec65 322{
0403eead 323 int result = -1, dev_id = 0, is_down, result_menu;
7201dc73 324 int fds_hnds[IN_MAX_DEVS];
325 int i, ret, count = 0;
74f5e726 326 in_drv_t *drv = NULL;
0403eead 327 unsigned int ticks;
7201dc73 328
217d08bc 329 if (in_have_async_devs) {
330 result = in_update_kc_async(&dev_id, &is_down, timeout_ms);
331 if (result == -1)
332 return -1;
333 drv = &DRV(in_devices[dev_id].drv_id);
334 goto finish;
335 }
336
0403eead 337 ticks = plat_get_ticks_ms();
338
7201dc73 339 for (i = 0; i < in_dev_count; i++) {
340 if (in_devices[i].probed)
341 fds_hnds[count++] = in_devices[i].drv_fd_hnd;
342 }
3b13ec65 343
344 if (count == 0) {
345 /* don't deadlock, fail */
346 printf("input: failed to find devices to read\n");
347 exit(1);
348 }
349
0403eead 350 while (1)
7201dc73 351 {
0403eead 352 ret = plat_wait_event(fds_hnds, count, timeout_ms);
353 if (ret < 0)
354 break;
7201dc73 355
0403eead 356 for (i = 0; i < in_dev_count; i++) {
357 if (in_devices[i].drv_fd_hnd == ret) {
358 dev_id = i;
359 break;
360 }
7201dc73 361 }
362
0403eead 363 drv = &DRV(in_devices[dev_id].drv_id);
364 result = drv->update_keycode(in_devices[dev_id].drv_data, &is_down);
7201dc73 365
0403eead 366 /* update_keycode() might return -1 when some not interesting
367 * event happened, like sync event for evdev. */
368 if (result >= 0)
f484a9fe 369 break;
0403eead 370
371 if (timeout_ms >= 0) {
372 unsigned int ticks2 = plat_get_ticks_ms();
373 timeout_ms -= ticks2 - ticks;
374 ticks = ticks2;
375 if (timeout_ms <= 0)
376 break;
3427e573 377 }
378 }
7201dc73 379
217d08bc 380 if (result == -1)
0403eead 381 return -1;
217d08bc 382finish:
f484a9fe 383 /* keep track of menu key state, to allow mixing
b6820926 384 * in_update_keycode() and in_menu_wait_any() calls */
7201dc73 385 result_menu = drv->menu_translate(result);
f484a9fe 386 if (result_menu != 0) {
387 if (is_down)
388 menu_key_state |= result_menu;
389 else
390 menu_key_state &= ~result_menu;
391 }
392
393 if (dev_id_out != NULL)
394 *dev_id_out = dev_id;
395 if (is_down_out != NULL)
396 *is_down_out = is_down;
3b13ec65 397 return result;
398}
399
b6820926 400/* same as above, only return bitfield of PBTN_* */
401int in_menu_wait_any(int timeout_ms)
3427e573 402{
f484a9fe 403 int keys_old = menu_key_state;
3427e573 404
405 while (1)
406 {
819ef025 407 int code, is_down = 0, dev_id = 0;
3427e573 408
f484a9fe 409 code = in_update_keycode(&dev_id, &is_down, timeout_ms);
217d08bc 410 if (code >= 0)
411 code = DRV(in_devices[dev_id].drv_id).menu_translate(code);
3427e573 412
b6820926 413 if (timeout_ms >= 0)
f484a9fe 414 break;
217d08bc 415 if (code < 0)
f484a9fe 416 continue;
417 if (keys_old != menu_key_state)
3427e573 418 break;
419 }
420
f484a9fe 421 return menu_key_state;
3427e573 422}
423
b6820926 424/* wait for menu input, do autorepeat */
713c9224 425int in_menu_wait(int interesting, int autorep_delay_ms)
b6820926 426{
427 static int inp_prev = 0;
299acadc 428 static int repeats = 0;
9025b931 429 int ret, release = 0, wait = 450;
b6820926 430
299acadc 431 if (repeats)
713c9224 432 wait = autorep_delay_ms;
b6820926 433
299acadc 434 ret = in_menu_wait_any(wait);
435 if (ret == inp_prev)
436 repeats++;
b6820926 437
438 while (!(ret & interesting)) {
439 ret = in_menu_wait_any(-1);
440 release = 1;
441 }
442
299acadc 443 if (release || ret != inp_prev)
b6820926 444 repeats = 0;
299acadc 445
b6820926 446 inp_prev = ret;
447
299acadc 448 /* we don't need diagonals in menus */
b6820926 449 if ((ret & PBTN_UP) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;
450 if ((ret & PBTN_UP) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
451 if ((ret & PBTN_DOWN) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;
452 if ((ret & PBTN_DOWN) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
453
454 return ret;
455}
456
819ef025 457const int *in_get_dev_binds(int dev_id)
458{
459 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
460 return NULL;
461
462 return in_devices[dev_id].binds;
463}
464
465const int *in_get_dev_def_binds(int dev_id)
466{
467 int count;
468
469 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
470 return NULL;
471
472 count = in_bind_count(in_devices[dev_id].drv_id);
473 return in_devices[dev_id].binds + count;
474}
475
9025b931 476int in_get_dev_info(int dev_id, int what)
819ef025 477{
478 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
479 return 0;
480
9025b931 481 switch (what) {
482 case IN_INFO_BIND_COUNT:
483 return in_bind_count(in_devices[dev_id].drv_id);
484 case IN_INFO_DOES_COMBOS:
485 return in_devices[dev_id].does_combos;
486 }
487
488 return 0;
819ef025 489}
490
713c9224 491const char *in_get_dev_name(int dev_id, int must_be_active, int skip_pfix)
819ef025 492{
713c9224 493 const char *name, *tmp;
494
819ef025 495 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
496 return NULL;
497
b6820926 498 if (must_be_active && !in_devices[dev_id].probed)
499 return NULL;
713c9224 500
501 name = in_devices[dev_id].name;
8c2a3661 502 if (name == NULL || !skip_pfix)
503 return name;
027c898c 504
8c2a3661 505 /* skip prefix */
713c9224 506 tmp = strchr(name, ':');
507 if (tmp != NULL)
508 name = tmp + 1;
509
510 return name;
819ef025 511}
512
f484a9fe 513/* never returns NULL */
3427e573 514const char *in_get_key_name(int dev_id, int keycode)
515{
f484a9fe 516 static char xname[16];
517 const char *name;
518
3427e573 519 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
520 return "Unkn0";
819ef025 521
f484a9fe 522 name = DRV(in_devices[dev_id].drv_id).get_key_name(keycode);
523 if (name != NULL)
524 return name;
525
526 /* assume scancode */
527 if ((keycode >= '0' && keycode <= '9') || (keycode >= 'a' && keycode <= 'z')
528 || (keycode >= 'A' && keycode <= 'Z'))
529 sprintf(xname, "%c", keycode);
530 else
531 sprintf(xname, "\\x%02X", keycode);
532 return xname;
533}
534
535int in_bind_key(int dev_id, int keycode, int mask, int force_unbind)
536{
537 int ret, count;
538 in_dev_t *dev;
539
540 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
541 return -1;
542 dev = &in_devices[dev_id];
543
544 if (dev->binds == NULL) {
545 if (force_unbind)
546 return 0;
547 dev->binds = in_alloc_binds(dev->drv_id);
548 if (dev->binds == NULL)
549 return -1;
550 }
551
552 count = in_bind_count(dev->drv_id);
553 if (keycode < 0 || keycode >= count)
554 return -1;
555
556 if (force_unbind)
557 dev->binds[keycode] &= ~mask;
558 else
559 dev->binds[keycode] ^= mask;
560
561 ret = DRV(dev->drv_id).clean_binds(dev->drv_data, dev->binds);
562 if (ret == 0) {
563 free(dev->binds);
564 dev->binds = NULL;
565 }
566
567 return 0;
819ef025 568}
569
570/* returns device id, or -1 on error */
571int in_config_parse_dev(const char *name)
572{
573 int drv_id = -1, i;
574
575 for (i = 0; i < IN_DRVID_COUNT; i++) {
576 int len = strlen(in_drivers[i].prefix);
577 if (strncmp(name, in_drivers[i].prefix, len) == 0) {
578 drv_id = i;
579 break;
580 }
581 }
582
583 if (drv_id < 0) {
584 printf("input: missing driver for %s\n", name);
585 return -1;
586 }
587
588 for (i = 0; i < in_dev_count; i++)
589 {
590 if (in_devices[i].name == NULL)
591 continue;
592 if (strcmp(in_devices[i].name, name) == 0)
593 return i;
594 }
595
596 if (i >= IN_MAX_DEVS)
597 {
598 /* try to find unused device */
599 for (i = 0; i < IN_MAX_DEVS; i++)
600 if (in_devices[i].name == NULL) break;
601 if (i >= IN_MAX_DEVS) {
602 printf("input: too many devices, can't add %s\n", name);
603 return -1;
604 }
605 }
606
607 memset(&in_devices[i], 0, sizeof(in_devices[i]));
608
609 in_devices[i].name = strdup(name);
610 if (in_devices[i].name == NULL)
611 return -1;
612
613 if (i + 1 > in_dev_count)
614 in_dev_count = i + 1;
615 in_devices[i].drv_id = drv_id;
616
617 return i;
618}
619
299acadc 620/*
621 * To reduce size of game specific configs, default binds are not saved.
622 * So we mark default binds in in_config_start(), override them in in_config_bind_key(),
623 * and restore whatever default binds are left in in_config_end().
624 */
819ef025 625void in_config_start(void)
626{
627 int i;
628
629 /* mark all default binds, so they get overwritten by func below */
630 for (i = 0; i < IN_MAX_DEVS; i++) {
631 int n, count, *binds, *def_binds;
632
f484a9fe 633 binds = in_devices[i].binds;
634 if (binds == NULL)
819ef025 635 continue;
636
637 count = in_bind_count(in_devices[i].drv_id);
819ef025 638 def_binds = binds + count;
639
640 for (n = 0; n < count; n++)
641 if (binds[n] == def_binds[n])
642 binds[n] = -1;
643 }
644}
645
646int in_config_bind_key(int dev_id, const char *key, int binds)
647{
f484a9fe 648 int count, kc;
649 in_dev_t *dev;
819ef025 650
651 if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
652 return -1;
f484a9fe 653 dev = &in_devices[dev_id];
819ef025 654
f484a9fe 655 count = in_bind_count(dev->drv_id);
656
657 /* maybe a raw code? */
658 if (key[0] == '\\' && key[1] == 'x') {
659 char *p = NULL;
660 kc = (int)strtoul(key + 2, &p, 16);
661 if (p == NULL || *p != 0)
662 kc = -1;
663 }
664 else {
665 /* device specific key name */
666 if (dev->binds == NULL) {
667 dev->binds = in_alloc_binds(dev->drv_id);
668 if (dev->binds == NULL)
669 return -1;
670 in_config_start();
671 }
672
673 kc = DRV(dev->drv_id).get_key_code(key);
674 if (kc < 0 && strlen(key) == 1) {
675 /* assume scancode */
676 kc = key[0];
677 }
819ef025 678 }
679
f484a9fe 680 if (kc < 0 || kc >= count) {
819ef025 681 printf("input: bad key: %s\n", key);
682 return -1;
3427e573 683 }
684
f484a9fe 685 if (dev->binds[kc] == -1)
686 dev->binds[kc] = 0;
687 dev->binds[kc] |= binds;
819ef025 688
689 return 0;
690}
691
692void in_config_end(void)
693{
694 int i;
695
696 for (i = 0; i < IN_MAX_DEVS; i++) {
697 int n, ret, count, *binds, *def_binds;
f484a9fe 698 in_dev_t *dev = &in_devices[i];
819ef025 699
f484a9fe 700 if (dev->binds == NULL)
819ef025 701 continue;
702
f484a9fe 703 count = in_bind_count(dev->drv_id);
704 binds = dev->binds;
819ef025 705 def_binds = binds + count;
706
707 for (n = 0; n < count; n++)
708 if (binds[n] == -1)
709 binds[n] = def_binds[n];
710
f484a9fe 711 if (dev->drv_data == NULL)
819ef025 712 continue;
713
f484a9fe 714 ret = DRV(dev->drv_id).clean_binds(dev->drv_data, binds);
819ef025 715 if (ret == 0) {
716 /* no useable binds */
f484a9fe 717 free(dev->binds);
718 dev->binds = NULL;
819ef025 719 }
720 }
3427e573 721}
722
819ef025 723void in_debug_dump(void)
724{
725 int i;
726
727 printf("# drv probed binds name\n");
728 for (i = 0; i < IN_MAX_DEVS; i++) {
729 in_dev_t *d = &in_devices[i];
730 if (!d->probed && d->name == NULL && d->binds == NULL)
731 continue;
732 printf("%d %3d %6c %5c %s\n", i, d->drv_id, d->probed ? 'y' : 'n',
733 d->binds ? 'y' : 'n', d->name);
734 }
735}
736
737/* handlers for unknown/not_preset drivers */
738
739static void in_def_probe(void) {}
740static void in_def_free(void *drv_data) {}
741static int in_def_get_bind_count(void) { return 0; }
742static void in_def_get_def_binds(int *binds) {}
743static int in_def_clean_binds(void *drv_data, int *binds) { return 0; }
744static void in_def_set_blocking(void *data, int y) {}
7201dc73 745static int in_def_update_keycode(void *drv_data, int *is_down) { return 0; }
819ef025 746static int in_def_menu_translate(int keycode) { return keycode; }
747static int in_def_get_key_code(const char *key_name) { return 0; }
748static const char *in_def_get_key_name(int keycode) { return NULL; }
749
e1f99f2b 750void in_init(void)
751{
819ef025 752 int i;
753
754 memset(in_drivers, 0, sizeof(in_drivers));
e1f99f2b 755 memset(in_devices, 0, sizeof(in_devices));
756 in_dev_count = 0;
819ef025 757
758 for (i = 0; i < IN_DRVID_COUNT; i++) {
759 in_drivers[i].prefix = "none:";
760 in_drivers[i].probe = in_def_probe;
761 in_drivers[i].free = in_def_free;
762 in_drivers[i].get_bind_count = in_def_get_bind_count;
763 in_drivers[i].get_def_binds = in_def_get_def_binds;
764 in_drivers[i].clean_binds = in_def_clean_binds;
765 in_drivers[i].set_blocking = in_def_set_blocking;
7201dc73 766 in_drivers[i].update_keycode = in_def_update_keycode;
819ef025 767 in_drivers[i].menu_translate = in_def_menu_translate;
768 in_drivers[i].get_key_code = in_def_get_key_code;
769 in_drivers[i].get_key_name = in_def_get_key_name;
770 }
771
217d08bc 772#ifdef IN_GP2X
773 in_gp2x_init(&in_drivers[IN_DRVID_GP2X]);
774#endif
819ef025 775#ifdef IN_EVDEV
776 in_evdev_init(&in_drivers[IN_DRVID_EVDEV]);
777#endif
e1f99f2b 778}
779
819ef025 780#if 0
e1f99f2b 781int main(void)
782{
3b13ec65 783 int ret;
784
e1f99f2b 785 in_init();
786 in_probe();
787
3427e573 788 in_set_blocking(1);
789
790#if 1
791 while (1) {
792 int dev = 0, down;
793 ret = in_update_keycode(&dev, &down);
794 printf("#%i: %i %i (%s)\n", dev, down, ret, in_get_key_name(dev, ret));
795 }
796#else
e1f99f2b 797 while (1) {
b6820926 798 ret = in_menu_wait_any();
3b13ec65 799 printf("%08x\n", ret);
e1f99f2b 800 }
3427e573 801#endif
e1f99f2b 802
803 return 0;
804}
819ef025 805#endif