mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-05 14:57:46 -04:00
support kernels without EVIOCGKEY
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@730 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
22b2271a09
commit
0d6fbb2c33
1 changed files with 41 additions and 13 deletions
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int fd;
|
int fd;
|
||||||
|
int *kbits;
|
||||||
int abs_lzone;
|
int abs_lzone;
|
||||||
int abs_rzone;
|
int abs_rzone;
|
||||||
int abs_tzone;
|
int abs_tzone;
|
||||||
|
@ -32,6 +33,9 @@ typedef struct {
|
||||||
#define KEYBITS_BIT_SET(x) (keybits[(x)/sizeof(keybits[0])/8] |= \
|
#define KEYBITS_BIT_SET(x) (keybits[(x)/sizeof(keybits[0])/8] |= \
|
||||||
(1 << ((x) & (sizeof(keybits[0])*8-1))))
|
(1 << ((x) & (sizeof(keybits[0])*8-1))))
|
||||||
|
|
||||||
|
#define KEYBITS_BIT_CLEAR(x) (keybits[(x)/sizeof(keybits[0])/8] &= \
|
||||||
|
~(1 << ((x) & (sizeof(keybits[0])*8-1))))
|
||||||
|
|
||||||
static const char * const in_evdev_prefix = "evdev:";
|
static const char * const in_evdev_prefix = "evdev:";
|
||||||
static const char * const in_evdev_keys[KEY_CNT] = {
|
static const char * const in_evdev_keys[KEY_CNT] = {
|
||||||
[0 ... KEY_MAX] = NULL,
|
[0 ... KEY_MAX] = NULL,
|
||||||
|
@ -158,7 +162,8 @@ static void in_evdev_probe(void)
|
||||||
|
|
||||||
/* check for interesting keys */
|
/* check for interesting keys */
|
||||||
for (u = 0; u < KEY_CNT; u++) {
|
for (u = 0; u < KEY_CNT; u++) {
|
||||||
if (KEYBITS_BIT(u) && u != KEY_POWER && u != KEY_SLEEP && u != BTN_TOUCH)
|
if (KEYBITS_BIT(u) && u != KEY_POWER &&
|
||||||
|
u != KEY_SLEEP && u != BTN_TOUCH)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +174,16 @@ static void in_evdev_probe(void)
|
||||||
if (dev == NULL)
|
if (dev == NULL)
|
||||||
goto skip;
|
goto skip;
|
||||||
|
|
||||||
|
ret = ioctl(fd, EVIOCGKEY(sizeof(keybits)), keybits);
|
||||||
|
if (ret == -1) {
|
||||||
|
printf("Warning: EVIOCGKEY not supported, will have to track state\n");
|
||||||
|
dev->kbits = calloc(KEY_CNT, sizeof(int));
|
||||||
|
if (dev->kbits == NULL) {
|
||||||
|
free(dev);
|
||||||
|
goto skip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* check for abs too */
|
/* check for abs too */
|
||||||
if (support & (1 << EV_ABS)) {
|
if (support & (1 << EV_ABS)) {
|
||||||
struct input_absinfo ainfo;
|
struct input_absinfo ainfo;
|
||||||
|
@ -235,10 +250,20 @@ int in_evdev_update(void *drv_data, const int *binds, int *result)
|
||||||
{
|
{
|
||||||
struct input_event ev[16];
|
struct input_event ev[16];
|
||||||
struct input_absinfo ainfo;
|
struct input_absinfo ainfo;
|
||||||
int keybits[KEY_CNT / sizeof(int)];
|
int keybits_[KEY_CNT / sizeof(int)];
|
||||||
|
int *keybits = keybits_;
|
||||||
in_evdev_t *dev = drv_data;
|
in_evdev_t *dev = drv_data;
|
||||||
int rd, ret, u;
|
int rd, ret, u;
|
||||||
|
|
||||||
|
if (dev->kbits == NULL) {
|
||||||
|
ret = ioctl(dev->fd, EVIOCGKEY(sizeof(keybits)), keybits);
|
||||||
|
if (ret == -1) {
|
||||||
|
perror("in_evdev: ioctl failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
keybits = dev->kbits;
|
||||||
while (1) {
|
while (1) {
|
||||||
rd = read(dev->fd, ev, sizeof(ev));
|
rd = read(dev->fd, ev, sizeof(ev));
|
||||||
if (rd < (int)sizeof(ev[0])) {
|
if (rd < (int)sizeof(ev[0])) {
|
||||||
|
@ -246,12 +271,15 @@ int in_evdev_update(void *drv_data, const int *binds, int *result)
|
||||||
perror("in_evdev: read failed");
|
perror("in_evdev: read failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
for (u = 0; u < rd / sizeof(ev[0]); u++) {
|
||||||
|
if (ev[u].type != EV_KEY)
|
||||||
|
continue;
|
||||||
|
else if (ev[u].value == 1)
|
||||||
|
KEYBITS_BIT_SET(ev[u].code);
|
||||||
|
else if (ev[u].value == 0)
|
||||||
|
KEYBITS_BIT_CLEAR(ev[u].code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ioctl(dev->fd, EVIOCGKEY(sizeof(keybits)), keybits);
|
|
||||||
if (ret == -1) {
|
|
||||||
perror("in_evdev: ioctl failed");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u = 0; u < KEY_CNT; u++) {
|
for (u = 0; u < KEY_CNT; u++) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue