summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClay Smith <claysmith158@gmail.com>2023-02-19 16:40:14 -0600
committerClay Smith <claysmith158@gmail.com>2023-02-19 16:40:14 -0600
commit2c8e4dbe5f597141cc9e3aeef19cceff58213853 (patch)
tree5cd39b506d072a41f8e633d3e6c95649ac51902f
parent02d4b7d68534284f42bb69dcc0efadd0eb4f1ae1 (diff)
DONE
-rwxr-xr-xController_Program.numbersbin0 -> 346764 bytes
-rw-r--r--devoutbin45640 -> 32568 bytes
-rw-r--r--handle_devices.c304
-rw-r--r--handle_devices.h16
-rw-r--r--main.c284
-rw-r--r--student.c2
-rw-r--r--testbin27712 -> 26360 bytes
7 files changed, 101 insertions, 505 deletions
diff --git a/Controller_Program.numbers b/Controller_Program.numbers
new file mode 100755
index 0000000..bae50a9
--- /dev/null
+++ b/Controller_Program.numbers
Binary files differ
diff --git a/devout b/devout
index 716d317..68ed13b 100644
--- a/devout
+++ b/devout
Binary files differ
diff --git a/handle_devices.c b/handle_devices.c
index dd154aa..0b646cb 100644
--- a/handle_devices.c
+++ b/handle_devices.c
@@ -1,295 +1,145 @@
-#include <stdint.h>
#include <stdio.h>
+#include <stdint.h>
#include <stdarg.h>
-#include "global_defs.h"
#include <stdbool.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <unistd.h>
#include <sys/mman.h>
+#include <linux/input.h>
-void open_wii(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
- //Determine if WII REMOTE is connected via bluetooth
- int wii[NUM_EVENTS_WII] = { 0 };
- FILE* wii_pipe = popen("cat /proc/bus/input/devices | \
- grep -A 5 \"^I: Bus=0005 Vendor=057e Product=0306\" | \
- grep \"event\" | \
- cut -d 't' -f2 | \
- cut -d ' ' -f1 | \
- paste - -s", \
- "r");
- fscanf(wii_pipe, "%2d %2d %2d %2d", &wii[GYRO], &wii[IR], &wii[BUTTONS], &wii[NUNCHUK]);
- if ( wii[GYRO] != 0 && wii[IR] != 0 && wii[BUTTONS] != 0) {
- //wii is connected, create strings of event PATHS, open event files
- char wii_events[NUM_EVENTS_WII][26];
- snprintf(wii_events[GYRO], 25, "/dev/input/event%d", wii[GYRO]);
- controller_event_fptrs[WII_GYRO] = open(wii_events[GYRO], O_RDONLY);
- snprintf(wii_events[IR], 25, "/dev/input/event%d", wii[IR]);
- controller_event_fptrs[WII_IR] = open(wii_events[IR], O_RDONLY);
- snprintf(wii_events[BUTTONS], 25, "/dev/input/event%d", wii[BUTTONS]);
- 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;
- 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);
- 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, 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]);
- if ( ps4[TOUCHPAD] != 0 && ps4[GYRO] != 0 && ps4[BUTTONS] != 0) {
- char ps4_events[NUM_EVENTS_PS4][26];
- snprintf(ps4_events[TOUCHPAD], 25, "/dev/input/event%d", ps4[TOUCHPAD]);
- controller_event_fptrs[PS4_BT_TOUCH] = open(ps4_events[TOUCHPAD], O_RDONLY);
- snprintf(ps4_events[GYRO], 25, "/dev/input/event%d", ps4[GYRO]);
- controller_event_fptrs[PS4_BT_GYRO] = open(ps4_events[GYRO], O_RDONLY);
- snprintf(ps4_events[BUTTONS], 25, "/dev/input/event%d", ps4[BUTTONS]);
- controller_event_fptrs[PS4_BT_BUTTONS] = open(ps4_events[BUTTONS], O_RDONLY);
- *connected_controllers |= 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, int choice) {
- int ps4[NUM_EVENTS_PS4] = { 0 };
- FILE* ps4_wired_pipe = popen("cat /proc/bus/input/devices | grep -A 5 \"^I: Bus=0003 Vendor=054c Product=09cc\" | grep \"event\" | cut -d 't' -f2 | paste - -s", "r");
- fscanf(ps4_wired_pipe, "%2d %2d %2d", &ps4[TOUCHPAD], &ps4[GYRO], &ps4[BUTTONS]);
- if ( ps4[TOUCHPAD] != 0 && ps4[GYRO] != 0 && ps4[BUTTONS] != 0) {
- char ps4_events[NUM_EVENTS_PS4][26];
- snprintf(ps4_events[TOUCHPAD], 25, "/dev/input/event%d", ps4[TOUCHPAD]);
- controller_event_fptrs[PS4_WIRED_TOUCH] = open(ps4_events[TOUCHPAD], O_RDONLY);
- snprintf(ps4_events[GYRO], 25, "/dev/input/event%d", ps4[GYRO]);
- controller_event_fptrs[PS4_WIRED_GYRO] = open(ps4_events[GYRO], O_RDONLY);
- snprintf(ps4_events[BUTTONS], 25, "/dev/input/event%d", ps4[BUTTONS]);
- controller_event_fptrs[PS4_WIRED_BUTTONS] = open(ps4_events[BUTTONS], O_RDONLY);
- *connected_controllers |= 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, int choice) {
- int steam_event_number = 0;
- FILE* steam_pipe = popen("cat /proc/bus/input/devices | grep -A 5 \"^I: Bus=0003 Vendor=28de Product=1102\" | tail -n 6 | grep \"event\" | cut -d \"t\" -f2", "r");
- fscanf(steam_pipe, "%2d", &steam_event_number);
- if ( steam_event_number != 0) {
- char steam_event_string[26];
- snprintf(steam_event_string, 25, "/dev/input/event%d", steam_event_number);
- controller_event_fptrs[VALVE_STEAM] = open(steam_event_string, O_RDONLY);
- *connected_controllers |= STEAM_BIT;
- if (choice) {
- fprintf(stderr, "%4d: STEAM \n", STEAM_BIT);
- }
- }
-}
-
-void open_xbox_360(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
- int xbox_360_event_number = 0;
- FILE* xbox_360_pipe = popen("cat /proc/bus/input/devices | grep -A 5 \"^I: Bus=0003 Vendor=045e Product=02a1\" | tail -n1 | cut -d \"t\" -f2", "r");
- fscanf(xbox_360_pipe, "%2d", &xbox_360_event_number);
- if ( xbox_360_event_number != 0) {
- char xbox_360_event_string[26];
- snprintf(xbox_360_event_string, 25, "/dev/input/event%d", xbox_360_event_number);
- controller_event_fptrs[XBOX_360] = open(xbox_360_event_string, O_RDONLY);
- *connected_controllers |= XBOX_360_BIT;
- if (choice) {
- fprintf(stderr, "%4d: XBOX 360 \n", XBOX_360_BIT);
- }
- }
-}
+#define BUFSIZE 45
+#define PATH_SIZE 26
-
-void close_unneeded_files(int num_exceptions, int controller_event_fptrs[], ...) {
- int* events_to_skip = (int *) malloc(sizeof(int) * num_exceptions);
- va_list list_of_args;
- va_start(list_of_args, controller_event_fptrs);
- //get arguments
- for (int i = 0; i < num_exceptions; ++i) {
- events_to_skip[i] = va_arg(list_of_args, int);
+void show_device_options(void)
+{
+ FILE* pipe = popen("cat /proc/bus/input/devices | \
+ grep \"^N:\\|^H:\\|^$\" | \
+ cut -d '=' -f2-",
+ "r");
+ int character = 0;
+ character = getc(pipe);
+ while (character != EOF) {
+ printf("%c", character);
+ character = getc(pipe);
}
- //close all but the provided arguments
- for (int i = 0; i < NUM_EVENTS; ++i) {
- for (int j = 0; j < num_exceptions; ++j) {
- if (i == events_to_skip[j]) {
- goto SKIP_CLOSE;
- }
- }
- close(controller_event_fptrs[i]);
-SKIP_CLOSE:
- }
}
-void print_one_event(int controller_event_fptrs[], int index, int event_number) {
- struct input_event event1;
+void print_one_event(unsigned long long event_num)
+{
+ struct input_event event;
int event_size = sizeof(struct input_event);
- size_t start_sec;
- int initial_read = read(controller_event_fptrs[index], &event1, event_size);
+ unsigned long start_sec;
+ char path_to_event[PATH_SIZE];
+ snprintf(path_to_event, PATH_SIZE - 1, "/dev/input/event%lld", event_num);
+ int fptr = open(path_to_event, O_RDWR);
+ int initial_read = read(fptr, &event, event_size);
if (initial_read == -1) {
fprintf(stderr, "PROBLEM READING FILE!\n");
exit(-1);
}
char buffer[BUFSIZE+1] = {0};
- start_sec = event1.time.tv_sec;
- while (read(controller_event_fptrs[index], &event1, event_size) != -1) {
- if (event1.type == 0) continue;
-/*
- printf("%d %lu.%06lu %d %3d %11d\n",
- event_number,
- (unsigned long) event1.time.tv_sec - start_sec,
- (unsigned long) event1.time.tv_usec,
- event1.type,
- event1.code,
- event1.value);
-*/
-///*
- snprintf(buffer, BUFSIZE, "%d %lu.%06lu %d %3d %11d\n",
- event_number,
- (unsigned long) event1.time.tv_sec - start_sec,
- (unsigned long) event1.time.tv_usec,
- event1.type,
- event1.code,
- event1.value);
- write(STDOUT_FILENO, buffer, sizeof(buffer));
-//*/
+ start_sec = event.time.tv_sec;
+ int string_size = 0;
+ while (read(fptr, &event, event_size) != -1) {
+ if (event.type == 0) continue;
+ string_size = snprintf(buffer, BUFSIZE, "%lld %lu.%06lu %d %3d %11d\n",
+ event_num,
+ (unsigned long) event.time.tv_sec - start_sec,
+ (unsigned long) event.time.tv_usec,
+ event.type,
+ event.code,
+ event.value);
+ write(STDOUT_FILENO, buffer, string_size);
}
fprintf(stderr, "DISCONNECTED\n");
}
-void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ...) {
- pid_t pids[num_exceptions];
- //set all pids to -1 at start
- for (int i = 0; i < num_exceptions; ++i) { pids[i] = -1; }
- //get all the variadic pairs sent in and store them in an array of the appropriate size
- struct event_pairs pairs[num_exceptions];
- va_list list_of_args;
- va_start(list_of_args, controller_event_fptrs);
- for (int i = 0; i < num_exceptions; ++i) {
- pairs[i] = va_arg(list_of_args, struct event_pairs);
- }
+
+void print_multiple_events(int num_events, unsigned long long event_nums[])
+{
//prepare to start printing inputs
- struct input_event event[num_exceptions];
+ struct input_event event[num_events];
int event_size = sizeof(struct input_event);
- int read_time = read(controller_event_fptrs[pairs[0].event_fptr_index], &event[0], event_size); //set a start_sec variable to be used across processes for consistent time
- if (read_time == -1) {
- fprintf(stderr, "PROBLEM READING FILE FOR TIME!\n");
+ //open events and get file pointers
+ char path_to_event[PATH_SIZE];
+ int event_fptrs[num_events];
+ for (int i = 0; i < num_events; ++i) {
+ snprintf(path_to_event, PATH_SIZE - 1, "/dev/input/event%lld", event_nums[i]);
+ event_fptrs[i] = open(path_to_event, O_RDWR);
+ if (event_fptrs[i] == -1) {
+ fprintf(stderr, "PROBLEM OPENING FILE: %s\n", path_to_event);
+ }
+ }
+ //make sure there was no error
+ int initial_read = read(event_fptrs[0], &event[0], event_size);
+ if (initial_read == -1) {
+ fprintf(stderr, "PROBLEM READING FILE!\n");
exit(-1);
}
+ //shared memory for all processes to get usec
unsigned long start_sec = event[0].time.tv_sec;
- //create shared memory to hold the value of the microseconds to be shared among all of the forked processes
unsigned long* shared_usec = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
//create the amount of processes appropriate to the number of events to print
- for (int i = 0; i < num_exceptions - 1; ++i) {
+ pid_t pids[num_events];
+ for (int i = 0; i < num_events; ++i) {
+ pids[i] = -1;
+ }
+ for (int i = 0; i < num_events - 1; ++i) {
pids[i] = fork();
if (pids[i] == 0) break;
}
//mark the parent
bool isParent = true;
- for (int i = 0; i < num_exceptions; ++i) {
+ for (int i = 0; i < num_events; ++i) {
if (pids[i] == 0) isParent &= false;
}
//find and run code just for the parent process (first event (a.k.a. index 0))
if (isParent) {
char buffer[BUFSIZE+1];
- int initial_read = read(controller_event_fptrs[pairs[0].event_fptr_index], &event[0], event_size);
+ int initial_read = read(event_fptrs[0], &event[0], event_size);
if (initial_read == -1) {
fprintf(stderr, "PROBLEM READING FILE!\n");
exit(-1);
}
- while (read(controller_event_fptrs[pairs[0].event_fptr_index], &event[0], event_size) != -1) {
+ int string_size = 0;
+ while (read(event_fptrs[0], &event[0], event_size) != -1) {
*shared_usec = event[0].time.tv_usec;
if (event[0].type == 0) continue;
-///*
- printf("%d %lu.%-6lu %d %3d %11d\n",
- pairs[0].event_user_num,
- event[0].time.tv_sec - start_sec,
- *shared_usec,
- event[0].type,
- event[0].code,
- event[0].value);
-//*/
-/*
- snprintf(buffer, BUFSIZE, "%d %lu.%-6lu %d %3d %11d\n",
- pairs[0].event_user_num,
+ string_size = snprintf(buffer, BUFSIZE, "%lld %lu.%-6lu %d %3d %11d\n",
+ event_nums[0],
event[0].time.tv_sec - start_sec,
event[0].time.tv_usec,
event[0].type,
event[0].code,
event[0].value);
- write(STDOUT_FILENO, buffer, sizeof(buffer));
-*/
+ write(STDOUT_FILENO, buffer, string_size);
}
fprintf(stderr, "DISCONNECTED\n");
}
//find the child process(es) and run the correct code for each (event #2 onwards) (a.k.a. index 1+))
- for (int i = 0; i < num_exceptions; ++i) {
+ for (int i = 0; i < num_events; ++i) {
if (pids[i] == 0) {
//put the rest of the code in here?
char buffer[BUFSIZE+1];
- int initial_read = read(controller_event_fptrs[pairs[i+1].event_fptr_index], &event[i+1], event_size);
+ int initial_read = read(event_fptrs[i+1], &event[i+1], event_size);
if (initial_read == -1) {
fprintf(stderr, "PROBLEM READING FILE!\n");
exit(-1);
}
- while (read(controller_event_fptrs[pairs[i+1].event_fptr_index], &event[i+1], event_size) != -1) {
+ int string_size = 0;
+ while (read(event_fptrs[i+1], &event[i+1], event_size) != -1) {
if (event[i+1].type == 0) continue;
-///*
- printf("%d %zu.%-6zu %d %3d %11d\n",
- pairs[i+1].event_user_num,
- event[i+1].time.tv_sec - start_sec,
- *shared_usec,
- //event[i+1].time.tv_usec,
- event[i+1].type,
- event[i+1].code,
- event[i+1].value);
-//*/
-/*
- snprintf(buffer, BUFSIZE, "%d %zu.%-6zu %d %3d %11d\n",
- pairs[i+1].event_user_num,
+ string_size = snprintf(buffer, BUFSIZE, "%lld %zu.%-6zu %d %3d %11d\n",
+ event_nums[i+1],
event[i+1].time.tv_sec - start_sec,
event[i+1].time.tv_usec,
event[i+1].type,
event[i+1].code,
event[i+1].value);
- write(STDOUT_FILENO, buffer, sizeof(buffer));
-*/
+ write(STDOUT_FILENO, buffer, string_size);
}
fprintf(stderr, "DISCONNECTED\n");
}
diff --git a/handle_devices.h b/handle_devices.h
index 372e883..2c7f40b 100644
--- a/handle_devices.h
+++ b/handle_devices.h
@@ -1,20 +1,10 @@
#ifndef HANDLE_DEVICES_H
#define HANDLE_DEVICES_H
-void open_wii(int* device_fptr_array, uint64_t* connected_controllers, int choice);
+void show_device_options(void);
-void open_ps4_bt(int* device_fptr_array, uint64_t* connected_controllers, int choice);
+void print_one_event(unsigned long long event_num);
-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, int choice);
-
-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[], ...);
-
-void print_one_event(int controller_event_fptrs[], int index, int event_number);
-
-void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ...);
+void print_multiple_events(int num_events, unsigned long long event_nums[]);
#endif
diff --git a/main.c b/main.c
index 0bf92f2..b90cc5b 100644
--- a/main.c
+++ b/main.c
@@ -1,273 +1,29 @@
-#include "global_defs.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
#include "handle_devices.h"
int main(int argc, char** argv)
{
- system("clear");
+ system("reset");
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");
+ if (argc < 2) {
+ show_device_options();
+ } else if (argc == 2) {
+ //open and print a single event
+ unsigned long long event_num;
+ char *end_ptr;
+ event_num = strtoull(argv[1], &end_ptr, 10);
+ print_one_event(event_num);
} else {
- 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);
- }
- }
+ //open and print multiple events
+ unsigned long long arg_event_nums[argc - 1];
+ char* end_ptr;
+ for(int i = 1; i < argc; ++i) {
+ arg_event_nums[i-1] = strtoull(argv[i], &end_ptr, 10);
+ }
+ print_multiple_events(argc - 1, arg_event_nums);
}
return 0;
}
diff --git a/student.c b/student.c
index 18f9591..281f8b2 100644
--- a/student.c
+++ b/student.c
@@ -2,7 +2,7 @@
#include "user_defs.h"
int main(void)
-{ FIX
+{
int num = -2, type = -2, code = -2, value = -2;
double time = -2;
diff --git a/test b/test
index d415cbe..c96598d 100644
--- a/test
+++ b/test
Binary files differ