static void set_abs(struct libevdev *dev, unsigned int changes, unsigned int axis, struct input_absinfo *absinfo) { int rc; struct input_absinfo abs; const struct input_absinfo *a; if ((a = libevdev_get_abs_info(dev, axis)) == NULL) { fprintf(stderr, "Device '%s' doesn't have axis %s\n", libevdev_get_name(dev), libevdev_event_code_get_name(EV_ABS, axis)); return; } abs = *a; if (changes & OPT_MIN) abs.minimum = absinfo->minimum; if (changes & OPT_MAX) abs.maximum = absinfo->maximum; if (changes & OPT_FUZZ) abs.fuzz = absinfo->fuzz; if (changes & OPT_FLAT) abs.flat = absinfo->flat; if (changes & OPT_RES) abs.resolution = absinfo->resolution; rc = libevdev_kernel_set_abs_info(dev, axis, &abs); if (rc != 0) fprintf(stderr, "Failed to set absinfo %s: %s", libevdev_event_code_get_name(EV_ABS, axis), strerror(-rc)); }
uint32_t joystick_linux::process_joysticks(uint32_t p_event_id) { if (joy_mutex->try_lock() != OK) { return p_event_id; } for (int i=0; i<JOYSTICKS_MAX; i++) { if (joysticks[i].fd == -1) continue; input_event ev; Joystick* joy = &joysticks[i]; libevdev* dev = joy->dev; int rc = 1; rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); if (rc < 0 && rc != -EAGAIN) { continue; } while (rc == LIBEVDEV_READ_STATUS_SYNC || rc == LIBEVDEV_READ_STATUS_SUCCESS) { switch (ev.type) { case EV_KEY: p_event_id = input->joy_button(p_event_id, i, joy->key_map[ev.code], ev.value); break; case EV_ABS: switch (ev.code) { case ABS_HAT0X: if (ev.value != 0) { if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_LEFT; else joy->dpad |= InputDefault::HAT_MASK_RIGHT; } else joy->dpad &= ~(InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_RIGHT); p_event_id = input->joy_hat(p_event_id, i, joy->dpad); break; case ABS_HAT0Y: if (ev.value != 0) { if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_UP; else joy->dpad |= InputDefault::HAT_MASK_DOWN; } else joy->dpad &= ~(InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_DOWN); p_event_id = input->joy_hat(p_event_id, i, joy->dpad); break; default: if (joy->abs_map[ev.code] != -1) { InputDefault::JoyAxis value = axis_correct(libevdev_get_abs_info(dev, ev.code), ev.value); joy->curr_axis[joy->abs_map[ev.code]] = value; } break; } break; } rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev); } for (int j = 0; j < MAX_ABS; j++) { int index = joy->abs_map[j]; if (index != -1) { p_event_id = input->joy_axis(p_event_id, i, index, joy->curr_axis[index]); } } } joy_mutex->unlock(); return p_event_id; }