Initial legion go hidraw read

This commit is contained in:
Denis 2023-12-10 03:24:43 +01:00
parent b25031bb20
commit 5976d13599
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
4 changed files with 123 additions and 31 deletions

View file

@ -394,15 +394,18 @@ void* dev_in_thread_func(void *ptr) {
fprintf(stderr, "Unable to fill input_event(s) for device %zd: %d -- Will reconnect the device\n", i, fill_res);
evdev_close_device(&devices[i].dev.evdev);
devices[i].type = DEV_IN_TYPE_NONE;
continue;
} else {
dev_in_data->input_dev_decl->dev[i]->ev_input_map_fn(&coll, dev_in_data->in_message_pipe_fd, dev_in_data->input_dev_decl->dev[i]->user_data);
dev_in_data->input_dev_decl->dev[i]->map.ev_input_map_fn(&coll, dev_in_data->in_message_pipe_fd, dev_in_data->input_dev_decl->dev[i]->user_data);
}
} else if (devices[i].type == DEV_IN_TYPE_IIO) {
// TODO: implement IIO
//fill_message_from_iio(&devices[i].dev.iio, out_msg);
} else if (devices[i].type == DEV_IN_TYPE_HIDRAW) {
dev_in_data->input_dev_decl->dev[i]->hidraw_input_map_fn(dev_hidraw_get_fd(devices[i].dev.hidraw.hidrawdev), dev_in_data->in_message_pipe_fd, dev_in_data->input_dev_decl->dev[i]->user_data);
const int hidraw_op_res = dev_in_data->input_dev_decl->dev[i]->map.hidraw_input_map_fn(dev_hidraw_get_fd(devices[i].dev.hidraw.hidrawdev), dev_in_data->in_message_pipe_fd, dev_in_data->input_dev_decl->dev[i]->user_data);
if (hidraw_op_res != 0) {
fprintf(stderr, "Error in performing operations for device %zd: %d -- Will reconnect to the device\n", i, hidraw_op_res);
devices[i].type = DEV_IN_TYPE_NONE;
}
}
}
}

View file

