Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0666cba2c |
2 changed files with 47 additions and 32 deletions
77
dev_in.c
77
dev_in.c
|
|
@ -328,6 +328,9 @@ void* dev_in_thread_func(void *ptr) {
|
||||||
|
|
||||||
const size_t max_devices = dev_in_data->input_dev_decl->dev_count;
|
const size_t max_devices = dev_in_data->input_dev_decl->dev_count;
|
||||||
|
|
||||||
|
in_message_t* controller_msg = malloc(sizeof(in_message_t) * 4);
|
||||||
|
size_t controller_msg_avail = controller_msg == NULL ? 0 : 4;
|
||||||
|
|
||||||
dev_in_t* const devices = malloc(sizeof(dev_in_t) * max_devices);
|
dev_in_t* const devices = malloc(sizeof(dev_in_t) * max_devices);
|
||||||
if (devices == NULL) {
|
if (devices == NULL) {
|
||||||
fprintf(stderr, "Unable to allocate memory to hold devices -- aborting input thread\n");
|
fprintf(stderr, "Unable to allocate memory to hold devices -- aborting input thread\n");
|
||||||
|
|
@ -463,40 +466,54 @@ void* dev_in_thread_func(void *ptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_message_t controller_msg[MAX_IN_MESSAGES];
|
int controller_msg_count = -ENOMEM;
|
||||||
size_t controller_msg_avail = sizeof(controller_msg) / sizeof(in_message_t);
|
while (controller_msg_count == -ENOMEM) {
|
||||||
int controller_msg_count = -EIO;
|
// the following part fills controller_msg and writes in controller_msg_count an error or the number of messages to be sent to the output device
|
||||||
|
if (devices[i].type == DEV_IN_TYPE_EV) {
|
||||||
|
evdev_collected_t coll = {
|
||||||
|
.ev_count = 0
|
||||||
|
};
|
||||||
|
|
||||||
// the following part fills controller_msg and writes in controller_msg_count an error or the number of messages to be sent to the output device
|
controller_msg_count = fill_message_from_evdev(&devices[i].dev.evdev, &coll);
|
||||||
if (devices[i].type == DEV_IN_TYPE_EV) {
|
if (controller_msg_count != 0) {
|
||||||
evdev_collected_t coll = {
|
fprintf(stderr, "Unable to fill input_event(s) for device %zd: %d -- Will reconnect the device\n", i, controller_msg_count);
|
||||||
.ev_count = 0
|
evdev_close_device(&devices[i].dev.evdev);
|
||||||
};
|
devices[i].type = DEV_IN_TYPE_NONE;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
controller_msg_count = fill_message_from_evdev(&devices[i].dev.evdev, &coll);
|
controller_msg_count = dev_in_data->input_dev_decl->dev[i]->map.ev_input_map_fn(&coll, controller_msg, controller_msg_avail, dev_in_data->input_dev_decl->dev[i]->user_data);
|
||||||
if (controller_msg_count != 0) {
|
} else if (devices[i].type == DEV_IN_TYPE_IIO) {
|
||||||
fprintf(stderr, "Unable to fill input_event(s) for device %zd: %d -- Will reconnect the device\n", i, controller_msg_count);
|
controller_msg_count = map_message_from_iio(&devices[i].dev.iio, controller_msg, controller_msg_avail);
|
||||||
evdev_close_device(&devices[i].dev.evdev);
|
if (controller_msg_count != 0) {
|
||||||
devices[i].type = DEV_IN_TYPE_NONE;
|
fprintf(stderr, "Error in performing operations for device %zd: %d -- Will reconnect to the device\n", i, controller_msg_count);
|
||||||
continue;
|
iio_close_device(&devices[i].dev.iio);
|
||||||
|
devices[i].type = DEV_IN_TYPE_NONE;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (devices[i].type == DEV_IN_TYPE_HIDRAW) {
|
||||||
|
controller_msg_count = dev_in_data->input_dev_decl->dev[i]->map.hidraw_input_map_fn(dev_hidraw_get_fd(devices[i].dev.hidraw.hidrawdev), controller_msg, controller_msg_avail, dev_in_data->input_dev_decl->dev[i]->user_data);
|
||||||
|
if (controller_msg_count != 0) {
|
||||||
|
fprintf(stderr, "Error in performing operations for device %zd: %d -- Will reconnect to the device\n", i, controller_msg_count);
|
||||||
|
hidraw_close_device(&devices[i].dev.hidraw);
|
||||||
|
devices[i].type = DEV_IN_TYPE_NONE;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
controller_msg_count = dev_in_data->input_dev_decl->dev[i]->map.ev_input_map_fn(&coll, &controller_msg[0], controller_msg_avail, dev_in_data->input_dev_decl->dev[i]->user_data);
|
// attempt to acquire more memory
|
||||||
} else if (devices[i].type == DEV_IN_TYPE_IIO) {
|
if (controller_msg_count == -ENOMEM) {
|
||||||
controller_msg_count = map_message_from_iio(&devices[i].dev.iio, &controller_msg[0], controller_msg_avail);
|
printf("Map function reported not enough memory, allocating new one...\n");
|
||||||
if (controller_msg_count != 0) {
|
const size_t tmp_controller_msg_avail = controller_msg_avail * 2;
|
||||||
fprintf(stderr, "Error in performing operations for device %zd: %d -- Will reconnect to the device\n", i, controller_msg_count);
|
in_message_t *tmp_controller_msg = malloc(sizeof(in_message_t) * tmp_controller_msg_avail);
|
||||||
iio_close_device(&devices[i].dev.iio);
|
if (tmp_controller_msg == NULL) {
|
||||||
devices[i].type = DEV_IN_TYPE_NONE;
|
fprintf(stderr, "Could not allocate new memory -- will retry\n");
|
||||||
continue;
|
} else {
|
||||||
}
|
printf("Allocated new memory to fill the buffer\n");
|
||||||
} else if (devices[i].type == DEV_IN_TYPE_HIDRAW) {
|
free(controller_msg);
|
||||||
controller_msg_count = dev_in_data->input_dev_decl->dev[i]->map.hidraw_input_map_fn(dev_hidraw_get_fd(devices[i].dev.hidraw.hidrawdev), &controller_msg[0], controller_msg_avail, dev_in_data->input_dev_decl->dev[i]->user_data);
|
controller_msg = tmp_controller_msg;
|
||||||
if (controller_msg_count != 0) {
|
controller_msg_avail = tmp_controller_msg_avail;
|
||||||
fprintf(stderr, "Error in performing operations for device %zd: %d -- Will reconnect to the device\n", i, controller_msg_count);
|
}
|
||||||
hidraw_close_device(&devices[i].dev.hidraw);
|
|
||||||
devices[i].type = DEV_IN_TYPE_NONE;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
dev_in.h
2
dev_in.h
|
|
@ -4,8 +4,6 @@
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "input_dev.h"
|
#include "input_dev.h"
|
||||||
|
|
||||||
#define MAX_IN_MESSAGES 8
|
|
||||||
|
|
||||||
#define DEV_IN_FLAG_EXIT 0x00000001U
|
#define DEV_IN_FLAG_EXIT 0x00000001U
|
||||||
|
|
||||||
typedef struct dev_in_data {
|
typedef struct dev_in_data {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue