summaryrefslogtreecommitdiff
path: root/handle_devices.c
diff options
context:
space:
mode:
authorClay Smith <claysmith158@gmail.com>2023-02-05 13:50:51 -0600
committerClay Smith <claysmith158@gmail.com>2023-02-05 13:50:51 -0600
commita8003ca6d7c1a48ad30aa8205d352031b21e7996 (patch)
tree06904f2f4e0f98417f16226fce35c6e51550ffd4 /handle_devices.c
parentf54d199eb6e20fb38248d73cf83926360b6a57d2 (diff)
Now working with scanf properly on my end. Run the program without arguments to get devices connected, run with the number to run that device
Diffstat (limited to 'handle_devices.c')
-rw-r--r--handle_devices.c90
1 files changed, 51 insertions, 39 deletions
diff --git a/handle_devices.c b/handle_devices.c
index df3e9f3..f32b85e 100644
--- a/handle_devices.c
+++ b/handle_devices.c
@@ -4,7 +4,7 @@
#include "global_defs.h"
#include <stdbool.h>
-void open_wii(int* controller_event_fptrs, uint64_t* connected_controllers) {
+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 };
FILE* wii_pipe = popen("cat /proc/bus/input/devices | \
@@ -26,31 +26,35 @@ void open_wii(int* controller_event_fptrs, uint64_t* connected_controllers) {
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;
- 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 GYRO AND IR\n", NINTENDO_GYRO_AND_IR);
- printf("%4d: NINTENDO WII GYRO AND BUTTONS\n", NINTENDO_GYRO_AND_BUTTONS);
- printf("%4d: NINTENDO WII IR AND BUTTONS\n", NINTENDO_IR_AND_BUTTONS);
- printf("%4d: NINTENDO WII GYRO AND IR AND BUTTONS\n", 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);
- printf("%4d: NINTENDO WII NUNCHUK\n", NINTENDO_NUNCHUK_BIT);
- printf("%4d: NINTENDO WII GYRO AND NUNCHUK\n", NINTENDO_GYRO_AND_NUNCHUK);
- printf("%4d: NINTENDO WII IR AND NUNCHUK\n", NINTENDO_IR_AND_NUNCHUK);
- printf("%4d: NINTENDO WII BUTTONS AND NUNCHUK\n", NINTENDO_BUTTONS_AND_NUNCHUK);
- printf("%4d: NINTENDO WII GYRO AND IR AND NUNCHUK\n", NINTENDO_GYRO_IR_AND_NUNCHUK);
- printf("%4d: NINTENDO WII GYRO AND BUTTONS AND NUNCHUK\n", NINTENDO_GYRO_BUTTONS_AND_NUNCHUK);
- printf("%4d: NINTENDO WII IR AND BUTTONS AND NUNCHUK\n", NINTENDO_IR_BUTTONS_AND_NUNCHUK);
- printf("%4d: ALL NINTENDO BT\n", NINTENDO_ALL_BITS);
+ 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) {
+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]);
@@ -63,46 +67,54 @@ void open_ps4_bt(int* controller_event_fptrs, uint64_t* connected_controllers) {
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: PS4 BT TOUCH AND GYRO \n", PS4_BT_TOUCH_AND_GYRO);
- printf("%4d: PS4 BT TOUCH AND BUTTONS\n", PS4_BT_TOUCH_AND_BUTTONS);
- printf("%4d: PS4 BT GYRO AND BUTTONS\n", PS4_BT_GYRO_AND_BUTTONS);
- printf("%4d: ALL PS4 BT\n", 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) {
+void open_ps4_wired(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
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("%4d: PS4 WIRED TOUCH\n", PS4_WIRED_TOUCH_BIT);
- printf("%4d: PS4 WIRED GYRO\n", PS4_WIRED_GYRO_BIT);
- printf("%4d: PS4 WIRED BUTTONS\n", PS4_WIRED_BUTTONS_BIT);
- printf("%4d: PS4 WIRED TOUCH AND GYRO \n", PS4_WIRED_TOUCH_AND_GYRO);
- printf("%4d: PS4 WIRED TOUCH AND BUTTONS\n", PS4_WIRED_TOUCH_AND_BUTTONS);
- printf("%4d: PS4 WIRED GYRO AND BUTTONS\n", PS4_WIRED_GYRO_AND_BUTTONS);
- printf("%4d: ALL PS4 WIRED\n", 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) {
+void open_steam(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
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 |= (uint64_t) 1;
- printf("%4d: VALVE STEAM\n", 1);
+ if (choice) {
+ fprintf(stderr, "%4d: VALVE STEAM\n", 1);
+ }
}
}
-void open_xbox_360(int* controller_event_fptrs, uint64_t* connected_controllers) {
+void open_xbox_360(int* controller_event_fptrs, uint64_t* connected_controllers, int choice) {
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 |= (uint64_t) 2;
- printf("%4d: XBOX 360\n", 2);
+ if (choice) {
+ fprintf(stderr, "%4d: XBOX 360\n", 2);
+ }
}
}
@@ -188,7 +200,7 @@ void print_multiple_events(int num_exceptions, int controller_event_fptrs[], ...
size_t start_sec = event[0].time.tv_sec;
while (read(controller_event_fptrs[pairs[0].event_fptr_index], &event[0], event_size) != -1) {
if (event[0].type == 0) continue;
-
+/*
printf("%d %zu.%-6zu %d %3d %11d\n",
pairs[0].event_user_num,
event[0].time.tv_sec - start_sec,
@@ -196,8 +208,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 %zu.%-6zu %d %3d %11d\n",
pairs[0].event_user_num,
event[0].time.tv_sec - start_sec,
@@ -206,7 +218,7 @@ 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");
}