From 038cca642bc8627162bdf50b132396595f9f73ea Mon Sep 17 00:00:00 2001 From: Clay Smith Date: Wed, 1 Feb 2023 18:48:57 -0600 Subject: Done minux adding new controllers? --- main.c | 382 ++++++++++++----------------------------------------------------- 1 file changed, 67 insertions(+), 315 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 01e393b..41c27ac 100644 --- a/main.c +++ b/main.c @@ -1,30 +1,20 @@ #include "global_defs.h" #include "handle_devices.h" -void print_single_event(int event_index) { -} - int main(void) { system("clear"); setvbuf(stdout, NULL, _IONBF, BUFSIZ); - int controller_event_fptrs[NUM_EVENTS]; uint64_t connected_controllers = 0; - open_wii(controller_event_fptrs, &connected_controllers); - open_ps4_bt(controller_event_fptrs, &connected_controllers); - open_ps4_wired(controller_event_fptrs, &connected_controllers); - open_steam(controller_event_fptrs, &connected_controllers); - open_xbox_360(controller_event_fptrs, &connected_controllers); - if (connected_controllers == 0) { fprintf(stderr, "No device matching the programs requirments (DualShock 4, Xbox 360, Valve Steam, or Wii Controller) was found, please double check the connection if you do not think that this is the case.\n"); return(-1); @@ -74,135 +64,34 @@ DUMB_USER: case PS4_WIRED_TOUCH_AND_GYRO: { close_unneeded_files(2, controller_event_fptrs, PS4_WIRED_TOUCH, PS4_WIRED_GYRO); - read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size); - read(controller_event_fptrs[PS4_WIRED_GYRO], &event2, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size); - printf("1 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - while (1) { - read(controller_event_fptrs[PS4_WIRED_GYRO], &event2, ievt_size); - printf("2 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } + struct event_pairs first_event = {PS4_WIRED_TOUCH, 1}, + second_event = {PS4_WIRED_GYRO, 2}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case PS4_WIRED_TOUCH_AND_BUTTONS: { close_unneeded_files(2, controller_event_fptrs, PS4_WIRED_TOUCH, PS4_WIRED_BUTTONS); - read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size); - read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event2, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size); - printf("1 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - while (1) { - read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event2, ievt_size); - printf("3 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } + struct event_pairs first_event = {PS4_WIRED_TOUCH, 1}, + second_event = {PS4_WIRED_BUTTONS, 3}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case PS4_WIRED_GYRO_AND_BUTTONS: { close_unneeded_files(2, controller_event_fptrs, PS4_WIRED_GYRO, PS4_WIRED_BUTTONS); - read(controller_event_fptrs[PS4_WIRED_GYRO], &event1, ievt_size); - read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event2, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_WIRED_GYRO], &event1, ievt_size); - printf("2 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - while (1) { - read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event2, ievt_size); - printf("3 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } + struct event_pairs first_event = {PS4_WIRED_GYRO, 2}, + second_event = {PS4_WIRED_BUTTONS, 3}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case PS4_WIRED_ALL_BITS: { close_unneeded_files(3, controller_event_fptrs, PS4_WIRED_TOUCH, PS4_WIRED_GYRO, PS4_WIRED_BUTTONS); - read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size); - read(controller_event_fptrs[PS4_WIRED_GYRO], &event2, ievt_size); - read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event3, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size); - printf("1 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_WIRED_GYRO], &event2, ievt_size); - printf("2 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } else { - while (1) { - read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event3, ievt_size); - printf("3 %zu.%-6zu %d %3d %9d\n", - event3.time.tv_sec - start_sec, - event3.time.tv_usec, - event3.type, - event3.code, - event3.value); - } - } - } + struct event_pairs first_event = {PS4_WIRED_TOUCH, 1}, + second_event = {PS4_WIRED_GYRO, 2}, + third_event = {PS4_WIRED_BUTTONS, 3}; + print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event); break; } case PS4_BT_TOUCH_BIT: @@ -226,135 +115,34 @@ DUMB_USER: case PS4_BT_TOUCH_AND_GYRO: { close_unneeded_files(2, controller_event_fptrs, PS4_BT_TOUCH, PS4_BT_GYRO); - read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size); - read(controller_event_fptrs[PS4_BT_GYRO], &event2, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size); - printf("1 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - while (1) { - read(controller_event_fptrs[PS4_BT_GYRO], &event2, ievt_size); - printf("2 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } + struct event_pairs first_event = {PS4_BT_TOUCH, 1}, + second_event = {PS4_BT_GYRO, 2}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case PS4_BT_TOUCH_AND_BUTTONS: { close_unneeded_files(2, controller_event_fptrs, PS4_BT_TOUCH, PS4_BT_BUTTONS); - read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size); - read(controller_event_fptrs[PS4_BT_BUTTONS], &event2, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size); - printf("1 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - while (1) { - read(controller_event_fptrs[PS4_BT_BUTTONS], &event2, ievt_size); - printf("3 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } + struct event_pairs first_event = {PS4_BT_TOUCH, 1}, + second_event = {PS4_BT_BUTTONS, 3}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case PS4_BT_GYRO_AND_BUTTONS: { close_unneeded_files(2, controller_event_fptrs, PS4_BT_GYRO, PS4_BT_BUTTONS); - read(controller_event_fptrs[PS4_BT_GYRO], &event1, ievt_size); - read(controller_event_fptrs[PS4_BT_BUTTONS], &event2, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_BT_GYRO], &event1, ievt_size); - printf("2 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - while (1) { - read(controller_event_fptrs[PS4_BT_BUTTONS], &event2, ievt_size); - printf("3 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } + struct event_pairs first_event = {PS4_BT_GYRO, 2}, + second_event = {PS4_BT_BUTTONS, 3}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case PS4_BT_ALL_BITS: { close_unneeded_files(3, controller_event_fptrs, PS4_BT_TOUCH, PS4_BT_GYRO, PS4_BT_BUTTONS); - read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size); - read(controller_event_fptrs[PS4_BT_GYRO], &event2, ievt_size); - read(controller_event_fptrs[PS4_BT_BUTTONS], &event3, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size); - printf("1 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[PS4_BT_GYRO], &event2, ievt_size); - printf("2 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } else { - while (1) { - read(controller_event_fptrs[PS4_BT_BUTTONS], &event3, ievt_size); - printf("3 %zu.%-6zu %d %3d %9d\n", - event3.time.tv_sec - start_sec, - event3.time.tv_usec, - event3.type, - event3.code, - event3.value); - } - } - } + struct event_pairs first_event = {PS4_BT_TOUCH, 1}, + second_event = {PS4_BT_GYRO, 2}, + third_event = {PS4_BT_BUTTONS, 3}; + print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event); break; } case NINTENDO_GYRO_BIT: @@ -384,137 +172,101 @@ DUMB_USER: case NINTENDO_GYRO_AND_IR: { close_unneeded_files(2, controller_event_fptrs, WII_GYRO, WII_IR); - read(controller_event_fptrs[WII_GYRO], &event1, ievt_size); - read(controller_event_fptrs[WII_IR], &event2, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[WII_GYRO], &event1, ievt_size); - printf("1 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - while (1) { - read(controller_event_fptrs[WII_IR], &event2, ievt_size); - printf("2 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } + struct event_pairs first_event = {WII_GYRO, 1}, + second_event = {WII_IR, 2}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case NINTENDO_GYRO_AND_BUTTONS: { close_unneeded_files(2, controller_event_fptrs, WII_GYRO, WII_BUTTONS); - read(controller_event_fptrs[WII_GYRO], &event1, ievt_size); - read(controller_event_fptrs[WII_BUTTONS], &event2, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[WII_GYRO], &event1, ievt_size); - printf("1 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - while (1) { - read(controller_event_fptrs[WII_BUTTONS], &event2, ievt_size); - printf("3 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } + struct event_pairs first_event = {WII_GYRO, 1}, + second_event = {WII_BUTTONS, 3}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case NINTENDO_GYRO_AND_NUNCHUK: { close_unneeded_files(2, controller_event_fptrs, WII_GYRO, WII_NUNCHUK); - read(controller_event_fptrs[WII_GYRO], &event1, ievt_size); - read(controller_event_fptrs[WII_BUTTONS], &event2, ievt_size); - start_sec = event1.time.tv_sec; - int pid = fork(); - if (pid == 0) { - while (1) { - read(controller_event_fptrs[WII_GYRO], &event1, ievt_size); - printf("1 %zu.%-6zu %d %3d %9d\n", - event1.time.tv_sec - start_sec, - event1.time.tv_usec, - event1.type, - event1.code, - event1.value); - } - } else { - while (1) { - read(controller_event_fptrs[WII_BUTTONS], &event2, ievt_size); - printf("3 %zu.%-6zu %d %3d %9d\n", - event2.time.tv_sec - start_sec, - event2.time.tv_usec, - event2.type, - event2.code, - event2.value); - } - } + struct event_pairs first_event = {WII_GYRO, 1}, + second_event = {WII_NUNCHUK, 4}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case NINTENDO_IR_AND_BUTTONS: { close_unneeded_files(2, controller_event_fptrs, WII_IR, WII_BUTTONS); + struct event_pairs first_event = {WII_IR, 2}, + second_event = {WII_BUTTONS, 3}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case NINTENDO_IR_AND_NUNCHUK: { close_unneeded_files(2, controller_event_fptrs, WII_IR, WII_NUNCHUK); + struct event_pairs first_event = {WII_IR, 2}, + second_event = {WII_NUNCHUK, 4}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case NINTENDO_BUTTONS_AND_NUNCHUK: { close_unneeded_files(2, controller_event_fptrs, WII_BUTTONS, WII_NUNCHUK); + struct event_pairs first_event = {WII_BUTTONS, 3}, + second_event = {WII_NUNCHUK, 4}; + print_multiple_events(2, controller_event_fptrs, first_event, second_event); break; } case NINTENDO_GYRO_IR_AND_BUTTONS: { close_unneeded_files(3, controller_event_fptrs, WII_GYRO, WII_IR, WII_BUTTONS); + struct event_pairs first_event = {WII_GYRO, 1}, + second_event = {WII_IR, 2}, + third_event = {WII_BUTTONS, 3}; + print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event); break; } case NINTENDO_GYRO_IR_AND_NUNCHUK: { close_unneeded_files(3, controller_event_fptrs, WII_GYRO, WII_IR, WII_NUNCHUK); + struct event_pairs first_event = {WII_GYRO, 1}, + second_event = {WII_IR, 2}, + third_event = {WII_NUNCHUK, 4}; + print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event); break; } case NINTENDO_GYRO_BUTTONS_AND_NUNCHUK: { close_unneeded_files(3, controller_event_fptrs, WII_GYRO, WII_BUTTONS, WII_NUNCHUK); + struct event_pairs first_event = {WII_GYRO, 1}, + second_event = {WII_BUTTONS, 3}, + third_event = {WII_NUNCHUK, 4}; + print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event); break; } case NINTENDO_IR_BUTTONS_AND_NUNCHUK: { close_unneeded_files(3, controller_event_fptrs, WII_IR, WII_BUTTONS, WII_NUNCHUK); + struct event_pairs first_event = {WII_IR, 2}, + second_event = {WII_BUTTONS, 3}, + third_event = {WII_NUNCHUK, 4}; + print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event); break; } case NINTENDO_ALL_BITS: { close_unneeded_files(4, controller_event_fptrs, WII_GYRO, WII_IR, WII_BUTTONS, WII_NUNCHUK); + struct event_pairs first_event = {WII_GYRO, 1}, + second_event = {WII_IR, 2}, + third_event = {WII_BUTTONS, 3}, + fourth_event = {WII_NUNCHUK, 4}; + print_multiple_events(4, controller_event_fptrs, first_event, second_event, third_event, fourth_event); break; } default: { - fprintf(stderr, "ERROR: Do not know how you made it here.\n"); - exit(-1); + fprintf(stderr, "ERROR: You entered an invalid number!\n"); + goto DUMB_USER; break; } } -- cgit v1.2.1