#include "global_defs.h" #include "handle_devices.h" int main(int argc, char** argv) { system("clear"); setvbuf(stdout, NULL, _IONBF, BUFSIZ); long choice = 0; if (argc > 1) { char* end_ptr; choice = strtol(argv[1], &end_ptr, 10); } int controller_event_fptrs[NUM_EVENTS]; uint64_t connected_controllers = 0; open_wii(controller_event_fptrs, &connected_controllers, !choice); open_ps4_bt(controller_event_fptrs, &connected_controllers, !choice); open_ps4_wired(controller_event_fptrs, &connected_controllers, !choice); open_steam(controller_event_fptrs, &connected_controllers, !choice); open_xbox_360(controller_event_fptrs, &connected_controllers, !choice); if (!choice) { if (connected_controllers == 0) { fprintf(stderr, "No device matching the programs requirements (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); } fprintf(stderr, "\n\nUse the same command with a space followed by the number corresponding to the input listed above that you want to use.\n\n"); //fprintf(stderr, "\n\nIf no devices are listed above, then the program failed to find an acceptable device connected to the computer.\n\n"); } else { struct input_event event1, event2, event3, event4; int ievt_size = sizeof(struct input_event); size_t start_sec; switch (choice) { case STEAM_BIT: { close_unneeded_files(1, controller_event_fptrs, VALVE_STEAM); print_one_event(controller_event_fptrs, VALVE_STEAM, 1); break; } case XBOX_360_BIT: { close_unneeded_files(1, controller_event_fptrs, XBOX_360); print_one_event(controller_event_fptrs, XBOX_360, 1); break; } case PS4_WIRED_TOUCH_BIT: { close_unneeded_files(1, controller_event_fptrs, PS4_WIRED_TOUCH); print_one_event(controller_event_fptrs, PS4_WIRED_TOUCH, 1); break; } case PS4_WIRED_GYRO_BIT: { close_unneeded_files(1, controller_event_fptrs, PS4_WIRED_GYRO); print_one_event(controller_event_fptrs, PS4_WIRED_GYRO, 2); break; } case PS4_WIRED_BUTTONS_BIT: { close_unneeded_files(1, controller_event_fptrs, PS4_WIRED_BUTTONS); print_one_event(controller_event_fptrs, PS4_WIRED_BUTTONS, 3); break; } case PS4_WIRED_TOUCH_AND_GYRO: { close_unneeded_files(2, controller_event_fptrs, PS4_WIRED_TOUCH, PS4_WIRED_GYRO); 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); 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); 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); 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: { close_unneeded_files(1, controller_event_fptrs, PS4_BT_TOUCH ); print_one_event(controller_event_fptrs, PS4_BT_TOUCH, 1); break; } case PS4_BT_GYRO_BIT: { close_unneeded_files(1, controller_event_fptrs, PS4_BT_GYRO ); print_one_event(controller_event_fptrs, PS4_BT_GYRO, 2); break; } case PS4_BT_BUTTONS_BIT: { close_unneeded_files(1, controller_event_fptrs, PS4_BT_BUTTONS ); print_one_event(controller_event_fptrs, PS4_BT_BUTTONS, 3); break; } case PS4_BT_TOUCH_AND_GYRO: { close_unneeded_files(2, controller_event_fptrs, PS4_BT_TOUCH, PS4_BT_GYRO); 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); 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); 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); 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: { close_unneeded_files(1, controller_event_fptrs, WII_GYRO); print_one_event(controller_event_fptrs, WII_GYRO, 1); break; } case NINTENDO_IR_BIT: { close_unneeded_files(1, controller_event_fptrs, WII_IR); print_one_event(controller_event_fptrs, WII_IR, 2); break; } case NINTENDO_BUTTONS_BIT: { close_unneeded_files(1, controller_event_fptrs, WII_BUTTONS); print_one_event(controller_event_fptrs, WII_BUTTONS, 3); break; } case NINTENDO_NUNCHUK_BIT: { close_unneeded_files(1, controller_event_fptrs, WII_NUNCHUK); print_one_event(controller_event_fptrs, WII_NUNCHUK, 4); break; } case NINTENDO_GYRO_AND_IR: { close_unneeded_files(2, controller_event_fptrs, WII_GYRO, WII_IR); 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); 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); 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: You entered an invalid number!\n"); exit(-1); } } } return 0; }