summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c600
1 files changed, 398 insertions, 202 deletions
diff --git a/main.c b/main.c
index 01aecf3..01e393b 100644
--- a/main.c
+++ b/main.c
@@ -1,87 +1,33 @@
#include "global_defs.h"
+#include "handle_devices.h"
+
+void print_single_event(int event_index) {
+}
int main(void)
{
system("clear");
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
+
int controller_event_fptrs[NUM_EVENTS];
uint64_t connected_controllers = 0;
- //Determine if WII REMOTE is connected via bluetooth
- int wii[4] = { 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 | paste - -s", "r");
- fscanf(wii_pipe, "%2d %2d %2d %2d", &wii[GYRO], &wii[IR], &wii[BUTTONS], &wii[NUNCHUCK]);
- 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]);
- 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);
- controller_event_fptrs[WII_IR] = open(wii_events[IR], O_RDONLY);
- controller_event_fptrs[WII_BUTTONS] = open(wii_events[BUTTONS], O_RDONLY);
- if (wii[NUNCHUCK] != 0) { //NUNCHUCK ATTACHED
- snprintf(wii_events[NUNCHUCK], 25, "/dev/input/event%d", wii[NUNCHUCK]);
- controller_event_fptrs[WII_NUNCHUCK] = open(wii_events[NUNCHUCK], O_RDONLY);
- }
- //tell user and program that this device is available for use
- connected_controllers |= NINTENDO_ALL_BITS;
- 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 NUNCHUCK\n", NINTENDO_NUNCHUCK_BIT);
- printf("%4d: ALL NINTENDO BT\n", NINTENDO_ALL_BITS);
- }
- //PS4 Bluetooth
- 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]);
- 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);
- 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: ALL PS4 BT\n", PS4_BT_ALL_BITS);
- }
+ open_wii(controller_event_fptrs, &connected_controllers);
- //PS4 Wired
- 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("4 : PS4 WIRED TOUCH\n");
- printf("8 : PS4 WIRED GYRO\n");
- printf("16 : PS4 WIRED BUTTONS\n");
- printf("28 : ALL PS4 WIRED\n");
- }
+ open_ps4_bt(controller_event_fptrs, &connected_controllers);
- //VALVE_STEAM WIRED
- 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 |= 1;
- printf("1 : VALVE STEAM\n");
- }
+ open_ps4_wired(controller_event_fptrs, &connected_controllers);
+
+ open_steam(controller_event_fptrs, &connected_controllers);
+
+ open_xbox_360(controller_event_fptrs, &connected_controllers);
- //Xbox Bluetooth Dongle
- 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 |= 2;
- printf("2 : XBOX 360\n");
- }
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");
- exit(-1);
+ return(-1);
}
DUMB_USER:
@@ -90,227 +36,479 @@ DUMB_USER:
short choice;
scanf("%d", &choice);
- struct input_event event1;
+ 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 //easy
+ case 1: //valve steam controller
{
- printf("You chose: VALVE_STEAM\n");
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i != VALVE_STEAM) {
- close(controller_event_fptrs[i]);
- }
- }
- int ird = read(controller_event_fptrs[VALVE_STEAM], &event1, ievt_size);
- start_sec = event1.time.tv_sec;
- if (ird == -1) fprintf(stderr, "PROBLEM READING FILE\n");
- while (ird != -1) {
- int ird = read(controller_event_fptrs[VALVE_STEAM], &event1, ievt_size);
- if (ird == -1) {
- fprintf(stderr, "PROBLEM READING FILE\n");
- }
- printf("%zu.%-6zu %d %3d %6d\n",
- event1.time.tv_sec - start_sec,
- event1.time.tv_usec,
- event1.type,
- event1.code,
- event1.value);
- }
+ close_unneeded_files(1, controller_event_fptrs, VALVE_STEAM);
+ print_one_event(controller_event_fptrs, VALVE_STEAM, 1);
break;
}
- case 2: //xbox 360 controller //easy
+ case 2: //xbox 360 controller
{
- printf("You chose: XBOX_360\n");
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == XBOX_360) continue;
- close(controller_event_fptrs[i]);
+ close_unneeded_files(1, controller_event_fptrs, XBOX_360);
+ print_one_event(controller_event_fptrs, XBOX_360, 1);
+ break;
}
- read(controller_event_fptrs[XBOX_360], &event1, ievt_size);
- start_sec = event1.time.tv_sec;
- while (1) {
- read(controller_event_fptrs[XBOX_360], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ 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_TOUCH_BIT: //easy
+ case PS4_WIRED_BUTTONS_BIT:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == PS4_WIRED_TOUCH) continue;
- close(controller_event_fptrs[i]);
+ 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);
read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size);
+ read(controller_event_fptrs[PS4_WIRED_GYRO], &event2, ievt_size);
start_sec = event1.time.tv_sec;
- while (1) {
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ printf("1 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[PS4_WIRED_GYRO], &event2, ievt_size);
+ printf("2 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
}
break;
}
- case PS4_WIRED_GYRO_BIT: //easy
+ case PS4_WIRED_TOUCH_AND_BUTTONS:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == PS4_WIRED_GYRO) continue;
- close(controller_event_fptrs[i]);
+ close_unneeded_files(2, controller_event_fptrs, PS4_WIRED_TOUCH, PS4_WIRED_BUTTONS);
+ read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size);
+ read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event2, ievt_size);
+ start_sec = event1.time.tv_sec;
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
+ read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size);
+ printf("1 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event2, ievt_size);
+ printf("3 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
}
+ break;
+ }
+ case PS4_WIRED_GYRO_AND_BUTTONS:
+ {
+ close_unneeded_files(2, controller_event_fptrs, PS4_WIRED_GYRO, PS4_WIRED_BUTTONS);
read(controller_event_fptrs[PS4_WIRED_GYRO], &event1, ievt_size);
+ read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event2, ievt_size);
start_sec = event1.time.tv_sec;
- while (1) {
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
read(controller_event_fptrs[PS4_WIRED_GYRO], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ printf("2 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event2, ievt_size);
+ printf("3 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
}
break;
}
- case PS4_WIRED_BUTTONS_BIT: //easy
+ case PS4_WIRED_ALL_BITS:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == PS4_WIRED_BUTTONS) continue;
- close(controller_event_fptrs[i]);
- }
- read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event1, ievt_size);
+ close_unneeded_files(3, controller_event_fptrs, PS4_WIRED_TOUCH, PS4_WIRED_GYRO, PS4_WIRED_BUTTONS);
+ read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size);
+ read(controller_event_fptrs[PS4_WIRED_GYRO], &event2, ievt_size);
+ read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event3, ievt_size);
start_sec = event1.time.tv_sec;
- while (1) {
- read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
+ read(controller_event_fptrs[PS4_WIRED_TOUCH], &event1, ievt_size);
+ printf("1 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ pid = fork();
+ if (pid == 0) {
+ while (1) {
+ read(controller_event_fptrs[PS4_WIRED_GYRO], &event2, ievt_size);
+ printf("2 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[PS4_WIRED_BUTTONS], &event3, ievt_size);
+ printf("3 %zu.%-6zu %d %3d %9d\n",
+ event3.time.tv_sec - start_sec,
+ event3.time.tv_usec,
+ event3.type,
+ event3.code,
+ event3.value);
+ }
+ }
}
break;
}
- case PS4_WIRED_ALL_BITS: //HARD
+ case PS4_BT_TOUCH_BIT:
{
- struct input_event event2, event3;
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == PS4_WIRED_TOUCH || i == PS4_WIRED_GYRO || i == PS4_WIRED_BUTTONS) continue;
- close(controller_event_fptrs[i]);
+ 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_TOUCH_BIT: //easy
+ case PS4_BT_BUTTONS_BIT:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == PS4_BT_TOUCH) continue;
- close(controller_event_fptrs[i]);
+ 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);
read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size);
+ read(controller_event_fptrs[PS4_BT_GYRO], &event2, ievt_size);
start_sec = event1.time.tv_sec;
- while (1) {
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ printf("1 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[PS4_BT_GYRO], &event2, ievt_size);
+ printf("2 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
}
break;
}
- case PS4_BT_GYRO_BIT: //easy
+ case PS4_BT_TOUCH_AND_BUTTONS:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == PS4_BT_GYRO) continue;
- close(controller_event_fptrs[i]);
+ close_unneeded_files(2, controller_event_fptrs, PS4_BT_TOUCH, PS4_BT_BUTTONS);
+ read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size);
+ read(controller_event_fptrs[PS4_BT_BUTTONS], &event2, ievt_size);
+ start_sec = event1.time.tv_sec;
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
+ read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size);
+ printf("1 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[PS4_BT_BUTTONS], &event2, ievt_size);
+ printf("3 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
}
+ break;
+ }
+ case PS4_BT_GYRO_AND_BUTTONS:
+ {
+ close_unneeded_files(2, controller_event_fptrs, PS4_BT_GYRO, PS4_BT_BUTTONS);
read(controller_event_fptrs[PS4_BT_GYRO], &event1, ievt_size);
+ read(controller_event_fptrs[PS4_BT_BUTTONS], &event2, ievt_size);
start_sec = event1.time.tv_sec;
- while (1) {
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
read(controller_event_fptrs[PS4_BT_GYRO], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ printf("2 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[PS4_BT_BUTTONS], &event2, ievt_size);
+ printf("3 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
}
break;
}
- case PS4_BT_BUTTONS_BIT: //easy
+ case PS4_BT_ALL_BITS:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == PS4_BT_BUTTONS) continue;
- close(controller_event_fptrs[i]);
- }
- read(controller_event_fptrs[PS4_BT_BUTTONS], &event1, ievt_size);
+ close_unneeded_files(3, controller_event_fptrs, PS4_BT_TOUCH, PS4_BT_GYRO, PS4_BT_BUTTONS);
+ read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size);
+ read(controller_event_fptrs[PS4_BT_GYRO], &event2, ievt_size);
+ read(controller_event_fptrs[PS4_BT_BUTTONS], &event3, ievt_size);
start_sec = event1.time.tv_sec;
- while (1) {
- read(controller_event_fptrs[PS4_BT_BUTTONS], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
+ read(controller_event_fptrs[PS4_BT_TOUCH], &event1, ievt_size);
+ printf("1 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ pid = fork();
+ if (pid == 0) {
+ while (1) {
+ read(controller_event_fptrs[PS4_BT_GYRO], &event2, ievt_size);
+ printf("2 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[PS4_BT_BUTTONS], &event3, ievt_size);
+ printf("3 %zu.%-6zu %d %3d %9d\n",
+ event3.time.tv_sec - start_sec,
+ event3.time.tv_usec,
+ event3.type,
+ event3.code,
+ event3.value);
+ }
+ }
}
break;
}
- case PS4_BT_ALL_BITS: //HARD
+ case NINTENDO_GYRO_BIT:
{
- struct input_event event2, event3;
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == PS4_BT_TOUCH || i == PS4_BT_GYRO || i == PS4_BT_BUTTONS) continue;
- close(controller_event_fptrs[i]);
+ 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_GYRO_BIT: //easy
+ case NINTENDO_BUTTONS_BIT:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == WII_GYRO) continue;
- close(controller_event_fptrs[i]);
+ 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);
read(controller_event_fptrs[WII_GYRO], &event1, ievt_size);
+ read(controller_event_fptrs[WII_IR], &event2, ievt_size);
start_sec = event1.time.tv_sec;
- while (1) {
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
read(controller_event_fptrs[WII_GYRO], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ printf("1 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[WII_IR], &event2, ievt_size);
+ printf("2 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
}
break;
}
- case NINTENDO_IR_BIT: //easy
+ case NINTENDO_GYRO_AND_BUTTONS:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == WII_IR) continue;
- close(controller_event_fptrs[i]);
+ close_unneeded_files(2, controller_event_fptrs, WII_GYRO, WII_BUTTONS);
+ read(controller_event_fptrs[WII_GYRO], &event1, ievt_size);
+ read(controller_event_fptrs[WII_BUTTONS], &event2, ievt_size);
+ start_sec = event1.time.tv_sec;
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
+ read(controller_event_fptrs[WII_GYRO], &event1, ievt_size);
+ printf("1 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[WII_BUTTONS], &event2, ievt_size);
+ printf("3 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
}
- read(controller_event_fptrs[WII_IR], &event1, ievt_size);
+ break;
+ }
+ case NINTENDO_GYRO_AND_NUNCHUK:
+ {
+ close_unneeded_files(2, controller_event_fptrs, WII_GYRO, WII_NUNCHUK);
+ read(controller_event_fptrs[WII_GYRO], &event1, ievt_size);
+ read(controller_event_fptrs[WII_BUTTONS], &event2, ievt_size);
start_sec = event1.time.tv_sec;
- while (1) {
- read(controller_event_fptrs[WII_IR], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ int pid = fork();
+ if (pid == 0) {
+ while (1) {
+ read(controller_event_fptrs[WII_GYRO], &event1, ievt_size);
+ printf("1 %zu.%-6zu %d %3d %9d\n",
+ event1.time.tv_sec - start_sec,
+ event1.time.tv_usec,
+ event1.type,
+ event1.code,
+ event1.value);
+ }
+ } else {
+ while (1) {
+ read(controller_event_fptrs[WII_BUTTONS], &event2, ievt_size);
+ printf("3 %zu.%-6zu %d %3d %9d\n",
+ event2.time.tv_sec - start_sec,
+ event2.time.tv_usec,
+ event2.type,
+ event2.code,
+ event2.value);
+ }
}
break;
}
- case NINTENDO_BUTTONS_BIT: //easy
+ case NINTENDO_IR_AND_BUTTONS:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == WII_BUTTONS) continue;
- close(controller_event_fptrs[i]);
+ close_unneeded_files(2, controller_event_fptrs, WII_IR, WII_BUTTONS);
+ break;
}
- read(controller_event_fptrs[WII_BUTTONS], &event1, ievt_size);
- start_sec = event1.time.tv_sec;
- while (1) {
- read(controller_event_fptrs[WII_BUTTONS], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ case NINTENDO_IR_AND_NUNCHUK:
+ {
+ close_unneeded_files(2, controller_event_fptrs, WII_IR, WII_NUNCHUK);
+ break;
}
+ case NINTENDO_BUTTONS_AND_NUNCHUK:
+ {
+ close_unneeded_files(2, controller_event_fptrs, WII_BUTTONS, WII_NUNCHUK);
break;
}
- case NINTENDO_NUNCHUCK_BIT: //easy
+ case NINTENDO_GYRO_IR_AND_BUTTONS:
{
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == WII_NUNCHUCK) continue;
- close(controller_event_fptrs[i]);
+ close_unneeded_files(3, controller_event_fptrs, WII_GYRO, WII_IR, WII_BUTTONS);
+ break;
}
- read(controller_event_fptrs[WII_NUNCHUCK], &event1, ievt_size);
- start_sec = event1.time.tv_sec;
- while (1) {
- read(controller_event_fptrs[WII_NUNCHUCK], &event1, ievt_size);
- if (event1.type == 0) continue;
- printf("%zu.%-6zu %d %3d %6d\n", event1.time.tv_sec - start_sec, event1.time.tv_usec, event1.type, event1.code, event1.value);
+ case NINTENDO_GYRO_IR_AND_NUNCHUK:
+ {
+ close_unneeded_files(3, controller_event_fptrs, WII_GYRO, WII_IR, WII_NUNCHUK);
+ break;
}
+ case NINTENDO_GYRO_BUTTONS_AND_NUNCHUK:
+ {
+ close_unneeded_files(3, controller_event_fptrs, WII_GYRO, WII_BUTTONS, WII_NUNCHUK);
break;
}
- case NINTENDO_ALL_BITS: //HARD
+ case NINTENDO_IR_BUTTONS_AND_NUNCHUK:
{
- struct input_event event2, event3;
- for (int i = 0; i < NUM_EVENTS - 1; ++i) {
- if (i == WII_GYRO || i == WII_IR || i == WII_BUTTONS) continue;
- close(controller_event_fptrs[i]);
+ close_unneeded_files(3, controller_event_fptrs, WII_IR, WII_BUTTONS, WII_NUNCHUK);
+ break;
}
+ case NINTENDO_ALL_BITS:
+ {
+ close_unneeded_files(4, controller_event_fptrs, WII_GYRO, WII_IR, WII_BUTTONS, WII_NUNCHUK);
break;
}
default:
@@ -320,7 +518,5 @@ DUMB_USER:
break;
}
}
-
-
return 0;
}