| 53 | } |
| 54 | |
| 55 | int open_evdev(const char* source, int flags) |
| 56 | { |
| 57 | /* Extract the ev number from the dev filename */ |
| 58 | int evnum; |
| 59 | int ret = sscanf(source, "/dev/input/event%d", &evnum); |
| 60 | if (ret != 1) { |
| 61 | errno = ENOENT; |
| 62 | return -1; |
| 63 | } |
| 64 | |
| 65 | /* Return -1 and set errno if we don't support this ev number */ |
| 66 | if (evnum < 0 || evnum >= Global::shared_config.nb_controllers || evnum >= AllInputsFlat::MAXJOYS) { |
| 67 | errno = ENOENT; |
| 68 | return -1; |
| 69 | } |
| 70 | |
| 71 | LOG(LL_DEBUG, LCF_JOYSTICK, " evdev device %d detected", evnum); |
| 72 | |
| 73 | if (evdevfds[evnum].second++ == 0) { |
| 74 | /* Register that we use EVDEV for joystick inputs */ |
| 75 | Global::game_info.joystick |= GameInfo::EVDEV; |
| 76 | Global::game_info.tosend = true; |
| 77 | |
| 78 | if (flags == O_RDWR) { |
| 79 | LOG(LL_DEBUG, LCF_JOYSTICK, " evdev device was opened with read/write, but we only support read. Enforcing this may be an issue later"); |
| 80 | flags = O_RDONLY; |
| 81 | } |
| 82 | |
| 83 | /* Create an unnamed pipe. */ |
| 84 | evdevfds[evnum].first = FileHandleList::createPipe(flags); |
| 85 | |
| 86 | /* If pipe creation failed (e.g. when opening the dev file in write mode), |
| 87 | * invalidate the pipe and return -1. */ |
| 88 | if (evdevfds[evnum].first.first == -1) { |
| 89 | LOG(LL_DEBUG, LCF_JOYSTICK, " could not create evdev pipe with flags %d", flags); |
| 90 | evdevfds[evnum].second = 0; |
| 91 | return -1; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return evdevfds[evnum].first.first; |
| 96 | } |
| 97 | |
| 98 | void write_evdev(struct input_event ev, int evnum) |
| 99 | { |
no test coverage detected