Skip to content

Commit fd8ac34

Browse files
author
Vegz78
committed
Expanded gamepad support
1 parent 6170936 commit fd8ac34

File tree

12 files changed

+845
-43
lines changed

12 files changed

+845
-43
lines changed

McAirpos/launCharc/launCharc

460 Bytes
Binary file not shown.

McAirpos/launCharc/launCharc.c

+15-5
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,21 @@ int main(int argc, char** argv) {
7474

7575
// Read game file argument to execute
7676
char* game = "";
77+
char* options = "";
7778
if (argc == 2) {
7879
game = argv[1];
79-
} else if (argc > 2) {
80-
printf("usage: launchArcade [/path/to/arcadegame.elf]\n");
80+
} else if (argc == 3) {
81+
game = argv[2];
82+
options = argv[1];
83+
} else if ((argc > 3) || (argc < 2)) {
84+
printf("usage: launchArcade [nomap] [/path/to/arcadegame.elf]\n");
8185
return 1;
8286
}
8387

8488

89+
if (!strcmp(options, "nomap")) {
90+
printf("%s, %s\n", game, options);
91+
} else {
8592
// Determine the number of connected gamepads
8693
printf("%s\n", game);
8794
char eventPaths[100];
@@ -90,15 +97,16 @@ int main(int argc, char** argv) {
9097
int numberOfEvents = 1 + atoi(getSystemOutput("ls /dev/input | sed 's/event//' | sort -n | tail -1"));
9198
for (int i = 0; i < numberOfEvents; i++) {
9299
if (numberOfPads < 2) {
93-
char processCommand[100];
94-
snprintf(processCommand, 100, "/home/pi/McAirpos/McAirpos/uinput-mapper/input-read -vp /dev/input/event%d | grep DPAD", i);
100+
char processCommand[120];
101+
snprintf(processCommand, 120, "/home/pi/McAirpos/McAirpos/uinput-mapper/input-read -vp /dev/input/event%d | grep -e BTN_SOUTH -e BTN_PINKIE", i);
95102
char* event = getSystemOutput(processCommand);
96103
if (strcmp(event, "")) {
97104
printf("%s, Output:%s\n", processCommand, getSystemOutput(processCommand));
98105
printf("%d Possible gamepads\n", numberOfEvents);
99106
char iString[20];
100107
sprintf(iString, "%d", i);
101108
strcat(strcat(strcat(eventPaths, "/dev/input/event"), iString), " ");
109+
strcat(strcat(strcat(eventPaths, "/dev/input/event"), iString), " ");
102110
numberOfPads++;
103111
}
104112
}
@@ -138,8 +146,10 @@ int main(int argc, char** argv) {
138146
}
139147
snprintf(sedCommand, 100, "sed -i \"1s&.*&\"%s\"&\" /sd/arcade.cfg", defaultEvent);
140148
system(sedCommand);
149+
}
141150
system("stty -ixon");
142151

152+
143153
// Fork game execution on launch, so that it is executed
144154
// the same way it's done in-game on reset and finish
145155
if (!fork()) {
@@ -214,7 +224,7 @@ int main(int argc, char** argv) {
214224
perror("warn: ioctl KBSKBMODE failed");
215225
}
216226

217-
system("stty -ixon");
227+
system("stty ixon");
218228
system("clear");
219229
}
220230

McAirpos/uinput-mapper/configs/arcade1.py

+212-15
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,154 @@
22

33

44
"""
5-
Configuration for a simple Microsoft SideWinter Game Pad Pro USB version 1.0
6-
... as ABS input pointer device
5+
Configuration for many EV_ABS(axis) and EV_KEY(digital buttons) directional controllers
6+
... as EV_KEY MakeCode Arcade keyboard device
77
"""
88

9+
# Global variables
10+
autoconf = 1 #Determines min and max for EV_ABS events automatically if 1, min and max must be set manually below if 0
11+
deadzone = 0.25 #Deadzone in percentage before EV_ABS events react, used to dampen reactions to axis movements
12+
13+
# Variables for EV_ABS controller no. 1
14+
invertUp = 0 #For inverting Y axis if 1, e.g. Nimbus SteelSeries controller
15+
invertLeft = 0 #For inverting X axis if 1
16+
max = 1 #Seed value = 1 for autoconf, if manual find properties using ./input-read -v -p /dev/input/eventX
17+
min = 0 #Seed value = 0 for autoconf
18+
mid = (min + max)/2
19+
20+
# Directional functions for EV_ABS controller no. 1
21+
def digitizeUp(x):
22+
global min, mid, max, deadzone
23+
if x < min:
24+
min = x
25+
mid = (min + max)/2
26+
27+
if invertUp:
28+
if x > (mid + (max - mid) * deadzone):
29+
x = 1
30+
else:
31+
x = 0
32+
else:
33+
if x < (mid - (max - mid) * deadzone):
34+
x = 1
35+
else:
36+
x = 0
37+
38+
return int(x)
39+
40+
def digitizeDown(x):
41+
global min, mid, max, deadzone
42+
if x > max:
43+
max = x
44+
mid = (min + max)/2
45+
46+
if invertUp:
47+
if x < (mid - (max - mid) * deadzone):
48+
x = 1
49+
else:
50+
x = 0
51+
else:
52+
if x > (mid + (max - mid) * deadzone):
53+
x = 1
54+
else:
55+
x = 0
56+
57+
return int(x)
58+
59+
def digitizeLeft(x):
60+
global min, mid, max, deadzone
61+
if x < min:
62+
min = x
63+
mid = (min + max)/2
64+
65+
if invertLeft:
66+
if x > (mid + (max - mid) * deadzone):
67+
x = 1
68+
else:
69+
x = 0
70+
else:
71+
if x < (mid - (max - mid) * deadzone):
72+
x = 1
73+
else:
74+
x = 0
75+
76+
return int(x)
77+
78+
def digitizeRight(x):
79+
global min, mid, max, deadzone
80+
if x > max:
81+
max = x
82+
mid = (min + max)/2
83+
84+
if invertLeft:
85+
if x < (mid - (max - mid) * deadzone):
86+
x = 1
87+
else:
88+
x = 0
89+
else:
90+
if x > (mid + (max - mid) * deadzone):
91+
x = 1
92+
else:
93+
x = 0
94+
95+
return int(x)
96+
97+
# Variables for EV_ABS HAT controllers
98+
hmin = -1
99+
hmax = 1
100+
hmid = 0
101+
102+
# Directional functions for EV_ABS HAT controllers
103+
def hat0Pos(x):
104+
global hmin, hmid, hmax
105+
106+
if x > hmid:
107+
x = 1
108+
else:
109+
x = 0
110+
111+
return int(x)
112+
113+
def hat0Neg(x):
114+
global hmin, hmid, hmax
115+
116+
if x < hmid:
117+
x = 1
118+
else:
119+
x = 0
120+
121+
return int(x)
122+
123+
124+
# Button mapping config
9125
config = {
10126
(0, EV_KEY): {
11-
BTN_DPAD_LEFT: {
12-
'type' : (0, EV_KEY),
13-
'code' : KEY_A,
14-
'value': None
15-
},
16-
BTN_DPAD_RIGHT: {
127+
BTN_DPAD_UP: {
17128
'type' : (0, EV_KEY),
18-
'code' : KEY_D,
129+
'code' : 17,
19130
'value' : None
20131
},
21-
BTN_DPAD_UP: {
132+
BTN_DPAD_DOWN: {
22133
'type' : (0, EV_KEY),
23-
'code' : KEY_W,
134+
'code' : 31,
24135
'value' : None
25136
},
26-
BTN_DPAD_DOWN: {
137+
BTN_DPAD_LEFT: {
27138
'type' : (0, EV_KEY),
28-
'code' : KEY_S,
139+
'code' : 30,
140+
'value' : None
141+
},
142+
BTN_DPAD_RIGHT: {
143+
'type' : (0, EV_KEY),
144+
'code' : 32,
29145
'value' : None
30146
},
31147
BTN_SOUTH: {
32148
'type' : (0, EV_KEY),
33149
'code' : 29,
34150
'value' : None
35151
},
36-
BTN_X: {
152+
BTN_B: {
37153
'type' : (0, EV_KEY),
38154
'code' : 42,
39155
'value' : None
@@ -52,9 +168,90 @@
52168
'type' : (0, EV_KEY),
53169
'code' : 60,
54170
'value' : None
55-
}
171+
},
56172
},
173+
(0, EV_ABS): {
174+
ABS_X: {
175+
'type' : (0, EV_KEY),
176+
'code' : 30,
177+
'value' : digitizeLeft
178+
},
179+
ABS_Y: {
180+
'type' : (0, EV_KEY),
181+
'code' : 17,
182+
'value' : digitizeUp
183+
},
184+
ABS_HAT0X: {
185+
'type' : (0, EV_KEY),
186+
'code' : 32,
187+
'value' : hat0Pos
188+
},
189+
ABS_HAT0Y: {
190+
'type' : (0, EV_KEY),
191+
'code' : 31,
192+
'value' : hat0Pos
193+
}
194+
},
57195
(1, EV_KEY): {
196+
BTN_THUMB: {
197+
'type' : (0, EV_KEY),
198+
'code' : 29,
199+
'value' : None
200+
},
201+
BTN_THUMB2: {
202+
'type' : (0, EV_KEY),
203+
'code' : 42,
204+
'value' : None
205+
},
206+
BTN_BASE4: {
207+
'type' : (0, EV_KEY),
208+
'code' : 1,
209+
'value' : None
210+
},
211+
BTN_BASE3: {
212+
'type' : (0, EV_KEY),
213+
'code' : 59,
214+
'value' : None
215+
},
216+
KEY_HOMEPAGE: {
217+
'type' : (0, EV_KEY),
218+
'code' : 60,
219+
'value' : None
220+
}
221+
},
222+
(1, EV_ABS): {
223+
ABS_X: {
224+
'type' : (0, EV_KEY),
225+
'code' : 32,
226+
'value' : digitizeRight
227+
},
228+
ABS_Y: {
229+
'type' : (0, EV_KEY),
230+
'code' : 31,
231+
'value' : digitizeDown
232+
},
233+
ABS_Z: {
234+
'type' : (0, EV_KEY),
235+
'code' : 1,
236+
'value' : hat0Pos
237+
},
238+
ABS_RZ: {
239+
'type' : (0, EV_KEY),
240+
'code' : 59,
241+
'value' : hat0Pos
242+
},
243+
ABS_HAT0X: {
244+
'type' : (0, EV_KEY),
245+
'code' : 30,
246+
'value' : hat0Neg
247+
},
248+
ABS_HAT0Y: {
249+
'type' : (0, EV_KEY),
250+
'code' : 17,
251+
'value' : hat0Neg
252+
}
253+
},
254+
(2, EV_KEY): {
58255
KEY_A: {
59256
'type' : (0, EV_KEY),
60257
'code' : 105,

0 commit comments

Comments
 (0)