@ -18,7 +18,7 @@ typedef struct evdev_collected {
* constructed from that data.
*/
typedef void (*ev_map)(const evdev_collected_t *const e, int in_messages_pipe_fd, void* user_data);
typedef void (*hidraw_map)(int hidraw_fd, int in_messages_pipe_fd, void* user_data);
typedef int (*hidraw_map)(int hidraw_fd, int in_messages_pipe_fd, void* user_data);
typedef enum input_dev_type {
input_dev_type_uinput,
@ -60,10 +60,10 @@ typedef struct input_dev {
void* user_data;
union {
union input_dev_map {
ev_map ev_input_map_fn;
hidraw_map hidraw_input_map_fn;
};
} map;
} input_dev_t;

View file

@ -10,7 +10,9 @@ static input_dev_t in_xbox_dev = {
.name = "Generic X-Box pad"
}
},
.ev_input_map_fn = xbox360_ev_map,
.map = {
.ev_input_map_fn = xbox360_ev_map,
}
};
static xbox360_settings_t x360_cfg;
@ -24,28 +26,107 @@ static input_dev_t in_iio_dev = {
},
};
static int legion_platform_init(void** platform_data) {
int res = -EINVAL;
static struct llg_hidraw_data {
uint8_t last_packet[64];
} llg_hidraw_user_data;
static int llg_hidraw_map(int hidraw_fd, int in_messages_pipe_fd, void* user_data) {
struct llg_hidraw_data *const llg_data = (struct llg_hidraw_data*)user_data;
int read_res = read(hidraw_fd, llg_data->last_packet, sizeof(llg_data->last_packet));
if (read_res != 64) {
fprintf(stderr, "Error reading from hidraw device\n");
return -EINVAL;
}
// here we have llg_data->last_packet filled with 64 bytes from the input device
const in_message_t current_message = {
.type = GAMEPAD_SET_ELEMENT,
.data = {
.gamepad_set = {
.element = GAMEPAD_BTN_L5,
.status = {
.btn = 1,
}
}
}
};
/*
// this does send messages to the output device
const ssize_t in_message_pipe_write_res = write(in_messages_pipe_fd, (void*)&current_message, sizeof(in_message_t));
if (in_message_pipe_write_res != sizeof(in_message_t)) {
fprintf(stderr, "Unable to write data for L4 to the in_message pipe: %zu\n", in_message_pipe_write_res);
return -EINVAL;
}
*/
// successful return
return 0;
}
static void legion_platform_deinit(void** platform_data) {
// free(platform);
static input_dev_t in_hidraw_dev = {
.dev_type = input_dev_type_hidraw,
.filters = {
.hidraw = {
.pid = 0x6182,
.vid = 0x17ef,
.rdesc_size = 44,
}
},
.user_data = (void*)&llg_hidraw_user_data,
.map = {
.hidraw_input_map_fn = llg_hidraw_map,
},
};
typedef struct legion_go_platform {
int _pad;
} legion_go_platform_t;
static int legion_platform_init(void** platform_data) {
int res = -EINVAL;
legion_go_platform_t *const llg_platform = malloc(sizeof(legion_go_platform_t));
if (llg_platform == NULL) {
fprintf(stderr, "Unable to allocate memory for the platform data\n");
res = -ENOMEM;
goto legion_platform_init_err;
}
*platform_data = (void*)llg_platform;
res = 0;
legion_platform_init_err:
return res;
}
static void legion_platform_deinit(void** platform_data) {
free(*platform_data);
*platform_data = NULL;
}
int legion_platform_leds(uint8_t r, uint8_t g, uint8_t b, void* platform_data) {
return 0;
}
input_dev_composite_t legion_composite = {
.dev = {
&in_hidraw_dev,
&in_xbox_dev,
// &in_iio_dev,
},
.dev_count = 1,
.init_fn = legion_platform_init,
.leds_fn = legion_platform_leds,
.deinit_fn = legion_platform_deinit,
};
input_dev_composite_t* legion_go_device_def(const controller_settings_t *const settings) {
// x360_cfg.nintendo_layout = settings->nintendo_layout;
x360_cfg.nintendo_layout = settings->nintendo_layout;
in_xbox_dev.user_data = (void*)&x360_cfg;
return &legion_composite;

View file

@ -495,7 +495,7 @@ void asus_kbd_ev_map(const evdev_collected_t *const e, int in_messages_pipe_fd,
const ssize_t in_message_pipe_write_res = write(in_messages_pipe_fd, (void*)&current_message, sizeof(in_message_t));
if (in_message_pipe_write_res != sizeof(in_message_t)) {
fprintf(stderr, "Unable to write data for L4 to the in_message pipe: %zu\n", in_message_pipe_write_res);
fprintf(stderr, "Unable to write data for L5 to the in_message pipe: %zu\n", in_message_pipe_write_res);
}
} else if (
(e->ev_count == 2) &&
@ -506,21 +506,21 @@ void asus_kbd_ev_map(const evdev_collected_t *const e, int in_messages_pipe_fd,
(e->ev[1].code == KEY_F18)
) {
const in_message_t current_message = {
.type = GAMEPAD_SET_ELEMENT,
.data = {
.gamepad_set = {
.element = GAMEPAD_BTN_R5,
.status = {
.btn = e->ev[1].value,
}
}
}
};
.type = GAMEPAD_SET_ELEMENT,
.data = {
.gamepad_set = {
.element = GAMEPAD_BTN_R5,
.status = {
.btn = e->ev[1].value,
}
}
}
};
const ssize_t in_message_pipe_write_res = write(in_messages_pipe_fd, (void*)&current_message, sizeof(in_message_t));
if (in_message_pipe_write_res != sizeof(in_message_t)) {
fprintf(stderr, "Unable to write data for R4 to the in_message pipe: %zu\n", in_message_pipe_write_res);
}
const ssize_t in_message_pipe_write_res = write(in_messages_pipe_fd, (void*)&current_message, sizeof(in_message_t));
if (in_message_pipe_write_res != sizeof(in_message_t)) {
fprintf(stderr, "Unable to write data for R5 to the in_message pipe: %zu\n", in_message_pipe_write_res);
}
}
}
@ -548,7 +548,9 @@ static input_dev_t in_asus_kb_1_dev = {
.name = "Asus Keyboard"
}
},
.ev_input_map_fn = asus_kbd_ev_map,
.map = {
.ev_input_map_fn = asus_kbd_ev_map,
}
};
static input_dev_t in_asus_kb_2_dev = {
@ -558,7 +560,9 @@ static input_dev_t in_asus_kb_2_dev = {
.name = "Asus Keyboard"
}
},
.ev_input_map_fn = asus_kbd_ev_map,
.map = {
.ev_input_map_fn = asus_kbd_ev_map,
}
};
static input_dev_t in_asus_kb_3_dev = {
@ -568,7 +572,9 @@ static input_dev_t in_asus_kb_3_dev = {
.name = "Asus Keyboard"
}
},
.ev_input_map_fn = asus_kbd_ev_map,
.map = {
.ev_input_map_fn = asus_kbd_ev_map,
}
};
static input_dev_t in_xbox_dev = {
@ -578,7 +584,9 @@ static input_dev_t in_xbox_dev = {
.name = "Microsoft X-Box 360 pad"
}
},
.ev_input_map_fn = xbox360_ev_map,
.map = {
.ev_input_map_fn = xbox360_ev_map,
}
};
static xbox360_settings_t x360_cfg;