diff options
-rw-r--r-- | .DS_Store | bin | 6148 -> 6148 bytes | |||
-rw-r--r-- | devout | bin | 45952 -> 45640 bytes | |||
-rw-r--r-- | handle_devices.c | 32 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | student.c | 3 | ||||
-rw-r--r-- | test | bin | 27728 -> 27712 bytes | |||
-rw-r--r-- | user_defs.h | 2 |
7 files changed, 18 insertions, 22 deletions
Binary files differBinary files differ diff --git a/handle_devices.c b/handle_devices.c index 4e84a3b..dd154aa 100644 --- a/handle_devices.c +++ b/handle_devices.c @@ -7,7 +7,7 @@ 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 }; + 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\" | \ @@ -20,10 +20,10 @@ void open_wii(int* controller_event_fptrs, uint64_t* connected_controllers, int //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]); - snprintf(wii_events[IR], 25, "/dev/input/event%d", wii[IR]); - snprintf(wii_events[BUTTONS], 25, "/dev/input/event%d", wii[BUTTONS]); 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; @@ -62,10 +62,10 @@ void open_ps4_bt(int* controller_event_fptrs, uint64_t* connected_controllers, i 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]); - snprintf(ps4_events[GYRO], 25, "/dev/input/event%d", ps4[GYRO]); - snprintf(ps4_events[BUTTONS], 25, "/dev/input/event%d", ps4[BUTTONS]); 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) { @@ -87,10 +87,10 @@ void open_ps4_wired(int* controller_event_fptrs, uint64_t* connected_controllers 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]); - snprintf(ps4_events[GYRO], 25, "/dev/input/event%d", ps4[GYRO]); - snprintf(ps4_events[BUTTONS], 25, "/dev/input/event%d", ps4[BUTTONS]); 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) { @@ -236,7 +236,7 @@ void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ... while (read(controller_event_fptrs[pairs[0].event_fptr_index], &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, @@ -244,8 +244,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 %lu.%-6lu %d %3d %11d\n", pairs[0].event_user_num, event[0].time.tv_sec - start_sec, @@ -254,15 +254,13 @@ 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"); } //find the child process(es) and run the correct code for each (event #2 onwards) (a.k.a. index 1+)) - //sleep(1); find a way to make sure the time is consistent...shared memory using mmap(NULL, PAGESIZE, PROT_READ | PROT_WRITE); for time? ??? for (int i = 0; i < num_exceptions; ++i) { if (pids[i] == 0) { - //printf("Im child #%d.\n", i + 1); //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); @@ -272,7 +270,7 @@ void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ... } while (read(controller_event_fptrs[pairs[i+1].event_fptr_index], &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, @@ -281,8 +279,8 @@ void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ... 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, event[i+1].time.tv_sec - start_sec, @@ -291,7 +289,7 @@ void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ... event[i+1].code, event[i+1].value); write(STDOUT_FILENO, buffer, sizeof(buffer)); -//*/ +*/ } fprintf(stderr, "DISCONNECTED\n"); } @@ -27,10 +27,7 @@ int main(int argc, char** argv) 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 { switch (choice) { case STEAM_BIT: @@ -2,8 +2,7 @@ #include "user_defs.h" int main(void) -{ - char buffer[100]; fgets(buffer, 99, stdin); //mandatory to fix controller programs input stream, not needed if they use fgets and sscanf instead of scanf +{ FIX int num = -2, type = -2, code = -2, value = -2; double time = -2; Binary files differdiff --git a/user_defs.h b/user_defs.h index 7630c16..8c2c6e9 100644 --- a/user_defs.h +++ b/user_defs.h @@ -1,6 +1,8 @@ #ifndef USER_DEFS_H #define USER_DEFS_H +#define FIX char buffer[100]; fgets(buffer, 99, stdin); //needed to fix a problem I cannot figure out with the standard input + //Linux Device Event Types #define EV_KEY 1 #define EV_ABS 3 |