Hidraw should work

This commit is contained in:
Denis 2023-12-08 23:45:31 +01:00
parent 197947e214
commit 348b0906b5
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
4 changed files with 40 additions and 7 deletions

View file

@ -116,3 +116,11 @@ int dev_hidraw_get_fd(const dev_hidraw_t* in_dev) {
return in_dev->fd; return in_dev->fd;
} }
int16_t dev_hidraw_get_pid(const dev_hidraw_t* in_dev) {
return in_dev->info.product;
}
int16_t dev_hidraw_get_vid(const dev_hidraw_t* in_dev) {
return in_dev->info.vendor;
}

View file

@ -17,4 +17,8 @@ int dev_hidraw_open(
void dev_hidraw_close(dev_hidraw_t *const inout_dev); void dev_hidraw_close(dev_hidraw_t *const inout_dev);
int dev_hidraw_get_fd(const dev_hidraw_t* in_dev); int dev_hidraw_get_fd(const dev_hidraw_t* in_dev);
int16_t dev_hidraw_get_pid(const dev_hidraw_t* in_dev);
int16_t dev_hidraw_get_vid(const dev_hidraw_t* in_dev);

View file

@ -104,6 +104,26 @@ fill_message_from_evdev_err_completed:
return res; return res;
} }
int hidraw_open_device(
const hidraw_filters_t *const in_filters,
dev_in_hidraw_t *const out_dev
) {
int res = dev_hidraw_open(in_filters, &out_dev->hidrawdev);
if (res != 0) {
fprintf(stderr, "Unable to open the specified iio device: %d\n", res);
goto iio_open_device_err;
}
printf(
"Opened hidraw device: %x:%x\n",
dev_hidraw_get_vid(out_dev->hidrawdev),
dev_hidraw_get_pid(out_dev->hidrawdev)
);
iio_open_device_err:
return res;
}
int iio_open_device( int iio_open_device(
const iio_filters_t *const in_filters, const iio_filters_t *const in_filters,
dev_in_iio_t *const out_dev dev_in_iio_t *const out_dev
@ -300,13 +320,10 @@ void* dev_in_thread_func(void *ptr) {
} else if (d_type == input_dev_type_hidraw) { } else if (d_type == input_dev_type_hidraw) {
fprintf(stderr, "Device (hidraw) %zu not found -- Attempt reconnection for device %x:%x\n", i, dev_in_data->input_dev_decl->dev[i]->filters.hidraw.pid, dev_in_data->input_dev_decl->dev[i]->filters.hidraw.vid); fprintf(stderr, "Device (hidraw) %zu not found -- Attempt reconnection for device %x:%x\n", i, dev_in_data->input_dev_decl->dev[i]->filters.hidraw.pid, dev_in_data->input_dev_decl->dev[i]->filters.hidraw.vid);
// TODO: do the same with hidraw: const int open_res = hidraw_open_device(&dev_in_data->input_dev_decl->dev[i]->filters.hidraw, &devices[i].dev.hidraw);
/*
const int open_res = iio_open_device(&dev_in_data->input_dev_decl->dev[i]->filters.iio, &devices[i].dev.iio);
if (open_res == 0) { if (open_res == 0) {
devices[i].type = DEV_IN_TYPE_HIDRAW; devices[i].type = DEV_IN_TYPE_HIDRAW;
} }
*/
} }
} }
} }
@ -375,7 +392,7 @@ void* dev_in_thread_func(void *ptr) {
// TODO: implement IIO // TODO: implement IIO
//fill_message_from_iio(&devices[i].dev.iio, out_msg); //fill_message_from_iio(&devices[i].dev.iio, out_msg);
} else if (devices[i].type == DEV_IN_TYPE_HIDRAW) { } else if (devices[i].type == DEV_IN_TYPE_HIDRAW) {
// TODO: do here your hidraw things 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);
} }
} }
} }

View file

@ -18,6 +18,7 @@ typedef struct evdev_collected {
* constructed from that data. * constructed from that data.
*/ */
typedef void (*ev_map)(const evdev_collected_t *const e, int in_messages_pipe_fd, void* user_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 enum input_dev_type { typedef enum input_dev_type {
input_dev_type_uinput, input_dev_type_uinput,
@ -59,7 +60,10 @@ typedef struct input_dev {
void* user_data; void* user_data;
ev_map ev_input_map_fn; union {
ev_map ev_input_map_fn;
hidraw_map hidraw_input_map_fn;
};
} input_dev_t; } input_dev_t;