The bbcr broke off my compilation help plz

This commit is contained in:
Denis 2023-12-06 21:05:02 +01:00
parent 91a639852f
commit 37c23e1b62
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
28 changed files with 1042 additions and 1256 deletions

141
main.c
View file

@ -3,6 +3,8 @@
#include "input_dev.h"
#include "output_dev.h"
#include "dev_in.h"
#include "dev_out.h"
#include "logic.h"
logic_t global_logic;
@ -11,48 +13,48 @@ static output_dev_t out_gamepadd_dev = {
.logic = &global_logic,
};
static iio_filters_t in_iio_filters = {
.name = "bmi323",
};
static input_dev_t in_iio_dev = {
.dev_type = input_dev_type_iio,
.iio_filters = &in_iio_filters,
.logic = &global_logic,
.filters = {
.iio = {
.name = "bmi323",
}
},
//.logic = &global_logic,
//.input_filter_fn = input_filter_imu_identity,
};
static uinput_filters_t in_asus_kb_1_filters = {
.name = "Asus Keyboard",
};
static input_dev_t in_asus_kb_1_dev = {
.dev_type = input_dev_type_uinput,
.ev_filters = &in_asus_kb_1_filters,
.logic = &global_logic,
.ev_input_filter_fn = input_filter_asus_kb,
};
static uinput_filters_t in_asus_kb_2_filters = {
.name = "Asus Keyboard",
.filters = {
.ev = {
.name = "Asus Keyboard"
}
},
//.logic = &global_logic,
//.ev_input_filter_fn = input_filter_asus_kb,
};
static input_dev_t in_asus_kb_2_dev = {
.dev_type = input_dev_type_uinput,
.ev_filters = &in_asus_kb_2_filters,
.logic = &global_logic,
.ev_input_filter_fn = input_filter_asus_kb,
};
static uinput_filters_t in_asus_kb_3_filters = {
.name = "Asus Keyboard",
.filters = {
.ev = {
.name = "Asus Keyboard"
}
},
//.logic = &global_logic,
//.ev_input_filter_fn = input_filter_asus_kb,
};
static input_dev_t in_asus_kb_3_dev = {
.dev_type = input_dev_type_uinput,
.ev_filters = &in_asus_kb_3_filters,
.logic = &global_logic,
.ev_input_filter_fn = input_filter_asus_kb,
.filters = {
.ev = {
.name = "Asus Keyboard"
}
},
//.logic = &global_logic,
//.ev_input_filter_fn = input_filter_asus_kb,
};
static uinput_filters_t in_xbox_filters = {
@ -61,34 +63,23 @@ static uinput_filters_t in_xbox_filters = {
static input_dev_t in_xbox_dev = {
.dev_type = input_dev_type_uinput,
.ev_filters = &in_xbox_filters,
.logic = &global_logic,
.ev_input_filter_fn = input_filter_identity,
.filters = {
.ev = {
.name = "Microsoft X-Box 360 pad"
}
},
//.logic = &global_logic,
//.ev_input_filter_fn = input_filter_asus_kb,
};
int start_input_devices(pthread_t *out_threads, input_dev_t **in_devs, uint16_t in_count) {
int ret = 0;
uint16_t i = 0;
for (i = 0; i < in_count; ++i) {
const int thread_creation = pthread_create(&out_threads[i], NULL, input_dev_thread_func, (void*)(in_devs[i]));
if (thread_creation != 0) {
fprintf(stderr, "Error creating input thread for device %d: %d\n", (int)i, thread_creation);
ret = -1;
// TODO: logic_request_termination(&global_logic);
goto start_input_devices_err;
}
}
start_input_devices_err:
return ret;
}
dev_in_data_t dev_in_thread_data;
dev_out_data_t dev_out_thread_data;
void sig_handler(int signo)
{
if (signo == SIGINT) {
logic_request_termination(&global_logic);
printf("received SIGINT\n");
printf("Received SIGINT\n");
}
}
@ -101,7 +92,6 @@ int main(int argc, char ** argv) {
return EXIT_FAILURE;
}
input_dev_t *in_devs[] = {
&in_xbox_dev,
&in_iio_dev,
@ -110,24 +100,40 @@ int main(int argc, char ** argv) {
&in_asus_kb_3_dev,
};
const uint16_t input_dev_count = (sizeof(in_devs) / sizeof(input_dev_t *));
int out_message_pipes[2];
pipe(out_message_pipes);
pthread_t *out_threads = malloc(sizeof(pthread_t) * input_dev_count);
int in_message_pipes[2];
pipe(in_message_pipes);
ret = start_input_devices(out_threads, in_devs, input_dev_count);
if (ret != 0) {
fprintf(stderr, "Unable to start input devices: %d -- terminating...\n", ret);
goto input_threads_err;
}
// populate the input device thread data
dev_in_thread_data.timeout_ms = 400;
dev_in_thread_data.in_message_pipe_fd = in_message_pipes[1];
dev_in_thread_data.out_message_pipe_fd = out_message_pipes[0];
dev_in_thread_data.input_dev_decl = *in_devs;
dev_in_thread_data.input_dev_cnt = sizeof(in_devs) / sizeof(input_dev_t *);
// populate the output device thread data
//dev_out_thread_data.timeout_ms = 400;
dev_out_thread_data.in_message_pipe_fd = in_message_pipes[0];
dev_out_thread_data.out_message_pipe_fd = out_message_pipes[1];
pthread_t gamepad_thread;
const int gamepad_thread_creation = pthread_create(&gamepad_thread, NULL, output_dev_thread_func, (void*)(&out_gamepadd_dev));
if (gamepad_thread_creation != 0) {
fprintf(stderr, "Error creating gamepad output thread: %d\n", gamepad_thread_creation);
pthread_t dev_in_thread;
const int dev_in_thread_creation = pthread_create(&dev_in_thread, NULL, dev_in_thread_func, (void*)(&dev_in_thread_data));
if (dev_in_thread_creation != 0) {
fprintf(stderr, "Error creating dev_in thread: %d\n", dev_in_thread_creation);
ret = -1;
logic_request_termination(&global_logic);
goto gamepad_thread_err;
goto main_err;
}
pthread_t dev_out_thread;
const int dev_out_thread_creation = pthread_create(&dev_out_thread, NULL, dev_out_thread_func, (void*)(&dev_out_thread_data));
if (dev_out_thread_creation != 0) {
fprintf(stderr, "Error creating dev_out thread: %d\n", dev_out_thread_creation);
ret = -1;
logic_request_termination(&global_logic);
goto main_err;
}
/*
@ -139,13 +145,14 @@ int main(int argc, char ** argv) {
}
*/
for (uint16_t j = 0; j < input_dev_count; ++j) {
pthread_join(out_threads[j], NULL);
main_err:
if (dev_in_thread_creation == 0) {
pthread_join(dev_in_thread, NULL);
}
pthread_join(gamepad_thread, NULL);
if (dev_out_thread_creation == 0) {
pthread_join(dev_out_thread, NULL);
}
gamepad_thread_err:
input_threads_err:
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}