summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClay Smith <claysmith158@gmail.com>2023-02-05 13:50:51 -0600
committerClay Smith <claysmith158@gmail.com>2023-02-05 13:50:51 -0600
commita8003ca6d7c1a48ad30aa8205d352031b21e7996 (patch)
tree06904f2f4e0f98417f16226fce35c6e51550ffd4
parentf54d199eb6e20fb38248d73cf83926360b6a57d2 (diff)
Now working with scanf properly on my end. Run the program without arguments to get devices connected, run with the number to run that device
-rw-r--r--Makefile3
-rw-r--r--handle_devices.c90
-rw-r--r--handle_devices.h10
-rw-r--r--main.c521
-rw-r--r--student.c24
5 files changed, 346 insertions, 302 deletions
diff --git a/Makefile b/Makefile
index ad796c4..12106c3 100644
--- a/Makefile
+++ b/Makefile
@@ -4,5 +4,8 @@ ALL_FLAGS = -g
main: main.c handle_devices.c
${CC} ${ALL_FLAGS} main.c handle_devices.c
+student: student.c
+ ${CC} ${ALL_FLAGS} student.c -o test
+
clean:
rm *\.o
diff --git a/handle_devices.c b/handle_devices.c
index df3e9f3..f32b85e 100644
--- a/handle_devices.c
+++ b/handle_devices.c
@@ -4,7 +4,7 @@
#include "global_defs.h"
#include <stdbool.h>
-void open_wii(int* controller_event_fptrs, uint64_t* connected_controllers) {
+void open_wii(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
//Determine if WII REMOTE is connected via bluetooth
int wii[4] = { 0 };
FILE* wii_pipe = popen("cat /proc/bus/input/devices | \
@@ -26,31 +26,35 @@ void open_wii(int* controller_event_fptrs, uint64_t* connected_controllers) {
controller_event_fptrs[WII_BUTTONS] = open(wii_events[BUTTONS], O_RDONLY);
//tell user and program that this device is available for use
*connected_controllers |= NINTENDO_GYRO_IR_AND_BUTTONS;
- printf("%4d: NINTENDO WII GYRO\n", NINTENDO_GYRO_BIT);
- printf("%4d: NINTENDO WII IR \n", NINTENDO_IR_BIT);
- printf("%4d: NINTENDO WII BUTTONS\n", NINTENDO_BUTTONS_BIT);
- printf("%4d: NINTENDO WII GYRO AND IR\n", NINTENDO_GYRO_AND_IR);
- printf("%4d: NINTENDO WII GYRO AND BUTTONS\n", NINTENDO_GYRO_AND_BUTTONS);
- printf("%4d: NINTENDO WII IR AND BUTTONS\n", NINTENDO_IR_AND_BUTTONS);
- printf("%4d: NINTENDO WII GYRO AND IR AND BUTTONS\n", NINTENDO_GYRO_IR_AND_BUTTONS);
+ if (choice) {
+ fprintf(stderr, "%4d: NINTENDO WII GYRO\n", NINTENDO_GYRO_BIT);
+ fprintf(stderr, "%4d: NINTENDO WII IR \n", NINTENDO_IR_BIT);
+ fprintf(stderr, "%4d: NINTENDO WII BUTTONS\n", NINTENDO_BUTTONS_BIT);
+ fprintf(stderr, "%4d: NINTENDO WII GYRO AND IR\n", NINTENDO_GYRO_AND_IR);
+ fprintf(stderr, "%4d: NINTENDO WII GYRO AND BUTTONS\n", NINTENDO_GYRO_AND_BUTTONS);
+ fprintf(stderr, "%4d: NINTENDO WII IR AND BUTTONS\n", NINTENDO_IR_AND_BUTTONS);
+ fprintf(stderr, "%4d: NINTENDO WII GYRO AND IR AND BUTTONS\n", NINTENDO_GYRO_IR_AND_BUTTONS);
+ }
//NUNCHUK CONNECTED?
if (wii[NUNCHUK] != 0) {
*connected_controllers |= NINTENDO_ALL_BITS;
snprintf(wii_events[NUNCHUK], 25, "/dev/input/event%d", wii[NUNCHUK]);
controller_event_fptrs[WII_NUNCHUK] = open(wii_events[NUNCHUK], O_RDONLY);
- printf("%4d: NINTENDO WII NUNCHUK\n", NINTENDO_NUNCHUK_BIT);
- printf("%4d: NINTENDO WII GYRO AND NUNCHUK\n", NINTENDO_GYRO_AND_NUNCHUK);
- printf("%4d: NINTENDO WII IR AND NUNCHUK\n", NINTENDO_IR_AND_NUNCHUK);
- printf("%4d: NINTENDO WII BUTTONS AND NUNCHUK\n", NINTENDO_BUTTONS_AND_NUNCHUK);
- printf("%4d: NINTENDO WII GYRO AND IR AND NUNCHUK\n", NINTENDO_GYRO_IR_AND_NUNCHUK);
- printf("%4d: NINTENDO WII GYRO AND BUTTONS AND NUNCHUK\n", NINTENDO_GYRO_BUTTONS_AND_NUNCHUK);
- printf("%4d: NINTENDO WII IR AND BUTTONS AND NUNCHUK\n", NINTENDO_IR_BUTTONS_AND_NUNCHUK);
- printf("%4d: ALL NINTENDO BT\n", NINTENDO_ALL_BITS);
+ if (choice) {
+ fprintf(stderr, "%4d: NINTENDO WII NUNCHUK\n", NINTENDO_NUNCHUK_BIT);
+ fprintf(stderr, "%4d: NINTENDO WII GYRO AND NUNCHUK\n", NINTENDO_GYRO_AND_NUNCHUK);
+ fprintf(stderr, "%4d: NINTENDO WII IR AND NUNCHUK\n", NINTENDO_IR_AND_NUNCHUK);
+ fprintf(stderr, "%4d: NINTENDO WII BUTTONS AND NUNCHUK\n", NINTENDO_BUTTONS_AND_NUNCHUK);
+ fprintf(stderr, "%4d: NINTENDO WII GYRO AND IR AND NUNCHUK\n", NINTENDO_GYRO_IR_AND_NUNCHUK);
+ fprintf(stderr, "%4d: NINTENDO WII GYRO AND BUTTONS AND NUNCHUK\n", NINTENDO_GYRO_BUTTONS_AND_NUNCHUK);
+ fprintf(stderr, "%4d: NINTENDO WII IR AND BUTTONS AND NUNCHUK\n", NINTENDO_IR_BUTTONS_AND_NUNCHUK);
+ fprintf(stderr, "%4d: ALL NINTENDO BT\n", NINTENDO_ALL_BITS);
+ }
}
}
}
-void open_ps4_bt(int* controller_event_fptrs, uint64_t* connected_controllers) {
+void open_ps4_bt(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
int ps4[NUM_EVENTS_PS4] = { 0 };
FILE* ps4_bt_pipe = popen("cat /proc/bus/input/devices | grep -A 5 \"^I: Bus=0005 Vendor=054c Product=09cc\" | grep \"event\" | cut -d 't' -f2 | paste - -s", "r");
fscanf(ps4_bt_pipe, "%2d %2d %2d", &ps4[TOUCHPAD], &ps4[GYRO], &ps4[BUTTONS]);
@@ -63,46 +67,54 @@ void open_ps4_bt(int* controller_event_fptrs, uint64_t* connected_controllers) {
controller_event_fptrs[PS4_BT_GYRO] = open(ps4_events[GYRO], O_RDONLY);
controller_event_fptrs[PS4_BT_BUTTONS] = open(ps4_events[BUTTONS], O_RDONLY);
*connected_controllers |= PS4_BT_ALL_BITS;
- printf("%4d: PS4 BT TOUCH \n", PS4_BT_TOUCH_BIT);
- printf("%4d: PS4 BT GYRO\n", PS4_BT_GYRO_BIT);
- printf("%4d: PS4 BT BUTTONS\n", PS4_BT_BUTTONS_BIT);
- printf("%4d: PS4 BT TOUCH AND GYRO \n", PS4_BT_TOUCH_AND_GYRO);
- printf("%4d: PS4 BT TOUCH AND BUTTONS\n", PS4_BT_TOUCH_AND_BUTTONS);
- printf("%4d: PS4 BT GYRO AND BUTTONS\n", PS4_BT_GYRO_AND_BUTTONS);
- printf("%4d: ALL PS4 BT\n", PS4_BT_ALL_BITS);
+ if (choice) {
+ fprintf(stderr, "%4d: PS4 BT TOUCH \n", PS4_BT_TOUCH_BIT);
+ fprintf(stderr, "%4d: PS4 BT GYRO\n", PS4_BT_GYRO_BIT);
+ fprintf(stderr, "%4d: PS4 BT BUTTONS\n", PS4_BT_BUTTONS_BIT);
+ fprintf(stderr, "%4d: PS4 BT TOUCH AND GYRO \n", PS4_BT_TOUCH_AND_GYRO);
+ fprintf(stderr, "%4d: PS4 BT TOUCH AND BUTTONS\n", PS4_BT_TOUCH_AND_BUTTONS);
+ fprintf(stderr, "%4d: PS4 BT GYRO AND BUTTONS\n", PS4_BT_GYRO_AND_BUTTONS);
+ fprintf(stderr, "%4d: ALL PS4 BT\n", PS4_BT_ALL_BITS);
+ }
}
}
-void open_ps4_wired(int* controller_event_fptrs, uint64_t* connected_controllers) {
+void open_ps4_wired(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
controller_event_fptrs[PS4_WIRED_GYRO] = open("/dev/input/by-id/usb-Sony_Interactive_Entertainment_Wireless_Controller-event-if03", O_RDONLY);
controller_event_fptrs[PS4_WIRED_BUTTONS] = open("/dev/input/by-id/usb-Sony_Interactive_Entertainment_Wireless_Controller-if03-event-joystick", O_RDONLY);
controller_event_fptrs[PS4_WIRED_TOUCH] = open("/dev/input/by-id/usb-Sony_Interactive_Entertainment_Wireless_Controller-if03-event-mouse", O_RDONLY);
if (controller_event_fptrs[PS4_WIRED_GYRO] != -1 && controller_event_fptrs[PS4_WIRED_BUTTONS] != -1 && controller_event_fptrs[PS4_WIRED_TOUCH] != -1) {
*connected_controllers |= PS4_WIRED_ALL_BITS;
- printf("%4d: PS4 WIRED TOUCH\n", PS4_WIRED_TOUCH_BIT);
- printf("%4d: PS4 WIRED GYRO\n", PS4_WIRED_GYRO_BIT);
- printf("%4d: PS4 WIRED BUTTONS\n", PS4_WIRED_BUTTONS_BIT);
- printf("%4d: PS4 WIRED TOUCH AND GYRO \n", PS4_WIRED_TOUCH_AND_GYRO);
- printf("%4d: PS4 WIRED TOUCH AND BUTTONS\n", PS4_WIRED_TOUCH_AND_BUTTONS);
- printf("%4d: PS4 WIRED GYRO AND BUTTONS\n", PS4_WIRED_GYRO_AND_BUTTONS);
- printf("%4d: ALL PS4 WIRED\n", PS4_WIRED_ALL_BITS);
+ if (choice) {
+ fprintf(stderr, "%4d: PS4 WIRED TOUCH\n", PS4_WIRED_TOUCH_BIT);
+ fprintf(stderr, "%4d: PS4 WIRED GYRO\n", PS4_WIRED_GYRO_BIT);
+ fprintf(stderr, "%4d: PS4 WIRED BUTTONS\n", PS4_WIRED_BUTTONS_BIT);
+ fprintf(stderr, "%4d: PS4 WIRED TOUCH AND GYRO \n", PS4_WIRED_TOUCH_AND_GYRO);
+ fprintf(stderr, "%4d: PS4 WIRED TOUCH AND BUTTONS\n", PS4_WIRED_TOUCH_AND_BUTTONS);
+ fprintf(stderr, "%4d: PS4 WIRED GYRO AND BUTTONS\n", PS4_WIRED_GYRO_AND_BUTTONS);
+ fprintf(stderr, "%4d: ALL PS4 WIRED\n", PS4_WIRED_ALL_BITS);
+ }
}
}
-void open_steam(int* controller_event_fptrs, uint64_t* connected_controllers) {
+void open_steam(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
controller_event_fptrs[VALVE_STEAM] = open("/dev/input/by-id/usb-Valve_Software_Wired_Controller-if02-event-joystick", O_RDONLY);
if (controller_event_fptrs[VALVE_STEAM] != -1) {
*connected_controllers |= (uint64_t) 1;
- printf("%4d: VALVE STEAM\n", 1);
+ if (choice) {
+ fprintf(stderr, "%4d: VALVE STEAM\n", 1);
+ }
}
}
-void open_xbox_360(int* controller_event_fptrs, uint64_t* connected_controllers) {
+void open_xbox_360(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
controller_event_fptrs[XBOX_360] = open("/dev/input/by-id/usb-©Microsoft_Xbox_360_Wireless_Receiver_for_Windows_E15D4C50-event-joystick", O_RDONLY);
if (controller_event_fptrs[XBOX_360] != -1) {
*connected_controllers |= (uint64_t) 2;
- printf("%4d: XBOX 360\n", 2);
+ if (choice) {
+ fprintf(stderr, "%4d: XBOX 360\n", 2);
+ }
}
}
@@ -188,7 +200,7 @@ void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ...
size_t start_sec = event[0].time.tv_sec;
while (read(controller_event_fptrs[pairs[0].event_fptr_index], &event[0], event_size) != -1) {
if (event[0].type == 0) continue;
-
+/*
printf("%d %zu.%-6zu %d %3d %11d\n",
pairs[0].event_user_num,
event[0].time.tv_sec - start_sec,
@@ -196,8 +208,8 @@ void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ...
event[0].type,
event[0].code,
event[0].value);
+*/
-/*
snprintf(buffer, BUFSIZE, "%d %zu.%-6zu %d %3d %11d\n",
pairs[0].event_user_num,
event[0].time.tv_sec - start_sec,
@@ -206,7 +218,7 @@ void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ...
event[0].code,
event[0].value);
write(STDOUT_FILENO, buffer, sizeof(buffer));
-*/
+
}
fprintf(stderr, "DISCONNECTED\n");
}
diff --git a/handle_devices.h b/handle_devices.h
index d70ff41..372e883 100644
--- a/handle_devices.h
+++ b/handle_devices.h
@@ -1,15 +1,15 @@
#ifndef HANDLE_DEVICES_H
#define HANDLE_DEVICES_H
-void open_wii(int* device_fptr_array, uint64_t* connected_controllers);
+void open_wii(int* device_fptr_array, uint64_t* connected_controllers, int choice);
-void open_ps4_bt(int* device_fptr_array, uint64_t* connected_controllers);
+void open_ps4_bt(int* device_fptr_array, uint64_t* connected_controllers, int choice);
-void open_ps4_wired(int* device_fptr_array, uint64_t* connected_controllers);
+void open_ps4_wired(int* device_fptr_array, uint64_t* connected_controllers, int choice);
-void open_steam(int* device_fptr_array, uint64_t* connected_controllers);
+void open_steam(int* device_fptr_array, uint64_t* connected_controllers, int choice);
-void open_xbox_360(int* device_fptr_array, uint64_t* connected_controllers);
+void open_xbox_360(int* device_fptr_array, uint64_t* connected_controllers, int choie);
void close_unneeded_files(int num_exceptions, int controller_event_fptrs[], ...);
diff --git a/main.c b/main.c
index 41c27ac..06e5f95 100644
--- a/main.c
+++ b/main.c
@@ -1,274 +1,279 @@
#include "global_defs.h"
#include "handle_devices.h"
-int main(void)
+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);
- 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);
+ 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 (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);
- }
+ if (!choice) {
+ 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);
+ }
-DUMB_USER:
- printf("\n\nPress the number corresponding to the device above that you would like to use and then press ENTER.\n");
+ fprintf(stderr, "\n\nPress the number corresponding to the device above that you would like to use and then press ENTER.\n");
- short choice;
- scanf("%d", &choice);
-
- struct input_event event1, event2, event3, event4;
- int ievt_size = sizeof(struct input_event);
- size_t start_sec;
-
- switch (choice) {
- case 1: //valve steam controller
- {
- close_unneeded_files(1, controller_event_fptrs, VALVE_STEAM);
- print_one_event(controller_event_fptrs, VALVE_STEAM, 1);
- break;
- }
- case 2: //xbox 360 controller
- {
- 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");
- goto DUMB_USER;
- break;
- }
+ } else {
+ struct input_event event1, event2, event3, event4;
+ int ievt_size = sizeof(struct input_event);
+ size_t start_sec;
+
+ switch (choice) {
+ case 1: //valve steam controller
+ {
+ close_unneeded_files(1, controller_event_fptrs, VALVE_STEAM);
+ print_one_event(controller_event_fptrs, VALVE_STEAM, 1);
+ break;
+ }
+ case 2: //xbox 360 controller
+ {
+ 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;
}
diff --git a/student.c b/student.c
new file mode 100644
index 0000000..908daa9
--- /dev/null
+++ b/student.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <unistd.h>
+#include "user_defs.h"
+
+int main(void)
+{
+ char buffer[100];
+ int num = -1, type = -1, code = -1, value = -1;
+ double time = -1;
+ int scan = -2;
+ char c;
+ while (1) {
+ fgets(buffer, 99, stdin);
+ //printf("%s", buffer);
+ //if (buffer[0] == '1') {
+ // printf("first value is 1\n");
+ // }
+ // scan = sscanf(buffer, "%d %lf %d %d %d\n", &num, &time, &type, &code, &value);
+ // printf("%d\n", scan);
+ scanf("%d %lf %d %d %d\n", &num, &time, &type, &code, &value);
+ printf("%d, %lf, %d, %d, %d\n", num, time, type, code, value);
+ }
+ return 0;
+}