Skip to content

Commit

Permalink
Expanded gamepad support
Browse files Browse the repository at this point in the history
  • Loading branch information
Vegz78 committed Jan 15, 2021
1 parent 6170936 commit fd8ac34
Show file tree
Hide file tree
Showing 12 changed files with 845 additions and 43 deletions.
Binary file modified McAirpos/launCharc/launCharc
Binary file not shown.
20 changes: 15 additions & 5 deletions McAirpos/launCharc/launCharc.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,21 @@ int main(int argc, char** argv) {

// Read game file argument to execute
char* game = "";
char* options = "";
if (argc == 2) {
game = argv[1];
} else if (argc > 2) {
printf("usage: launchArcade [/path/to/arcadegame.elf]\n");
} else if (argc == 3) {
game = argv[2];
options = argv[1];
} else if ((argc > 3) || (argc < 2)) {
printf("usage: launchArcade [nomap] [/path/to/arcadegame.elf]\n");
return 1;
}


if (!strcmp(options, "nomap")) {
printf("%s, %s\n", game, options);
} else {
// Determine the number of connected gamepads
printf("%s\n", game);
char eventPaths[100];
Expand All @@ -90,15 +97,16 @@ int main(int argc, char** argv) {
int numberOfEvents = 1 + atoi(getSystemOutput("ls /dev/input | sed 's/event//' | sort -n | tail -1"));
for (int i = 0; i < numberOfEvents; i++) {
if (numberOfPads < 2) {
char processCommand[100];
snprintf(processCommand, 100, "/home/pi/McAirpos/McAirpos/uinput-mapper/input-read -vp /dev/input/event%d | grep DPAD", i);
char processCommand[120];
snprintf(processCommand, 120, "/home/pi/McAirpos/McAirpos/uinput-mapper/input-read -vp /dev/input/event%d | grep -e BTN_SOUTH -e BTN_PINKIE", i);
char* event = getSystemOutput(processCommand);
if (strcmp(event, "")) {
printf("%s, Output:%s\n", processCommand, getSystemOutput(processCommand));
printf("%d Possible gamepads\n", numberOfEvents);
char iString[20];
sprintf(iString, "%d", i);
strcat(strcat(strcat(eventPaths, "/dev/input/event"), iString), " ");
strcat(strcat(strcat(eventPaths, "/dev/input/event"), iString), " ");
numberOfPads++;
}
}
Expand Down Expand Up @@ -138,8 +146,10 @@ int main(int argc, char** argv) {
}
snprintf(sedCommand, 100, "sed -i \"1s&.*&\"%s\"&\" /sd/arcade.cfg", defaultEvent);
system(sedCommand);
}
system("stty -ixon");


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

system("stty -ixon");
system("stty ixon");
system("clear");
}

Expand Down
227 changes: 212 additions & 15 deletions McAirpos/uinput-mapper/configs/arcade1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,154 @@


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

# Global variables
autoconf = 1 #Determines min and max for EV_ABS events automatically if 1, min and max must be set manually below if 0
deadzone = 0.25 #Deadzone in percentage before EV_ABS events react, used to dampen reactions to axis movements

# Variables for EV_ABS controller no. 1
invertUp = 0 #For inverting Y axis if 1, e.g. Nimbus SteelSeries controller
invertLeft = 0 #For inverting X axis if 1
max = 1 #Seed value = 1 for autoconf, if manual find properties using ./input-read -v -p /dev/input/eventX
min = 0 #Seed value = 0 for autoconf
mid = (min + max)/2

# Directional functions for EV_ABS controller no. 1
def digitizeUp(x):
global min, mid, max, deadzone
if x < min:
min = x
mid = (min + max)/2

if invertUp:
if x > (mid + (max - mid) * deadzone):
x = 1
else:
x = 0
else:
if x < (mid - (max - mid) * deadzone):
x = 1
else:
x = 0

return int(x)

def digitizeDown(x):
global min, mid, max, deadzone
if x > max:
max = x
mid = (min + max)/2

if invertUp:
if x < (mid - (max - mid) * deadzone):
x = 1
else:
x = 0
else:
if x > (mid + (max - mid) * deadzone):
x = 1
else:
x = 0

return int(x)

def digitizeLeft(x):
global min, mid, max, deadzone
if x < min:
min = x
mid = (min + max)/2

if invertLeft:
if x > (mid + (max - mid) * deadzone):
x = 1
else:
x = 0
else:
if x < (mid - (max - mid) * deadzone):
x = 1
else:
x = 0

return int(x)

def digitizeRight(x):
global min, mid, max, deadzone
if x > max:
max = x
mid = (min + max)/2

if invertLeft:
if x < (mid - (max - mid) * deadzone):
x = 1
else:
x = 0
else:
if x > (mid + (max - mid) * deadzone):
x = 1
else:
x = 0

return int(x)

# Variables for EV_ABS HAT controllers
hmin = -1
hmax = 1
hmid = 0

# Directional functions for EV_ABS HAT controllers
def hat0Pos(x):
global hmin, hmid, hmax

if x > hmid:
x = 1
else:
x = 0

return int(x)

def hat0Neg(x):
global hmin, hmid, hmax

if x < hmid:
x = 1
else:
x = 0

return int(x)


# Button mapping config
config = {
(0, EV_KEY): {
BTN_DPAD_LEFT: {
'type' : (0, EV_KEY),
'code' : KEY_A,
'value': None
},
BTN_DPAD_RIGHT: {
BTN_DPAD_UP: {
'type' : (0, EV_KEY),
'code' : KEY_D,
'code' : 17,
'value' : None
},
BTN_DPAD_UP: {
BTN_DPAD_DOWN: {
'type' : (0, EV_KEY),
'code' : KEY_W,
'code' : 31,
'value' : None
},
BTN_DPAD_DOWN: {
BTN_DPAD_LEFT: {
'type' : (0, EV_KEY),
'code' : KEY_S,
'code' : 30,
'value' : None
},
BTN_DPAD_RIGHT: {
'type' : (0, EV_KEY),
'code' : 32,
'value' : None
},
BTN_SOUTH: {
'type' : (0, EV_KEY),
'code' : 29,
'value' : None
},
BTN_X: {
BTN_B: {
'type' : (0, EV_KEY),
'code' : 42,
'value' : None
Expand All @@ -52,9 +168,90 @@
'type' : (0, EV_KEY),
'code' : 60,
'value' : None
}
},
},
(0, EV_ABS): {
ABS_X: {
'type' : (0, EV_KEY),
'code' : 30,
'value' : digitizeLeft
},
ABS_Y: {
'type' : (0, EV_KEY),
'code' : 17,
'value' : digitizeUp
},
ABS_HAT0X: {
'type' : (0, EV_KEY),
'code' : 32,
'value' : hat0Pos
},
ABS_HAT0Y: {
'type' : (0, EV_KEY),
'code' : 31,
'value' : hat0Pos
}
},
(1, EV_KEY): {
BTN_THUMB: {
'type' : (0, EV_KEY),
'code' : 29,
'value' : None
},
BTN_THUMB2: {
'type' : (0, EV_KEY),
'code' : 42,
'value' : None
},
BTN_BASE4: {
'type' : (0, EV_KEY),
'code' : 1,
'value' : None
},
BTN_BASE3: {
'type' : (0, EV_KEY),
'code' : 59,
'value' : None
},
KEY_HOMEPAGE: {
'type' : (0, EV_KEY),
'code' : 60,
'value' : None
}
},
(1, EV_ABS): {
ABS_X: {
'type' : (0, EV_KEY),
'code' : 32,
'value' : digitizeRight
},
ABS_Y: {
'type' : (0, EV_KEY),
'code' : 31,
'value' : digitizeDown
},
ABS_Z: {
'type' : (0, EV_KEY),
'code' : 1,
'value' : hat0Pos
},
ABS_RZ: {
'type' : (0, EV_KEY),
'code' : 59,
'value' : hat0Pos
},
ABS_HAT0X: {
'type' : (0, EV_KEY),
'code' : 30,
'value' : hat0Neg
},
ABS_HAT0Y: {
'type' : (0, EV_KEY),
'code' : 17,
'value' : hat0Neg
}
},
(2, EV_KEY): {
KEY_A: {
'type' : (0, EV_KEY),
'code' : 105,
Expand Down
Loading

0 comments on commit fd8ac34

Please sign in to comment.