+/*
+ * (C) GraÅžvydas "notaz" Ignotas, 2008-2010
+ *
+ * This work is licensed under the terms of any of these licenses
+ * (at your option):
+ * - GNU GPL, version 2 or later.
+ * - GNU LGPL, version 2.1 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define KEYBITS_BIT_CLEAR(x) (keybits[(x)/sizeof(keybits[0])/8] &= \
~(1 << ((x) & (sizeof(keybits[0])*8-1))))
+int in_evdev_allow_abs_only;
+
static const char * const in_evdev_prefix = "evdev:";
static const char * const in_evdev_keys[KEY_CNT] = {
[0 ... KEY_MAX] = NULL,
for (i = 0;; i++)
{
int support = 0, count = 0;
- int u, ret, fd, kc_first, kc_last;
+ int u, ret, fd, kc_first = KEY_MAX, kc_last = 0;
in_evdev_t *dev;
char name[64];
goto skip;
}
- if (!(support & (1 << EV_KEY)))
- goto skip;
-
- ret = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits);
- if (ret == -1) {
- printf("in_evdev: ioctl failed on %s\n", name);
- goto skip;
- }
+ if (support & (1 << EV_KEY)) {
+ ret = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits);
+ if (ret == -1) {
+ printf("in_evdev: ioctl failed on %s\n", name);
+ goto skip;
+ }
- /* check for interesting keys */
- kc_first = KEY_MAX;
- kc_last = 0;
- for (u = 0; u < KEY_CNT; u++) {
- if (KEYBITS_BIT(u)) {
- if (u < kc_first)
- kc_first = u;
- if (u > kc_last)
- kc_last = u;
- if (u != KEY_POWER && u != KEY_SLEEP && u != BTN_TOUCH)
- count++;
+ /* check for interesting keys */
+ for (u = 0; u < KEY_CNT; u++) {
+ if (KEYBITS_BIT(u)) {
+ if (u < kc_first)
+ kc_first = u;
+ if (u > kc_last)
+ kc_last = u;
+ if (u != KEY_POWER && u != KEY_SLEEP && u != BTN_TOUCH)
+ count++;
+ if (u == BTN_TOUCH) /* we can't deal with ts currently */
+ goto skip;
+ }
}
}
- if (count == 0)
+ if (count == 0 && !in_evdev_allow_abs_only)
goto skip;
dev = calloc(1, sizeof(*dev));
}
no_abs:
+ if (count == 0 && dev->abs_lzone == 0) {
+ free(dev);
+ goto skip;
+ }
+
dev->fd = fd;
dev->kc_first = kc_first;
dev->kc_last = kc_last;
free(dev);
}
-static int in_evdev_get_bind_count(void)
+static const char * const *
+in_evdev_get_key_names(int *count)
{
- return KEY_CNT;
+ *count = KEY_CNT;
+ return in_evdev_keys;
}
static void or_binds(const int *binds, int key, int *result)
struct input_event ev;
int rd;
+ /* do single event, the caller sometimes wants
+ * to do select() in blocking mode */
rd = read(dev->fd, &ev, sizeof(ev));
if (rd < (int) sizeof(ev)) {
if (errno != EAGAIN) {
perror("in_evdev: error reading");
- sleep(1);
+ //sleep(1);
+ ret_kc = -2;
}
goto out;
}
return 0;
}
+/* FIXME: move to plat */
+#if 0
static const struct {
short code;
char btype;
{ BTN_PINKIE, IN_BINDTYPE_EMU, PEVB_STATE_LOAD },
{ BTN_BASE, IN_BINDTYPE_EMU, PEVB_MENU },
};
-
-#define DEF_BIND_COUNT (sizeof(in_evdev_def_binds) / sizeof(in_evdev_def_binds[0]))
+#endif
static void in_evdev_get_def_binds(int *binds)
{
int i;
- for (i = 0; i < DEF_BIND_COUNT; i++)
- binds[IN_BIND_OFFS(in_evdev_def_binds[i].code, in_evdev_def_binds[i].btype)] =
- 1 << in_evdev_def_binds[i].bit;
+ for (i = 0; ; i++) {
+ if (in_evdev_defbinds[i].bit == 0 && in_evdev_defbinds[i].code == 0)
+ break;
+ binds[IN_BIND_OFFS(in_evdev_defbinds[i].code, in_evdev_defbinds[i].btype)] =
+ 1 << in_evdev_defbinds[i].bit;
+ }
}
/* remove binds of missing keys, count remaining ones */
in_evdev_t *dev = drv_data;
int i, t, ret, offs, count = 0;
+ memset(keybits, 0, sizeof(keybits));
ret = ioctl(dev->fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits);
if (ret == -1) {
perror("in_evdev: ioctl failed");
- memset(keybits, 0xff, sizeof(keybits)); /* mark all as good */
+ // memset(keybits, 0xff, sizeof(keybits)); /* mark all as good */
}
if (dev->abs_lzone != 0) {
drv->prefix = in_evdev_prefix;
drv->probe = in_evdev_probe;
drv->free = in_evdev_free;
- drv->get_bind_count = in_evdev_get_bind_count;
+ drv->get_key_names = in_evdev_get_key_names;
drv->get_def_binds = in_evdev_get_def_binds;
drv->clean_binds = in_evdev_clean_binds;
drv->set_config = in_evdev_set_config;