X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fin_evdev.c;h=c2589a9bc2941f837a983881923e18fa563c18ff;hb=fa5e045bdc817112c1abf19e65e2d3481d51c48a;hp=984333c8e2ce4ef84b99107af5aa6e03e3c20931;hpb=7f022a8d573295d721fd6a517c8f1fe04480a8f0;p=libpicofe.git diff --git a/linux/in_evdev.c b/linux/in_evdev.c index 984333c..c2589a9 100644 --- a/linux/in_evdev.c +++ b/linux/in_evdev.c @@ -9,7 +9,6 @@ #include #include -#include "../common/common.h" #include "../common/input.h" #include "in_evdev.h" @@ -195,7 +194,7 @@ no_abs: ioctl(fd, EVIOCGNAME(sizeof(name)-6), name+6); printf("in_evdev: found \"%s\" with %d events (type %08x)\n", name+6, count, support); - in_register(name, IN_DRVID_EVDEV, fd, dev); + in_register(name, IN_DRVID_EVDEV, fd, dev, 0); continue; skip: @@ -306,14 +305,16 @@ static int in_evdev_update_keycode(void *data, int *is_down) rd = read(dev->fd, &ev, sizeof(ev)); if (rd < (int) sizeof(ev)) { - perror("in_evdev: error reading"); - sleep(1); - return 0; + if (errno != EAGAIN) { + perror("in_evdev: error reading"); + sleep(1); + } + return -1; } if (ev.type == EV_KEY) { if (ev.value < 0 || ev.value > 1) - return 0; + return -1; if (is_down != NULL) *is_down = ev.value; return ev.code; @@ -349,25 +350,53 @@ static int in_evdev_update_keycode(void *data, int *is_down) } } - return 0; + return -1; } +static const struct { + short key; + short pbtn; +} key_pbtn_map[] = +{ + { KEY_UP, PBTN_UP }, + { KEY_DOWN, PBTN_DOWN }, + { KEY_LEFT, PBTN_LEFT }, + { KEY_RIGHT, PBTN_RIGHT }, + { KEY_ENTER, PBTN_MOK }, + { BTN_A, PBTN_MOK }, + { BTN_TRIGGER, PBTN_MOK }, + { KEY_ESC, PBTN_MBACK }, + { BTN_B, PBTN_MBACK }, + { BTN_THUMB, PBTN_MBACK }, + { KEY_A, PBTN_MA2 }, + { KEY_S, PBTN_MA3 }, + { KEY_BACKSLASH, PBTN_MENU }, + { KEY_MENU, PBTN_MENU }, + { KEY_LEFTBRACE, PBTN_L }, + { KEY_RIGHTBRACE, PBTN_R }, +}; + +#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0])) + static int in_evdev_menu_translate(int keycode) { - switch (keycode) { - case KEY_UP: return PBTN_UP; - case KEY_DOWN: return PBTN_DOWN; - case KEY_LEFT: return PBTN_LEFT; - case KEY_RIGHT: return PBTN_RIGHT; - case KEY_ENTER: - case BTN_A: - case BTN_TRIGGER: return PBTN_MOK; - case KEY_ESC: - case BTN_B: - case BTN_THUMB: return PBTN_MBACK; - case KEY_MENU: return PBTN_MENU; - default: return 0; + int i; + if (keycode < 0) + { + /* menu -> kc */ + keycode = -keycode; + for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) + if (key_pbtn_map[i].pbtn == keycode) + return key_pbtn_map[i].key; + } + else + { + for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) + if (key_pbtn_map[i].key == keycode) + return key_pbtn_map[i].pbtn; } + + return 0; } static int in_evdev_get_key_code(const char *key_name) @@ -376,8 +405,7 @@ static int in_evdev_get_key_code(const char *key_name) for (i = 0; i < KEY_MAX + 1; i++) { const char *k = in_evdev_keys[i]; - if (k != NULL && k[0] == key_name[0] && - strcasecmp(k, key_name) == 0) + if (k != NULL && strcasecmp(k, key_name) == 0) return i; } @@ -413,6 +441,8 @@ static const struct { { BTN_Y, 6 }, { KEY_ENTER, 7 }, { BTN_START, 7 }, + { BTN_TL, 27 }, /* save state */ + { BTN_TR, 28 }, /* load state */ }; #define DEF_BIND_COUNT (sizeof(in_evdev_def_binds) / sizeof(in_evdev_def_binds[0]))