linux-dist: Drop hardcoded mappings in favor of mapping files
This commit is contained in:
parent
5c01098cab
commit
528cd5a793
|
@ -75,7 +75,7 @@
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
int input_evdev_init(Controller* controller, const char* device, const char* mapping_fname = NULL)
|
int input_evdev_init(Controller* controller, const char* device, const char* custom_mapping_fname = NULL)
|
||||||
{
|
{
|
||||||
char name[256] = "Unknown";
|
char name[256] = "Unknown";
|
||||||
|
|
||||||
|
@ -97,53 +97,61 @@
|
||||||
|
|
||||||
controller->fd = fd;
|
controller->fd = fd;
|
||||||
|
|
||||||
if(mapping_fname != NULL)
|
const char* mapping_fname;
|
||||||
|
|
||||||
|
if(custom_mapping_fname != NULL)
|
||||||
{
|
{
|
||||||
if(loaded_mappings.count(string(mapping_fname)) == 0)
|
mapping_fname = custom_mapping_fname;
|
||||||
{
|
|
||||||
FILE* mapping_fd = fopen(mapping_fname, "r");
|
|
||||||
if(mapping_fd != NULL)
|
|
||||||
{
|
|
||||||
printf("evdev: reading custom mapping file: '%s'\n", mapping_fname);
|
|
||||||
loaded_mappings.insert(std::make_pair(string(mapping_fname), load_mapping(mapping_fd)));
|
|
||||||
fclose(mapping_fd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("evdev: unable to open custom mapping file '%s'\n", mapping_fname);
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
controller->mapping = &loaded_mappings[string(mapping_fname)];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if defined(TARGET_PANDORA)
|
#if defined(TARGET_PANDORA)
|
||||||
*controller.mapping = &controller_mapping_pandora;
|
mapping_fname = "controller_pandora.cfg";
|
||||||
#elif defined(TARGET_GCW0)
|
#elif defined(TARGET_GCW0)
|
||||||
*controller.mapping = &controller_mapping_gcwz;
|
mapping_fname = "controller_gcwz.cfg";
|
||||||
#else
|
#else
|
||||||
if (strcmp(name, "Microsoft X-Box 360 pad") == 0 ||
|
if (strcmp(name, "Microsoft X-Box 360 pad") == 0 ||
|
||||||
strcmp(name, "Xbox 360 Wireless Receiver") == 0 ||
|
strcmp(name, "Xbox 360 Wireless Receiver") == 0 ||
|
||||||
strcmp(name, "Xbox 360 Wireless Receiver (XBOX)") == 0)
|
strcmp(name, "Xbox 360 Wireless Receiver (XBOX)") == 0)
|
||||||
{
|
{
|
||||||
controller->mapping = &controller_mapping_xpad;
|
mapping_fname = "controller_xpad.cfg";
|
||||||
}
|
}
|
||||||
else if (strstr(name, "Xbox Gamepad (userspace driver)") != NULL)
|
else if (strstr(name, "Xbox Gamepad (userspace driver)") != NULL)
|
||||||
{
|
{
|
||||||
controller->mapping = &controller_mapping_xboxdrv;
|
mapping_fname = "controller_xboxdrv.cfg";
|
||||||
}
|
}
|
||||||
else if (strstr(name, "keyboard") != NULL ||
|
else if (strstr(name, "keyboard") != NULL ||
|
||||||
strstr(name, "Keyboard") != NULL)
|
strstr(name, "Keyboard") != NULL)
|
||||||
{
|
{
|
||||||
controller->mapping = &controller_mapping_keyboard;
|
mapping_fname = "keyboard.cfg";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
controller->mapping = &controller_mapping_generic;
|
mapping_fname = "controller_generic.cfg";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if(loaded_mappings.count(string(mapping_fname)) == 0)
|
||||||
|
{
|
||||||
|
size_t size_needed = snprintf(NULL, 0, EVDEV_MAPPING_PATH, mapping_fname) + 1;
|
||||||
|
char* mapping_path = (char*)malloc(size_needed);
|
||||||
|
sprintf(mapping_path, EVDEV_MAPPING_PATH, mapping_fname);
|
||||||
|
FILE* mapping_fd = fopen(GetPath(mapping_path).c_str(), "r");
|
||||||
|
free(mapping_path);
|
||||||
|
|
||||||
|
if(mapping_fd != NULL)
|
||||||
|
{
|
||||||
|
printf("evdev: reading mapping file: '%s'\n", mapping_fname);
|
||||||
|
loaded_mappings.insert(std::make_pair(string(mapping_fname), load_mapping(mapping_fd)));
|
||||||
|
fclose(mapping_fd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("evdev: unable to open mapping file '%s'\n", mapping_fname);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
controller->mapping = &loaded_mappings[string(mapping_fname)];
|
||||||
printf("evdev: Using '%s' mapping\n", controller->mapping->name);
|
printf("evdev: Using '%s' mapping\n", controller->mapping->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,191 +0,0 @@
|
||||||
#include "linux-dist/evdev_mappings.h"
|
|
||||||
|
|
||||||
#if defined(USE_EVDEV)
|
|
||||||
|
|
||||||
ControllerMapping controller_mapping_generic = {
|
|
||||||
"Generic Controller",
|
|
||||||
0x130, // BTN_A
|
|
||||||
0x131, // BTN_B
|
|
||||||
0x132, // BTN_C
|
|
||||||
0x13d, // BTN_THUMBL
|
|
||||||
0x133, // BTN_X
|
|
||||||
0x134, // BTN_Y
|
|
||||||
0x135, // BTN_Z
|
|
||||||
0x13b, // BTN_START
|
|
||||||
0x13a, // BTN_SELECT
|
|
||||||
0x220, // BTN_DPAD_LEFT
|
|
||||||
0x221, // BTN_DPAD_RIGHT
|
|
||||||
0x222, // BTN_DPAD_UP
|
|
||||||
0x223, // BTN_DPAD_DOWN
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
0x136, // BTN_TL
|
|
||||||
0x137, // BTN_TR
|
|
||||||
0x10, // ABS_HAT0X
|
|
||||||
0x11, // ABS_HAT0Y
|
|
||||||
0x12, // ABS_HAT1X
|
|
||||||
0x13, // ABS_HAT1Y
|
|
||||||
0x00, // ABS_X
|
|
||||||
0x01, // ABS_Y
|
|
||||||
0x02, // ABS_Z
|
|
||||||
0x05, // ABS_RZ
|
|
||||||
};
|
|
||||||
|
|
||||||
ControllerMapping controller_mapping_keyboard = {
|
|
||||||
"Generic Keyboard",
|
|
||||||
30, // KEY_A
|
|
||||||
48, // KEY_B
|
|
||||||
46, // KEY_C
|
|
||||||
32, // KEY_D
|
|
||||||
45, // KEY_X
|
|
||||||
21, // KEY_Y
|
|
||||||
44, // KEY_Z
|
|
||||||
28, // KEY_ENTER
|
|
||||||
1, // KEY_ESC
|
|
||||||
105, // KEY_LEFT
|
|
||||||
106, // KEY_RIGHT
|
|
||||||
103, // KEY_UP
|
|
||||||
108, // KEY_DOWN
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
29, // KEY_LEFTCTRL
|
|
||||||
97, // KEY_RIGHTCTRL
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1
|
|
||||||
};
|
|
||||||
|
|
||||||
ControllerMapping controller_mapping_xpad = {
|
|
||||||
"Xbox 360 Controller (xpad driver)",
|
|
||||||
0x130, // BTN_A
|
|
||||||
0x131, // BTN_B
|
|
||||||
0x136, // BTN_TL
|
|
||||||
0x137, // BTN_TR
|
|
||||||
0x133, // BTN_X
|
|
||||||
0x134, // BTN_Y
|
|
||||||
0x13d, // BTN_THUMBL
|
|
||||||
0x13b, // BTN_START
|
|
||||||
0x13a, // BTN_SELECT
|
|
||||||
0x2c0, // BTN_TRIGGER_HAPPY1
|
|
||||||
0x2c1, // BTN_TRIGGER_HAPPY2
|
|
||||||
0x2c2, // BTN_TRIGGER_HAPPY3
|
|
||||||
0x2c3, // BTN_TRIGGER_HAPPY4
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
0x10, // ABS_HAT0X
|
|
||||||
0x11, // ABS_HAT0Y
|
|
||||||
0x12, // ABS_HAT1X
|
|
||||||
0x13, // ABS_HAT1Y
|
|
||||||
0x00, // ABS_X
|
|
||||||
0x01, // ABS_Y
|
|
||||||
0x02, // ABS_Z
|
|
||||||
0x05, // ABS_RZ
|
|
||||||
};
|
|
||||||
|
|
||||||
ControllerMapping controller_mapping_xboxdrv = {
|
|
||||||
"Xbox 360 Controller (xboxdrv userspace driver)",
|
|
||||||
0x130, // BTN_A
|
|
||||||
0x131, // BTN_B
|
|
||||||
0x136, // BTN_TL
|
|
||||||
0x137, // BTN_TR
|
|
||||||
0x133, // BTN_X
|
|
||||||
0x134, // BTN_Y
|
|
||||||
0x13d, // BTN_THUMBL
|
|
||||||
0x13b, // BTN_START
|
|
||||||
0x13a, // BTN_SELECT
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
0x10, // ABS_HAT0X
|
|
||||||
0x11, // ABS_HAT0Y
|
|
||||||
0x12, // ABS_HAT1X
|
|
||||||
0x13, // ABS_HAT1Y
|
|
||||||
0x00, // ABS_X
|
|
||||||
0x01, // ABS_Y
|
|
||||||
0x0a, // ABS_BRAKE
|
|
||||||
0x09, // ABS_GAS
|
|
||||||
};
|
|
||||||
|
|
||||||
ControllerMapping controller_mapping_gcwz = {
|
|
||||||
"GCW Zero",
|
|
||||||
0x1D, // GCWZ_BTN_A
|
|
||||||
0x38, // GCWZ_BTN_B
|
|
||||||
0x0F, // GCWZ_BTN_L
|
|
||||||
0x0E, // GCWZ_BTN_R
|
|
||||||
0x2A, // GCWZ_BTN_X
|
|
||||||
0x39, // GCWZ_BTN_Y
|
|
||||||
-1,
|
|
||||||
0x1C, // GCWZ_BTN_START
|
|
||||||
0x01, // GCWZ_BTN_SELECT
|
|
||||||
0x69, // GCWZ_BTN_LEFT
|
|
||||||
0x6A, // GCWZ_BTN_RIGHT
|
|
||||||
0x67, // GCWZ_BTN_UP
|
|
||||||
0x6C, // GCWZ_BTN_DOWN
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1
|
|
||||||
};
|
|
||||||
|
|
||||||
ControllerMapping controller_mapping_pandora = {
|
|
||||||
"Pandora",
|
|
||||||
109, // KEY_PAGEDOWN
|
|
||||||
107, // KEY_END
|
|
||||||
57, // KEY_SPACE
|
|
||||||
-1,
|
|
||||||
102, // KEY_HOME
|
|
||||||
104, // KEY_PAGEUP
|
|
||||||
-1,
|
|
||||||
56, // KEY_LEFTALT
|
|
||||||
139, // KEY_MENU,
|
|
||||||
105, // KEY_LEFT
|
|
||||||
106, // KEY_RIGHT
|
|
||||||
103, // KEY_UP
|
|
||||||
108, // KEY_DOWN
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
54, // KEY_RIGHTSHIFT
|
|
||||||
97, // KEY_RIGHTCTRL
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -32,10 +32,3 @@ struct s_evdev_controller_mapping
|
||||||
const int Axis_Trigger_Right;
|
const int Axis_Trigger_Right;
|
||||||
};
|
};
|
||||||
typedef struct s_evdev_controller_mapping ControllerMapping;
|
typedef struct s_evdev_controller_mapping ControllerMapping;
|
||||||
|
|
||||||
extern ControllerMapping controller_mapping_generic;
|
|
||||||
extern ControllerMapping controller_mapping_keyboard;
|
|
||||||
extern ControllerMapping controller_mapping_xpad;
|
|
||||||
extern ControllerMapping controller_mapping_xboxdrv;
|
|
||||||
extern ControllerMapping controller_mapping_gcwz;
|
|
||||||
extern ControllerMapping controller_mapping_pandora;
|
|
||||||
|
|
|
@ -96,11 +96,9 @@ void SetupInput()
|
||||||
{
|
{
|
||||||
#if defined(USE_EVDEV)
|
#if defined(USE_EVDEV)
|
||||||
evdev_init_keycodes(); //FIXME: This sucks, but initializer lists for maps are only available with std=c++0x
|
evdev_init_keycodes(); //FIXME: This sucks, but initializer lists for maps are only available with std=c++0x
|
||||||
|
|
||||||
int evdev_device_id[4] = { -1, -1, -1, -1 };
|
int evdev_device_id[4] = { -1, -1, -1, -1 };
|
||||||
char* mapping = NULL;
|
|
||||||
size_t size_needed;
|
size_t size_needed;
|
||||||
int evdev_device_length, port, i;
|
|
||||||
int port, i;
|
int port, i;
|
||||||
|
|
||||||
char* evdev_device;
|
char* evdev_device;
|
||||||
|
@ -132,24 +130,14 @@ void SetupInput()
|
||||||
evdev_device = (char*)malloc(size_needed);
|
evdev_device = (char*)malloc(size_needed);
|
||||||
sprintf(evdev_device, EVDEV_DEVICE_STRING, evdev_device_id[port]);
|
sprintf(evdev_device, EVDEV_DEVICE_STRING, evdev_device_id[port]);
|
||||||
|
|
||||||
mapping = NULL;
|
|
||||||
|
|
||||||
size_needed = snprintf(NULL, 0, EVDEV_MAPPING_CONFIG_KEY, port+1) + 1;
|
size_needed = snprintf(NULL, 0, EVDEV_MAPPING_CONFIG_KEY, port+1) + 1;
|
||||||
evdev_config_key = (char*)malloc(size_needed);
|
evdev_config_key = (char*)malloc(size_needed);
|
||||||
sprintf(evdev_config_key, EVDEV_MAPPING_CONFIG_KEY, port+1);
|
sprintf(evdev_config_key, EVDEV_MAPPING_CONFIG_KEY, port+1);
|
||||||
if (cfgExists("input", evdev_config_key) == 2)
|
const char* mapping = (cfgExists("input", evdev_config_key) == 2 ? cfgLoadStr("input", evdev_config_key, "").c_str() : NULL);
|
||||||
{
|
|
||||||
string mapping_name = cfgLoadStr("input", evdev_config_key, "");
|
|
||||||
|
|
||||||
size_needed = snprintf(NULL, 0, EVDEV_MAPPING_PATH, mapping_name.c_str()) + 1;
|
|
||||||
char* evdev_mapping_fname = (char*)malloc(size_needed);
|
|
||||||
sprintf(evdev_mapping_fname, EVDEV_MAPPING_PATH, mapping_name.c_str());
|
|
||||||
mapping = (char*)GetPath(evdev_mapping_fname).c_str();
|
|
||||||
free(evdev_mapping_fname);
|
|
||||||
}
|
|
||||||
free(evdev_config_key);
|
free(evdev_config_key);
|
||||||
|
|
||||||
input_evdev_init(&controllers[port], evdev_device, mapping);
|
input_evdev_init(&controllers[port], evdev_device, mapping);
|
||||||
|
|
||||||
free(evdev_device);
|
free(evdev_device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue