Record controller input

This commit is contained in:
Phireh 2024-12-13 02:44:08 +01:00
commit e84a413c9e
2 changed files with 87 additions and 2 deletions

View file

@ -747,6 +747,63 @@ int main()
// TODO: Debug printing
if (iev.type == EV_ABS || iev.type == EV_KEY)
console_debug_ss(MODULE_CONTROLLER, "Controller event\n\tTime: %ld.%06ld\n\tType: %s\n\tCode: %s\n\tValue: %d\n", iev.input_event_sec, iev.input_event_usec, libevdev_event_type_get_name(iev.type), libevdev_event_code_get_name(iev.type, iev.code), iev.value);
if (iev.type == EV_ABS)
{
int max_val = libevdev_event_type_get_max(EV_ABS);
float normalized_val = (2 * iev.value / (float)max_val) - 1.0f;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "ABS_X"))
user_input.lx_axis = normalized_val;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "ABS_Y"))
user_input.ly_axis = normalized_val;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "ABS_Z"))
user_input.lz_axis = normalized_val;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "ABS_RX"))
user_input.rx_axis = normalized_val;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "ABS_RY"))
user_input.ry_axis = normalized_val;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "ABS_RZ"))
user_input.rz_axis = normalized_val;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "ABS_HAT0X"))
{
user_input.controller_buttons[CONT_LEFT] = iev.value == -1 ? 1 : 0;
user_input.controller_buttons[CONT_RIGHT] = iev.value == 1 ? 1 : 0;
}
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "ABS_HAT0Y"))
{
user_input.controller_buttons[CONT_UP] = iev.value == -1 ? 1 : 0;
user_input.controller_buttons[CONT_DOWN] = iev.value == 1 ? 1 : 0;
}
}
if (iev.type == EV_KEY)
{
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_TL"))
user_input.controller_buttons[CONT_L] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_TR"))
user_input.controller_buttons[CONT_R] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_SELECT"))
user_input.controller_buttons[CONT_SELECT] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_START"))
user_input.controller_buttons[CONT_START] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_MODE"))
user_input.controller_buttons[CONT_MODE] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_THUMBR"))
user_input.controller_buttons[CONT_RTHUMB] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_THUMBL"))
user_input.controller_buttons[CONT_RTHUMB] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_NORTH"))
user_input.controller_buttons[CONT_NORTH] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_EAST"))
user_input.controller_buttons[CONT_EAST] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_SOUTH"))
user_input.controller_buttons[CONT_SOUTH] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_WEST"))
user_input.controller_buttons[CONT_WEST] = iev.value;
if (!strcmp(libevdev_event_code_get_name(iev.type, iev.code), "BTN_MODE"))
user_input.controller_buttons[CONT_MODE] = iev.value;
}
}
} while (errcode != LIBEVDEV_READ_STATUS_SYNC && errcode != LIBEVDEV_READ_STATUS_SUCCESS && errcode != -EAGAIN);