linux/joy.c: add fallback to /dev/input/js0

some devices seem to map the joystick to /dev/input/js0 rather than
/dev/js0.
This commit is contained in:
rofl0r 2017-11-22 23:55:57 +00:00
parent 2479cf7000
commit 4ec645a60e
1 changed files with 38 additions and 1 deletions

View File

@ -35,9 +35,19 @@ rcvar_t joy_exports[] =
void joy_init() void joy_init()
{ {
int set;
if (!usejoy) return; if (!usejoy) return;
if (!joydev) joydev = strdup("/dev/js0"); set = 0;
if (!joydev) {
joydev = strdup("/dev/js0");
set = 1;
}
joyfd = open(joydev, O_RDONLY|O_NONBLOCK); joyfd = open(joydev, O_RDONLY|O_NONBLOCK);
if(joyfd == -1 && set) {
free(joydev);
joydev = strdup("/dev/input/js0");
joyfd = open(joydev, O_RDONLY|O_NONBLOCK);
}
} }
void joy_close() void joy_close()
@ -92,3 +102,30 @@ void joy_poll()
} }
} }
} }
#ifdef JOY_TEST
#include "../../events.c"
#include "../../keytable.c"
int main() {
joy_init();
event_t e;
while(1) {
joy_poll();
if(ev_getevent(&e)) {
static const char* evt_str[] = {
[EV_NONE] = "none",
[EV_PRESS] = "press",
[EV_RELEASE] = "release",
[EV_REPEAT] = "repeat",
[EV_MOUSE] = "mouse",
};
printf("%s: %s\n", evt_str[e.type], k_keyname(e.code));
} else {
usleep(300);
}
}
}
#endif