comparison controller_info.c @ 2220:dd9d43c67986

Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
author Michael Pavone <pavone@retrodev.com>
date Fri, 02 Sep 2022 22:53:41 -0700
parents 58774a77f2e0
children 7df357522c49
comparison
equal deleted inserted replaced
2219:ff700f50541c 2220:dd9d43c67986
16 } heuristic; 16 } heuristic;
17 17
18 static heuristic heuristics[] = { 18 static heuristic heuristics[] = {
19 //TODO: Add more heuristic rules 19 //TODO: Add more heuristic rules
20 {"DualShock 4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}}, 20 {"DualShock 4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}},
21 {"PS5", {.type = TYPE_PSX, .subtype = SUBTYPE_PS5}},
21 {"PS4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}}, 22 {"PS4", {.type = TYPE_PSX, .subtype = SUBTYPE_PS4}},
22 {"PS3", {.type = TYPE_PSX, .subtype = SUBTYPE_PS3}}, 23 {"PS3", {.type = TYPE_PSX, .subtype = SUBTYPE_PS3}},
23 {"X360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}}, 24 {"X360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}},
24 {"Xbox 360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}}, 25 {"Xbox 360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}},
25 {"X-box 360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}}, 26 {"X-box 360", {.type = TYPE_XBOX, .subtype = SUBTYPE_X360}},
37 static const char *subtype_names[] = { 38 static const char *subtype_names[] = {
38 "unknown", 39 "unknown",
39 "xbox", 40 "xbox",
40 "xbox 360", 41 "xbox 360",
41 "xbone", 42 "xbone",
43 "xbox elite",
42 "ps2", 44 "ps2",
43 "ps3", 45 "ps3",
44 "ps4", 46 "ps4",
47 "ps5",
45 "wiiu", 48 "wiiu",
46 "switch", 49 "switch",
47 "genesis", 50 "genesis",
48 "saturn" 51 "saturn"
49 }; 52 };
50 static const char *subtype_human_names[] = { 53 static const char *subtype_human_names[] = {
51 "unknown", 54 "unknown",
52 "Xbos", 55 "Xbos",
53 "Xbox 360", 56 "Xbox 360",
54 "Xbox One", 57 "Xbox One/Series",
58 "Xbox Elite",
55 "PS2", 59 "PS2",
56 "PS3", 60 "PS3",
57 "PS4", 61 "PS4",
62 "PS5",
58 "Wii-U", 63 "Wii-U",
59 "Switch", 64 "Switch",
60 "Genesis", 65 "Genesis",
61 "Saturn" 66 "Saturn"
62 }; 67 };
270 if (info->type == TYPE_UNKNOWN || info->type == TYPE_GENERIC_MAPPING || info->subtype ==SUBTYPE_X360) { 275 if (info->type == TYPE_UNKNOWN || info->type == TYPE_GENERIC_MAPPING || info->subtype ==SUBTYPE_X360) {
271 return labels_360; 276 return labels_360;
272 } else if (info->type == TYPE_NINTENDO) { 277 } else if (info->type == TYPE_NINTENDO) {
273 return labels_nintendo; 278 return labels_nintendo;
274 } else if (info->type == TYPE_PSX) { 279 } else if (info->type == TYPE_PSX) {
275 if (info->subtype == SUBTYPE_PS4) { 280 if (info->subtype >= SUBTYPE_PS4) {
276 return labels_ps4; 281 return labels_ps4;
277 } else { 282 } else {
278 return labels_ps3; 283 return labels_ps3;
279 } 284 }
280 } else if (info->type == TYPE_XBOX) { 285 } else if (info->type == TYPE_XBOX) {
281 if (info->subtype == SUBTYPE_XBONE) { 286 if (info->subtype >= SUBTYPE_XBONE) {
282 return labels_xbone; 287 return labels_xbone;
283 } else { 288 } else {
284 return labels_xbox; 289 return labels_xbox;
285 } 290 }
286 } else { 291 } else {
299 } 304 }
300 305
301 const char *get_button_label(controller_info *info, int button) 306 const char *get_button_label(controller_info *info, int button)
302 { 307 {
303 #ifndef USE_FBDEV 308 #ifndef USE_FBDEV
309 #if SDL_VERSION_ATLEAST(2,0,12)
310 if (info->subtype == SUBTYPE_XBOX_ELITE && button >= SDL_CONTROLLER_BUTTON_PADDLE1 && button <= SDL_CONTROLLER_BUTTON_PADDLE4) {
311 static char const * names[] = {"Paddle 1", "Paddle 2", "Paddle 3", "Paddle 4"};
312 return names[button - SDL_CONTROLLER_BUTTON_PADDLE1];
313 }
314 if (button == SDL_CONTROLLER_BUTTON_TOUCHPAD && (info->subtype == SUBTYPE_PS4 || info->subtype == SUBTYPE_PS5)) {
315 return "Touchpad";
316 }
317 if (button == SDL_CONTROLLER_BUTTON_MISC1) {
318 switch (info->subtype)
319 {
320 case SUBTYPE_XBONE:
321 case SUBTYPE_XBOX_ELITE:
322 return "Share";
323 case SUBTYPE_PS5:
324 return "Microphone";
325 case SUBTYPE_SWITCH:
326 return "Capture";
327 }
328 }
329 #endif
304 if (button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { 330 if (button >= SDL_CONTROLLER_BUTTON_DPAD_UP) {
305 static char const * dirs[] = {"Up", "Down", "Left", "Right"}; 331 if (button <= SDL_CONTROLLER_BUTTON_DPAD_RIGHT) {
306 return dirs[button - SDL_CONTROLLER_BUTTON_DPAD_UP]; 332 static char const * dirs[] = {"Up", "Down", "Left", "Right"};
333 return dirs[button - SDL_CONTROLLER_BUTTON_DPAD_UP];
334 }
335 return NULL;
307 } 336 }
308 #endif 337 #endif
309 return label_source(info)[button]; 338 return label_source(info)[button];
310 } 339 }
311 340