#include <linux/input.h>
#include <errno.h>
-#include "../common/common.h"
#include "../common/input.h"
#include "in_evdev.h"
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:
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;
}
}
- 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)
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;
}
{ 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]))