summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xController_Program.numbersbin0 -> 295461 bytes
-rw-r--r--DOCUMENTATION30
-rw-r--r--Makefile8
-rw-r--r--README.md0
-rw-r--r--global_defs.h39
-rw-r--r--main.c316
6 files changed, 393 insertions, 0 deletions
diff --git a/Controller_Program.numbers b/Controller_Program.numbers
new file mode 100755
index 0000000..9a89a70
--- /dev/null
+++ b/Controller_Program.numbers
Binary files differ
diff --git a/DOCUMENTATION b/DOCUMENTATION
new file mode 100644
index 0000000..0574ee7
--- /dev/null
+++ b/DOCUMENTATION
@@ -0,0 +1,30 @@
+/*
+Sony PlayStation DualShock4 Controller
+ BT:
+ Bit(s): 128s, 64s, 32s
+ /proc/bus/input/devices Vendor=054c Product=09cc
+ "Wireless Controller Motion Sensors"
+ "Wireless Controller"
+ "Wireless Controller Touchpad"
+ WIRED:
+ Bit(s): 16s, 8s, 4s
+ /dev/input/by-id/usb-Sony_Interactive_Entertainment_Wireless_Controller-event-if03
+ /dev/input/by-id/usb-Sony_Interactive_Entertainment_Wireless_Controller-if03-event-joystick
+ /dev/input/by-id/usb-Sony_Interactive_Entertainment_Wireless_Controller-if03-event-mouse
+Valve Steam Controller
+ WIRED ONLY:
+ Bit(s): 2s
+ /dev/input/by-id/usb-Valve_Software_Wired_Controller-if02-event-joystick
+Microsoft 360 Controller
+ BT ONLY: (Dongle)
+ Bit(s): 1s
+ /dev/input/by-id/usb-©Microsoft_Xbox_360_Wireless_Receiver_for_Windows_E15D4C50-event-joystick
+Nintendo Wii Remote
+ BT ONLY:
+ Bit(s) 1024s, 512s, 256s
+ /proc/bus/input/devices Vendor=057e Product=0306
+ "Nintendo Wii Remote Accelerometer"
+ "Nintendo Wii Remote"
+ "Nintendo Wii Remote IR" //not currently supported, not sure how realistic this is
+*/
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..aa6c8ee
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+CC = gcc
+ALL_FLAGS = -g
+
+main: main.c
+ ${CC} ${ALL_FLAGS} main.c
+
+clean:
+ rm *\.o
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README.md
diff --git a/global_defs.h b/global_defs.h
new file mode 100644
index 0000000..17269c9
--- /dev/null
+++ b/global_defs.h
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <linux/input.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+//magic numbers
+#define NUM_EVENTS 12 //steam + xbox + ps4 * 6 + wii * 3 + mouse
+#define NUM_EVENTS_WII_PS4 3
+
+#define PS4_BT_TOUCH_BIT 32
+#define PS4_BT_GYRO_BIT 64
+#define PS4_BT_BUTTONS_BIT 128
+#define PS4_BT_ALL_BITS 224 // 128 + 64 + 32
+
+#define PS4_WIRED_TOUCH_BIT 4
+#define PS4_WIRED_GYRO_BIT 8
+#define PS4_WIRED_BUTTONS_BIT 16
+#define PS4_WIRED_ALL_BITS 28 // 16 + 8 + 4
+
+#define NINTENDO_GYRO_BIT 256
+#define NINTENDO_IR_BIT 512
+#define NINTENDO_BUTTONS_BIT 1024
+#define NINTENDO_ALL_BITS 1792 // 1024 + 512 + 256
+
+enum {
+ IR = 0, TOUCHPAD = 0, GYRO = 1, BUTTONS = 2
+};
+
+enum {
+ VALVE_STEAM = 0,
+ XBOX_360 = 1,
+ PS4_WIRED_GYRO = 2, PS4_WIRED_BUTTONS = 3, PS4_WIRED_TOUCH = 4,
+ PS4_BT_GYRO = 5, PS4_BT_BUTTONS = 6, PS4_BT_TOUCH = 7,
+ WII_GYRO = 8, WII_IR = 9, WII_BUTTONS = 10, MOUSE = 11
+};
+
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..9f9b7dd
--- /dev/null
+++ b/main.c
@@ -0,0 +1,316 @@
+#include "global_defs.h"
+
+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[NUM_EVENTS_WII_PS4] = { 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", &wii[GYRO], &wii[IR], &wii[BUTTONS]);
+ 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_PS4][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);
+ //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: ALL NINTENDO BT\n", NINTENDO_ALL_BITS);
+ }
+
+ //PS4 Bluetooth
+ int ps4[NUM_EVENTS_WII_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_WII_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);
+ }
+
+ //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");
+ }
+
+ //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");
+ }
+
+ //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);
+ }
+
+DUMB_USER:
+ printf("\n\nPress the number corresponding to the device above that you would like to use and then press ENTER.\n");
+
+ short choice;
+ int chosen_fd[3] = {-1};
+ scanf("%d", &choice);
+
+ struct input_event event1;
+ int ievt_size = sizeof(struct input_event);
+ size_t start_sec;
+
+ switch (choice) {
+ case 1: //valve steam controller //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[VALVE_STEAM];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == VALVE_STEAM) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case 2: //xbox 360 controller //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[XBOX_360];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == XBOX_360) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case PS4_WIRED_TOUCH_BIT: //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[PS4_WIRED_TOUCH];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == PS4_WIRED_TOUCH) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case PS4_WIRED_GYRO_BIT: //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[PS4_WIRED_GYRO];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == PS4_WIRED_GYRO) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case PS4_WIRED_BUTTONS_BIT: //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[PS4_WIRED_BUTTONS];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == PS4_WIRED_BUTTONS) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case PS4_WIRED_ALL_BITS: //HARD
+ {
+ struct input_event event2, event3;
+ chosen_fd[0] = controller_event_fptrs[PS4_WIRED_TOUCH];
+ chosen_fd[1] = controller_event_fptrs[PS4_WIRED_GYRO];
+ chosen_fd[2] = controller_event_fptrs[PS4_WIRED_BUTTONS];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == PS4_WIRED_TOUCH || i == PS4_WIRED_GYRO || i == PS4_WIRED_BUTTONS) continue;
+ close(controller_event_fptrs[i]);
+ }
+ break;
+ }
+ case PS4_BT_TOUCH_BIT: //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[PS4_BT_TOUCH];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == PS4_BT_TOUCH) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case PS4_BT_GYRO_BIT: //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[PS4_BT_GYRO];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == PS4_BT_GYRO) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case PS4_BT_BUTTONS_BIT: //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[PS4_BT_BUTTONS];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == PS4_BT_BUTTONS) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case PS4_BT_ALL_BITS: //HARD
+ {
+ struct input_event event2, event3;
+ chosen_fd[0] = controller_event_fptrs[PS4_BT_TOUCH];
+ chosen_fd[1] = controller_event_fptrs[PS4_BT_GYRO];
+ chosen_fd[2] = controller_event_fptrs[PS4_BT_BUTTONS];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == PS4_BT_TOUCH || i == PS4_BT_GYRO || i == PS4_BT_BUTTONS) continue;
+ close(controller_event_fptrs[i]);
+ }
+ break;
+ }
+ case NINTENDO_GYRO_BIT: //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[WII_GYRO];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == WII_GYRO) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case NINTENDO_IR_BIT: //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[WII_IR];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == WII_IR) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case NINTENDO_BUTTONS_BIT: //easy
+ {
+ chosen_fd[0] = controller_event_fptrs[WII_BUTTONS];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == WII_BUTTONS) continue;
+ close(controller_event_fptrs[i]);
+ }
+ read(chosen_fd[0], &event1, ievt_size);
+ start_sec = event1.time.tv_sec;
+ while (1) {
+ read(chosen_fd[0], &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);
+ }
+ break;
+ }
+ case NINTENDO_ALL_BITS: //HARD
+ {
+ struct input_event event2, event3;
+ chosen_fd[0] = controller_event_fptrs[WII_GYRO];
+ chosen_fd[1] = controller_event_fptrs[WII_IR];
+ chosen_fd[2] = controller_event_fptrs[WII_BUTTONS];
+ for (int i = 0; i < NUM_EVENTS; ++i) {
+ if (i == WII_GYRO || i == WII_IR || i == WII_BUTTONS) continue;
+ close(controller_event_fptrs[i]);
+ }
+ break;
+ }
+ default:
+ {
+ fprintf(stderr, "ERROR: Do not know how you made it here.\n");
+ exit(-1);
+ break;
+ }
+ }
+
+
+ return 0;
+}