1 // vim:shiftwidth=2:expandtab
11 #include <linux/input.h>
14 #include "realfuncs.h"
16 static int ifds[2] = { -1, -1 };
24 for (ifd = -1, i = 0; ifds[0] == -1 || ifds[1] == -1; i++) {
25 snprintf(buff, sizeof(buff), "/dev/input/event%i", i);
26 ifd = open(buff, O_RDONLY | O_NONBLOCK);
30 ret = ioctl(ifd, EVIOCGNAME(sizeof(buff)), buff);
34 if (strcasestr(buff, "gpio") != NULL) {
38 if (strcasestr(buff, "keypad") != NULL) {
46 fprintf(stderr, PFX "missing buttons\n");
48 fprintf(stderr, PFX "missing keypad\n");
57 { KEY_LEFT, GP2X_LEFT },
58 { KEY_RIGHT, GP2X_RIGHT },
60 { KEY_DOWN, GP2X_DOWN },
61 { KEY_PAGEUP, GP2X_Y },
64 { BTN_BASE2, GP2X_B },
65 { KEY_PAGEDOWN, GP2X_X },
66 { BTN_BASE3, GP2X_X },
68 { BTN_BASE4, GP2X_A },
69 { KEY_RIGHTSHIFT, GP2X_L },
71 { KEY_RIGHTCTRL, GP2X_R },
73 { KEY_LEFTALT, GP2X_START },
74 { BTN_START, GP2X_START },
75 { KEY_LEFTCTRL, GP2X_SELECT },
76 { BTN_SELECT, GP2X_SELECT },
77 { KEY_COMMA, GP2X_VOL_DOWN },
78 { KEY_DOT, GP2X_VOL_UP },
82 int host_read_btns(void)
84 struct input_event ev;
89 ret = read(ifds[0], &ev, sizeof(ev));
90 if (ret < (int) sizeof(ev)) {
91 if (errno != EAGAIN && errno != EWOULDBLOCK)
92 perror(PFX "read error");
94 ret = read(ifds[1], &ev, sizeof(ev));
95 if (ret < (int) sizeof(ev))
96 if (errno != EAGAIN && errno != EWOULDBLOCK)
97 perror(PFX "read error");
100 if (ret < (int) sizeof(ev))
103 if (ev.type != EV_KEY)
106 if (ev.code == KEY_Q && ev.value) {
107 // exit() might not be enough because loader and app data is out of sync,
108 // and other threads (which are really processes) might not exit properly.
109 system("killall ginge_sloader");
111 system("killall -9 ginge_sloader");
115 for (i = 0; i < sizeof(key_map) / sizeof(key_map[0]); i++) {
116 if (key_map[i].key != ev.code)
119 keystate |= (1 << key_map[i].btn);
121 keystate &= ~(1 << key_map[i].btn);