1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
#include "global_defs.h"
#include "handle_devices.h"
int main(void)
{
system("clear");
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
int controller_event_fptrs[NUM_EVENTS];
uint64_t connected_controllers = 0;
open_wii(controller_event_fptrs, &connected_controllers);
open_ps4_bt(controller_event_fptrs, &connected_controllers);
open_ps4_wired(controller_event_fptrs, &connected_controllers);
open_steam(controller_event_fptrs, &connected_controllers);
open_xbox_360(controller_event_fptrs, &connected_controllers);
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");
return(-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;
scanf("%d", &choice);
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
{
close_unneeded_files(1, controller_event_fptrs, VALVE_STEAM);
print_one_event(controller_event_fptrs, VALVE_STEAM, 1);
break;
}
case 2: //xbox 360 controller
{
close_unneeded_files(1, controller_event_fptrs, XBOX_360);
print_one_event(controller_event_fptrs, XBOX_360, 1);
break;
}
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_BUTTONS_BIT:
{
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);
struct event_pairs first_event = {PS4_WIRED_TOUCH, 1},
second_event = {PS4_WIRED_GYRO, 2};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case PS4_WIRED_TOUCH_AND_BUTTONS:
{
close_unneeded_files(2, controller_event_fptrs, PS4_WIRED_TOUCH, PS4_WIRED_BUTTONS);
struct event_pairs first_event = {PS4_WIRED_TOUCH, 1},
second_event = {PS4_WIRED_BUTTONS, 3};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case PS4_WIRED_GYRO_AND_BUTTONS:
{
close_unneeded_files(2, controller_event_fptrs, PS4_WIRED_GYRO, PS4_WIRED_BUTTONS);
struct event_pairs first_event = {PS4_WIRED_GYRO, 2},
second_event = {PS4_WIRED_BUTTONS, 3};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case PS4_WIRED_ALL_BITS:
{
close_unneeded_files(3, controller_event_fptrs, PS4_WIRED_TOUCH, PS4_WIRED_GYRO, PS4_WIRED_BUTTONS);
struct event_pairs first_event = {PS4_WIRED_TOUCH, 1},
second_event = {PS4_WIRED_GYRO, 2},
third_event = {PS4_WIRED_BUTTONS, 3};
print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event);
break;
}
case PS4_BT_TOUCH_BIT:
{
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_BUTTONS_BIT:
{
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);
struct event_pairs first_event = {PS4_BT_TOUCH, 1},
second_event = {PS4_BT_GYRO, 2};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case PS4_BT_TOUCH_AND_BUTTONS:
{
close_unneeded_files(2, controller_event_fptrs, PS4_BT_TOUCH, PS4_BT_BUTTONS);
struct event_pairs first_event = {PS4_BT_TOUCH, 1},
second_event = {PS4_BT_BUTTONS, 3};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case PS4_BT_GYRO_AND_BUTTONS:
{
close_unneeded_files(2, controller_event_fptrs, PS4_BT_GYRO, PS4_BT_BUTTONS);
struct event_pairs first_event = {PS4_BT_GYRO, 2},
second_event = {PS4_BT_BUTTONS, 3};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case PS4_BT_ALL_BITS:
{
close_unneeded_files(3, controller_event_fptrs, PS4_BT_TOUCH, PS4_BT_GYRO, PS4_BT_BUTTONS);
struct event_pairs first_event = {PS4_BT_TOUCH, 1},
second_event = {PS4_BT_GYRO, 2},
third_event = {PS4_BT_BUTTONS, 3};
print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event);
break;
}
case NINTENDO_GYRO_BIT:
{
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_BUTTONS_BIT:
{
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);
struct event_pairs first_event = {WII_GYRO, 1},
second_event = {WII_IR, 2};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case NINTENDO_GYRO_AND_BUTTONS:
{
close_unneeded_files(2, controller_event_fptrs, WII_GYRO, WII_BUTTONS);
struct event_pairs first_event = {WII_GYRO, 1},
second_event = {WII_BUTTONS, 3};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case NINTENDO_GYRO_AND_NUNCHUK:
{
close_unneeded_files(2, controller_event_fptrs, WII_GYRO, WII_NUNCHUK);
struct event_pairs first_event = {WII_GYRO, 1},
second_event = {WII_NUNCHUK, 4};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case NINTENDO_IR_AND_BUTTONS:
{
close_unneeded_files(2, controller_event_fptrs, WII_IR, WII_BUTTONS);
struct event_pairs first_event = {WII_IR, 2},
second_event = {WII_BUTTONS, 3};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case NINTENDO_IR_AND_NUNCHUK:
{
close_unneeded_files(2, controller_event_fptrs, WII_IR, WII_NUNCHUK);
struct event_pairs first_event = {WII_IR, 2},
second_event = {WII_NUNCHUK, 4};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case NINTENDO_BUTTONS_AND_NUNCHUK:
{
close_unneeded_files(2, controller_event_fptrs, WII_BUTTONS, WII_NUNCHUK);
struct event_pairs first_event = {WII_BUTTONS, 3},
second_event = {WII_NUNCHUK, 4};
print_multiple_events(2, controller_event_fptrs, first_event, second_event);
break;
}
case NINTENDO_GYRO_IR_AND_BUTTONS:
{
close_unneeded_files(3, controller_event_fptrs, WII_GYRO, WII_IR, WII_BUTTONS);
struct event_pairs first_event = {WII_GYRO, 1},
second_event = {WII_IR, 2},
third_event = {WII_BUTTONS, 3};
print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event);
break;
}
case NINTENDO_GYRO_IR_AND_NUNCHUK:
{
close_unneeded_files(3, controller_event_fptrs, WII_GYRO, WII_IR, WII_NUNCHUK);
struct event_pairs first_event = {WII_GYRO, 1},
second_event = {WII_IR, 2},
third_event = {WII_NUNCHUK, 4};
print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event);
break;
}
case NINTENDO_GYRO_BUTTONS_AND_NUNCHUK:
{
close_unneeded_files(3, controller_event_fptrs, WII_GYRO, WII_BUTTONS, WII_NUNCHUK);
struct event_pairs first_event = {WII_GYRO, 1},
second_event = {WII_BUTTONS, 3},
third_event = {WII_NUNCHUK, 4};
print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event);
break;
}
case NINTENDO_IR_BUTTONS_AND_NUNCHUK:
{
close_unneeded_files(3, controller_event_fptrs, WII_IR, WII_BUTTONS, WII_NUNCHUK);
struct event_pairs first_event = {WII_IR, 2},
second_event = {WII_BUTTONS, 3},
third_event = {WII_NUNCHUK, 4};
print_multiple_events(3, controller_event_fptrs, first_event, second_event, third_event);
break;
}
case NINTENDO_ALL_BITS:
{
close_unneeded_files(4, controller_event_fptrs, WII_GYRO, WII_IR, WII_BUTTONS, WII_NUNCHUK);
struct event_pairs first_event = {WII_GYRO, 1},
second_event = {WII_IR, 2},
third_event = {WII_BUTTONS, 3},
fourth_event = {WII_NUNCHUK, 4};
print_multiple_events(4, controller_event_fptrs, first_event, second_event, third_event, fourth_event);
break;
}
default:
{
fprintf(stderr, "ERROR: You entered an invalid number!\n");
goto DUMB_USER;
break;
}
}
return 0;
}
|