From 348b0906b597f1aae5bb9c30e9696fdc7bea765a Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 8 Dec 2023 23:45:31 +0100 Subject: [PATCH] Hidraw should work --- dev_hidraw.c | 8 ++++++++ dev_hidraw.h | 6 +++++- dev_in.c | 27 ++++++++++++++++++++++----- input_dev.h | 6 +++++- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/dev_hidraw.c b/dev_hidraw.c index 1119421..cf6729b 100644 --- a/dev_hidraw.c +++ b/dev_hidraw.c @@ -116,3 +116,11 @@ int dev_hidraw_get_fd(const dev_hidraw_t* in_dev) { 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; +} diff --git a/dev_hidraw.h b/dev_hidraw.h index 0a8092b..2955110 100644 --- a/dev_hidraw.h +++ b/dev_hidraw.h @@ -17,4 +17,8 @@ int dev_hidraw_open( void dev_hidraw_close(dev_hidraw_t *const inout_dev); -int dev_hidraw_get_fd(const dev_hidraw_t* in_dev); \ No newline at end of file +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); \ No newline at end of file diff --git a/dev_in.c b/dev_in.c index 36ae639..3c75d7d 100644 --- a/dev_in.c +++ b/dev_in.c @@ -104,6 +104,26 @@ fill_message_from_evdev_err_completed: 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( const iio_filters_t *const in_filters, 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) { 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 = iio_open_device(&dev_in_data->input_dev_decl->dev[i]->filters.iio, &devices[i].dev.iio); + const int open_res = hidraw_open_device(&dev_in_data->input_dev_decl->dev[i]->filters.hidraw, &devices[i].dev.hidraw); if (open_res == 0) { devices[i].type = DEV_IN_TYPE_HIDRAW; } - */ } } } @@ -375,7 +392,7 @@ void* dev_in_thread_func(void *ptr) { // TODO: implement IIO //fill_message_from_iio(&devices[i].dev.iio, out_msg); } 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); } } } diff --git a/input_dev.h b/input_dev.h index 15e5b30..00dbbed 100644 --- a/input_dev.h +++ b/input_dev.h @@ -18,6 +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 enum input_dev_type { input_dev_type_uinput, @@ -59,7 +60,10 @@ typedef struct input_dev { 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;