From 399cc0d8e0aee083feae04d00ace10b3c5fea56f Mon Sep 17 00:00:00 2001 From: pamapa Date: Fri, 8 May 2015 16:57:54 +0200 Subject: [PATCH 1/2] Make autoconfig more explicit: - add pid and vid to autoconfig file if avaiable --- tools/retroarch-joyconfig.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tools/retroarch-joyconfig.c b/tools/retroarch-joyconfig.c index c939f204fb..67ac1f016e 100644 --- a/tools/retroarch-joyconfig.c +++ b/tools/retroarch-joyconfig.c @@ -46,6 +46,8 @@ static char *g_out_path = NULL; static char *g_auto_path = NULL; static char *g_driver = NULL; static unsigned g_meta_level = 0; +static int g_input_vid = 0; +static int g_input_pid = 0; bool rarch_main_verbosity(void) { @@ -141,10 +143,19 @@ static void get_binds(config_file_t *conf, config_file_t *auto_conf, const char *joypad_name = input_joypad_name(driver, joypad); fprintf(stderr, "Using joypad: %s\n", joypad_name ? joypad_name : "Unknown"); - if (joypad_name && auto_conf) + if (auto_conf) { - config_set_string(auto_conf, "input_device", joypad_name); - config_set_string(auto_conf, "input_driver", driver->ident); + if (joypad_name) + { + config_set_string(auto_conf, "input_device", joypad_name); + config_set_string(auto_conf, "input_driver", driver->ident); + } + + if (g_input_vid != 0 && g_input_pid != 0) + { + config_set_int(auto_conf, "input_vendor_id", g_input_vid); + config_set_int(auto_conf, "input_product_id", g_input_pid); + } } int16_t initial_axes[MAX_AXES] = {0}; @@ -450,7 +461,8 @@ static void parse_input(int argc, char *argv[]) void input_config_autoconfigure_joypad(autoconfig_params_t *params) { - (void)params; + g_input_vid = params->vid; + g_input_pid = params->pid; } // Need SDL_main on OSX. From ff286a957931d1ea6110c2aabddfafdfc1777b91 Mon Sep 17 00:00:00 2001 From: pamapa Date: Fri, 8 May 2015 17:01:07 +0200 Subject: [PATCH 2/2] make sure the best configuration file wins, if there is more than one, because the name is not unique. We look as long as we have a perfect match, if not the latest config file which matches the name will win --- input/input_autodetect.c | 76 +++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/input/input_autodetect.c b/input/input_autodetect.c index d19300b865..4d805c4f06 100644 --- a/input/input_autodetect.c +++ b/input/input_autodetect.c @@ -137,31 +137,12 @@ static void input_autoconfigure_joypad_add( RARCH_LOG("%s\n", msg); } -static int input_autoconfigure_joypad_from_conf( - config_file_t *conf, autoconfig_params_t *params) -{ - int ret = 0; - uint32_t match = 0; - - if (!conf) - return false; - - ret = input_try_autoconfigure_joypad_from_conf(conf, - params, &match); - - if (ret) - input_autoconfigure_joypad_add(conf, params); - - config_file_free(conf); - - return ret; -} - static bool input_autoconfigure_joypad_from_conf_dir( autoconfig_params_t *params) { size_t i; int ret = 0; + config_file_t *best_conf = NULL; settings_t *settings = config_get_ptr(); struct string_list *list = settings ? dir_list_new( settings->input.autoconfig_dir, "cfg", false) : NULL; @@ -172,16 +153,34 @@ static bool input_autoconfigure_joypad_from_conf_dir( for (i = 0; i < list->size; i++) { config_file_t *conf = config_file_new(list->elems[i].data); - ret = input_autoconfigure_joypad_from_conf(conf, params); - - if (ret == 1) - break; + unsigned match = 0; + ret = input_try_autoconfigure_joypad_from_conf(conf, params, &match); + if (ret) + { + if (best_conf) config_file_free(best_conf); + best_conf = conf; + if (BIT32_GET(match, AUTODETECT_MATCH_VID) && BIT32_GET(match, AUTODETECT_MATCH_PID)) + { + /* prefect match, no need to look any further */ + break; + } + } + else + { + config_file_free(conf); + } + } + if (best_conf) + { + input_autoconfigure_joypad_add(best_conf, params); + config_file_free(best_conf); + ret = 1; } string_list_free(list); - return ret !=0 ? true : false; + return ret != 0 ? true : false; } #if defined(HAVE_BUILTIN_AUTOCONFIG) @@ -190,16 +189,37 @@ static bool input_autoconfigure_joypad_from_conf_internal( { size_t i; settings_t *settings = config_get_ptr(); - bool ret = false; + int ret = 0; + config_file_t *best_conf = NULL; /* Load internal autoconfig files */ for (i = 0; input_builtin_autoconfs[i]; i++) { config_file_t *conf = config_file_new_from_string( input_builtin_autoconfs[i]); + unsigned match = 0; + ret = input_try_autoconfigure_joypad_from_conf(conf, params, &match); + if (ret) + { + if (best_conf) config_file_free(best_conf); + best_conf = conf; + if (BIT32_GET(match, AUTODETECT_MATCH_VID) && BIT32_GET(match, AUTODETECT_MATCH_PID)) + { + /* prefect match, no need to look any further */ + break; + } + } + else + { + config_file_free(best_conf); + } + } - if ((ret = input_autoconfigure_joypad_from_conf(conf, params))) - break; + if (best_conf != NULL) + { + input_autoconfigure_joypad_add(best_conf, params); + config_file_free(best_conf); + ret = 1; } if (ret || !*settings->input.autoconfig_dir)