summaryrefslogtreecommitdiff
path: root/handle_devices.c
diff options
context:
space:
mode:
authorClay Smith <claysmith158@gmail.com>2023-02-15 06:41:54 -0600
committerClay Smith <claysmith158@gmail.com>2023-02-15 06:41:54 -0600
commit02d4b7d68534284f42bb69dcc0efadd0eb4f1ae1 (patch)
tree730b925df7d4eb375b0e3beee056e34bc038d75e /handle_devices.c
parent4760458bad9546cc2329cee45a844e4e450ccd5d (diff)
Demo time
Diffstat (limited to 'handle_devices.c')
-rw-r--r--handle_devices.c32
1 files changed, 15 insertions, 17 deletions
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");
}