2014-09-30 15:48:31 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 03:33:01 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2014-09-30 15:48:31 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
2015-07-10 07:15:55 +00:00
|
|
|
|
2016-12-01 21:16:06 +00:00
|
|
|
#include <compat/strl.h>
|
2016-03-20 13:53:54 +00:00
|
|
|
#include <lists/dir_list.h>
|
2015-07-10 04:12:35 +00:00
|
|
|
#include <file/file_path.h>
|
2015-12-26 06:54:17 +00:00
|
|
|
#include <string/stdstring.h>
|
2014-09-30 15:48:31 +00:00
|
|
|
|
2016-12-01 19:38:20 +00:00
|
|
|
#include "../input/input_config.h"
|
2015-07-10 07:15:55 +00:00
|
|
|
|
2016-02-07 12:25:55 +00:00
|
|
|
#include "../configuration.h"
|
2016-06-11 19:51:28 +00:00
|
|
|
#include "../file_path_special.h"
|
2016-05-21 11:31:41 +00:00
|
|
|
#include "../list_special.h"
|
2015-11-23 11:03:38 +00:00
|
|
|
#include "../verbosity.h"
|
2014-09-30 15:48:31 +00:00
|
|
|
|
2016-12-01 19:38:20 +00:00
|
|
|
#include "tasks_internal.h"
|
|
|
|
|
2016-12-01 21:36:38 +00:00
|
|
|
typedef struct autoconfig_disconnect
|
|
|
|
{
|
2016-12-16 11:20:31 +00:00
|
|
|
unsigned idx;
|
2016-12-01 21:36:38 +00:00
|
|
|
char msg[255];
|
|
|
|
} autoconfig_disconnect_t;
|
|
|
|
|
2015-12-04 01:57:47 +00:00
|
|
|
/* Adds an index for devices with the same name,
|
|
|
|
* so they can be identified in the GUI. */
|
2016-12-01 17:52:34 +00:00
|
|
|
static void input_autoconfigure_joypad_reindex_devices(void)
|
2015-11-25 03:30:51 +00:00
|
|
|
{
|
2015-11-25 18:27:33 +00:00
|
|
|
unsigned i;
|
2015-11-25 03:30:51 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-11-25 18:27:33 +00:00
|
|
|
|
2016-05-01 18:50:26 +00:00
|
|
|
for(i = 0; i < settings->input.max_users; i++)
|
2015-11-25 03:30:51 +00:00
|
|
|
settings->input.device_name_index[i]=0;
|
2015-11-25 18:27:33 +00:00
|
|
|
|
2016-05-01 18:50:26 +00:00
|
|
|
for(i = 0; i < settings->input.max_users; i++)
|
2015-11-25 03:30:51 +00:00
|
|
|
{
|
2015-11-25 18:27:33 +00:00
|
|
|
unsigned j;
|
2015-11-25 03:30:51 +00:00
|
|
|
const char *tmp = settings->input.device_names[i];
|
2015-11-25 18:27:33 +00:00
|
|
|
int k = 1;
|
2015-11-25 03:30:51 +00:00
|
|
|
|
2015-11-25 18:27:33 +00:00
|
|
|
for(j = 0; j < settings->input.max_users; j++)
|
2015-11-25 03:30:51 +00:00
|
|
|
{
|
2016-01-20 03:07:24 +00:00
|
|
|
if(string_is_equal(tmp, settings->input.device_names[j])
|
|
|
|
&& settings->input.device_name_index[i] == 0)
|
2015-11-25 03:30:51 +00:00
|
|
|
settings->input.device_name_index[j]=k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-30 15:48:31 +00:00
|
|
|
static void input_autoconfigure_joypad_conf(config_file_t *conf,
|
|
|
|
struct retro_keybind *binds)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2015-01-09 23:06:49 +00:00
|
|
|
|
2014-09-30 15:48:31 +00:00
|
|
|
for (i = 0; i < RARCH_BIND_LIST_END; i++)
|
|
|
|
{
|
|
|
|
input_config_parse_joy_button(conf, "input",
|
2015-11-28 01:13:27 +00:00
|
|
|
input_config_bind_map_get_base(i), &binds[i]);
|
2014-09-30 15:48:31 +00:00
|
|
|
input_config_parse_joy_axis(conf, "input",
|
2015-11-28 01:13:27 +00:00
|
|
|
input_config_bind_map_get_base(i), &binds[i]);
|
2014-09-30 15:48:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 17:52:34 +00:00
|
|
|
static int input_autoconfigure_joypad_try_from_conf(config_file_t *conf,
|
2015-07-10 03:46:28 +00:00
|
|
|
autoconfig_params_t *params)
|
2014-09-30 15:48:31 +00:00
|
|
|
{
|
2016-10-09 06:54:33 +00:00
|
|
|
char ident[256];
|
|
|
|
char input_driver[32];
|
2016-12-01 19:38:20 +00:00
|
|
|
int tmp_int = 0;
|
|
|
|
int input_vid = 0;
|
|
|
|
int input_pid = 0;
|
|
|
|
int score = 0;
|
2014-09-30 15:48:31 +00:00
|
|
|
|
2016-12-01 19:38:20 +00:00
|
|
|
ident[0] = input_driver[0] = '\0';
|
2016-10-09 06:54:33 +00:00
|
|
|
|
2014-09-30 15:48:31 +00:00
|
|
|
config_get_array(conf, "input_device", ident, sizeof(ident));
|
|
|
|
config_get_array(conf, "input_driver", input_driver, sizeof(input_driver));
|
2016-05-24 21:53:35 +00:00
|
|
|
|
|
|
|
if (config_get_int (conf, "input_vendor_id", &tmp_int))
|
|
|
|
input_vid = tmp_int;
|
|
|
|
|
|
|
|
if (config_get_int (conf, "input_product_id", &tmp_int))
|
|
|
|
input_pid = tmp_int;
|
2014-09-30 15:48:31 +00:00
|
|
|
|
2015-07-10 03:46:28 +00:00
|
|
|
/* Check for VID/PID */
|
2015-03-27 16:27:21 +00:00
|
|
|
if ( (params->vid == input_vid)
|
|
|
|
&& (params->pid == input_pid)
|
2016-12-01 17:38:11 +00:00
|
|
|
&& (params->vid != 0)
|
|
|
|
&& (params->pid != 0)
|
|
|
|
&& (input_vid != 0)
|
|
|
|
&& (input_pid != 0))
|
2015-07-10 03:46:28 +00:00
|
|
|
score += 3;
|
2015-07-03 02:48:06 +00:00
|
|
|
|
2015-04-30 21:28:07 +00:00
|
|
|
/* Check for name match */
|
2016-01-20 03:07:24 +00:00
|
|
|
if (string_is_equal(ident, params->name))
|
2015-07-10 03:46:28 +00:00
|
|
|
score += 2;
|
|
|
|
else
|
|
|
|
{
|
2016-12-01 21:38:19 +00:00
|
|
|
if ( !string_is_empty(ident)
|
|
|
|
&& string_is_equal(params->name, ident))
|
2015-07-10 03:46:28 +00:00
|
|
|
score += 1;
|
|
|
|
}
|
2016-09-12 16:39:46 +00:00
|
|
|
|
2015-07-10 03:46:28 +00:00
|
|
|
return score;
|
2015-03-27 16:27:21 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 13:06:43 +00:00
|
|
|
static void input_autoconfigure_joypad_add(config_file_t *conf,
|
2016-12-01 21:16:06 +00:00
|
|
|
autoconfig_params_t *params, retro_task_t *task)
|
2015-03-27 16:27:21 +00:00
|
|
|
{
|
2016-10-27 07:13:36 +00:00
|
|
|
char msg[128];
|
|
|
|
char display_name[128];
|
|
|
|
char device_type[128];
|
2016-10-09 06:54:33 +00:00
|
|
|
bool block_osd_spam = false;
|
2015-12-04 01:57:47 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-03-27 16:34:09 +00:00
|
|
|
|
2016-10-09 06:54:33 +00:00
|
|
|
msg[0] = display_name[0] = device_type[0] = '\0';
|
|
|
|
|
2016-02-05 13:06:43 +00:00
|
|
|
config_get_array(conf, "input_device_display_name",
|
|
|
|
display_name, sizeof(display_name));
|
|
|
|
config_get_array(conf, "input_device_type", device_type,
|
|
|
|
sizeof(device_type));
|
2015-07-12 18:45:17 +00:00
|
|
|
|
2015-03-27 16:27:21 +00:00
|
|
|
if (!settings)
|
|
|
|
return;
|
2015-08-01 04:40:30 +00:00
|
|
|
|
2015-10-12 19:02:07 +00:00
|
|
|
/* This will be the case if input driver is reinitialized.
|
|
|
|
* No reason to spam autoconfigure messages every time. */
|
|
|
|
block_osd_spam = settings->input.autoconfigured[params->idx]
|
2016-12-01 17:35:30 +00:00
|
|
|
&& !string_is_empty(params->name);
|
2015-10-12 19:02:07 +00:00
|
|
|
|
2015-03-27 15:57:58 +00:00
|
|
|
settings->input.autoconfigured[params->idx] = true;
|
2015-03-27 16:27:21 +00:00
|
|
|
input_autoconfigure_joypad_conf(conf,
|
|
|
|
settings->input.autoconf_binds[params->idx]);
|
2014-09-30 15:48:31 +00:00
|
|
|
|
2016-07-19 16:25:08 +00:00
|
|
|
if (string_is_equal(device_type, "remote"))
|
2015-08-01 04:09:25 +00:00
|
|
|
{
|
2016-12-01 17:36:50 +00:00
|
|
|
static bool remote_is_bound = false;
|
|
|
|
|
2016-10-22 02:57:46 +00:00
|
|
|
snprintf(msg, sizeof(msg), "%s configured.",
|
2016-01-20 03:07:24 +00:00
|
|
|
string_is_empty(display_name) ? params->name : display_name);
|
2015-08-31 13:26:37 +00:00
|
|
|
|
2015-08-01 05:07:28 +00:00
|
|
|
if(!remote_is_bound)
|
2016-12-29 05:50:18 +00:00
|
|
|
task_set_title(task, strdup(msg));
|
2015-08-01 04:09:25 +00:00
|
|
|
remote_is_bound = true;
|
|
|
|
}
|
2015-07-12 18:45:17 +00:00
|
|
|
else
|
2015-08-01 04:09:25 +00:00
|
|
|
{
|
2016-10-22 02:57:46 +00:00
|
|
|
snprintf(msg, sizeof(msg), "%s %s #%u.",
|
2016-01-20 03:07:24 +00:00
|
|
|
string_is_empty(display_name) ? params->name : display_name,
|
2016-10-22 02:57:46 +00:00
|
|
|
msg_hash_to_str(MSG_DEVICE_CONFIGURED_IN_PORT),
|
2016-01-20 03:07:24 +00:00
|
|
|
params->idx);
|
|
|
|
|
2015-08-01 05:07:28 +00:00
|
|
|
if (!block_osd_spam)
|
2016-12-29 05:50:18 +00:00
|
|
|
task_set_title(task, strdup(msg));
|
2015-08-01 04:09:25 +00:00
|
|
|
}
|
2016-12-16 11:33:56 +00:00
|
|
|
|
2016-12-16 13:02:11 +00:00
|
|
|
if (!string_is_empty(params->name))
|
|
|
|
strlcpy(settings->input.device_names[params->idx],
|
|
|
|
params->name,
|
|
|
|
sizeof(settings->input.device_names[params->idx]));
|
|
|
|
settings->input.pid[params->idx] = params->pid;
|
|
|
|
settings->input.vid[params->idx] = params->vid;
|
2016-12-16 11:33:56 +00:00
|
|
|
|
2016-12-01 17:52:34 +00:00
|
|
|
input_autoconfigure_joypad_reindex_devices();
|
2014-09-30 15:48:31 +00:00
|
|
|
}
|
|
|
|
|
2015-05-08 15:25:55 +00:00
|
|
|
static int input_autoconfigure_joypad_from_conf(
|
2016-12-01 21:16:06 +00:00
|
|
|
config_file_t *conf, autoconfig_params_t *params, retro_task_t *task)
|
2015-05-08 15:25:55 +00:00
|
|
|
{
|
2016-12-01 17:52:34 +00:00
|
|
|
int ret = input_autoconfigure_joypad_try_from_conf(conf,
|
2015-07-10 03:46:28 +00:00
|
|
|
params);
|
2015-05-08 15:25:55 +00:00
|
|
|
|
|
|
|
if (ret)
|
2016-12-01 21:16:06 +00:00
|
|
|
input_autoconfigure_joypad_add(conf, params, task);
|
2015-05-08 15:25:55 +00:00
|
|
|
|
|
|
|
config_file_free(conf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-27 17:05:43 +00:00
|
|
|
static bool input_autoconfigure_joypad_from_conf_dir(
|
2016-12-01 21:16:06 +00:00
|
|
|
autoconfig_params_t *params, retro_task_t *task)
|
2014-09-30 15:48:31 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
2016-10-09 06:54:33 +00:00
|
|
|
char path[PATH_MAX_LENGTH];
|
2015-09-29 15:35:28 +00:00
|
|
|
int ret = 0;
|
|
|
|
int index = -1;
|
|
|
|
int current_best = 0;
|
2015-07-10 07:06:00 +00:00
|
|
|
config_file_t *conf = NULL;
|
|
|
|
struct string_list *list = NULL;
|
2015-07-10 04:12:35 +00:00
|
|
|
|
2016-10-09 06:54:33 +00:00
|
|
|
path[0] = '\0';
|
|
|
|
|
2016-06-11 19:51:28 +00:00
|
|
|
fill_pathname_application_special(path, sizeof(path),
|
|
|
|
APPLICATION_SPECIAL_DIRECTORY_AUTOCONFIG);
|
2015-09-29 15:35:28 +00:00
|
|
|
|
2016-05-21 11:31:41 +00:00
|
|
|
list = dir_list_new_special(path, DIR_LIST_AUTOCONFIG, "cfg");
|
2014-09-30 15:48:31 +00:00
|
|
|
|
2015-07-10 04:51:39 +00:00
|
|
|
if (!list || !list->size)
|
2016-05-23 19:28:43 +00:00
|
|
|
{
|
2016-06-11 19:51:28 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2016-05-23 19:28:43 +00:00
|
|
|
if (list)
|
|
|
|
string_list_free(list);
|
2016-05-21 11:31:41 +00:00
|
|
|
list = dir_list_new_special(settings->directory.autoconfig,
|
|
|
|
DIR_LIST_AUTOCONFIG, "cfg");
|
2016-05-23 19:28:43 +00:00
|
|
|
}
|
2015-07-10 04:51:39 +00:00
|
|
|
|
|
|
|
if(!list)
|
2015-03-27 17:05:43 +00:00
|
|
|
return false;
|
2014-09-30 15:48:31 +00:00
|
|
|
|
2016-10-22 02:57:46 +00:00
|
|
|
RARCH_LOG("Autodetect: %d profiles found.\n", list->size);
|
2015-03-27 17:02:21 +00:00
|
|
|
|
2015-07-10 03:46:28 +00:00
|
|
|
for (i = 0; i < list->size; i++)
|
|
|
|
{
|
|
|
|
conf = config_file_new(list->elems[i].data);
|
2016-10-04 08:40:37 +00:00
|
|
|
|
|
|
|
if (conf)
|
2016-12-01 17:52:34 +00:00
|
|
|
ret = input_autoconfigure_joypad_try_from_conf(conf, params);
|
2016-09-12 16:39:46 +00:00
|
|
|
|
2015-07-11 03:36:28 +00:00
|
|
|
if(ret >= current_best)
|
2015-07-10 03:46:28 +00:00
|
|
|
{
|
2015-07-10 07:06:00 +00:00
|
|
|
index = i;
|
|
|
|
current_best = ret;
|
2015-07-10 03:46:28 +00:00
|
|
|
}
|
|
|
|
config_file_free(conf);
|
2014-09-30 15:48:31 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 04:38:31 +00:00
|
|
|
if(index >= 0 && current_best > 0)
|
2015-08-31 13:26:37 +00:00
|
|
|
{
|
2015-07-10 03:52:52 +00:00
|
|
|
conf = config_file_new(list->elems[index].data);
|
2015-11-15 21:28:57 +00:00
|
|
|
|
|
|
|
if (conf)
|
|
|
|
{
|
|
|
|
char conf_path[PATH_MAX_LENGTH];
|
|
|
|
|
2016-10-09 06:54:33 +00:00
|
|
|
conf_path[0] = '\0';
|
|
|
|
|
2015-11-15 21:28:57 +00:00
|
|
|
config_get_config_path(conf, conf_path, sizeof(conf_path));
|
|
|
|
|
|
|
|
RARCH_LOG("Autodetect: selected configuration: %s\n", conf_path);
|
2016-12-01 21:16:06 +00:00
|
|
|
input_autoconfigure_joypad_add(conf, params, task);
|
2015-11-15 21:28:57 +00:00
|
|
|
config_file_free(conf);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2015-07-10 03:52:52 +00:00
|
|
|
}
|
|
|
|
else
|
2015-07-10 07:06:00 +00:00
|
|
|
ret = 0;
|
2015-11-15 04:49:26 +00:00
|
|
|
|
2015-03-27 17:02:21 +00:00
|
|
|
string_list_free(list);
|
2015-03-27 17:05:43 +00:00
|
|
|
|
2015-07-10 07:06:00 +00:00
|
|
|
if (ret == 0)
|
|
|
|
return false;
|
|
|
|
return true;
|
2015-03-27 17:02:21 +00:00
|
|
|
}
|
2014-09-30 15:48:31 +00:00
|
|
|
|
2015-03-27 17:02:21 +00:00
|
|
|
static bool input_autoconfigure_joypad_from_conf_internal(
|
2016-12-01 21:16:06 +00:00
|
|
|
autoconfig_params_t *params, retro_task_t *task)
|
2015-03-27 17:02:21 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
2015-03-27 16:55:00 +00:00
|
|
|
/* Load internal autoconfig files */
|
2014-09-30 15:48:31 +00:00
|
|
|
for (i = 0; input_builtin_autoconfs[i]; i++)
|
|
|
|
{
|
2015-03-27 16:47:15 +00:00
|
|
|
config_file_t *conf = config_file_new_from_string(
|
|
|
|
input_builtin_autoconfs[i]);
|
2016-12-01 21:16:06 +00:00
|
|
|
if (conf && input_autoconfigure_joypad_from_conf(conf, params, task))
|
2016-10-04 05:39:41 +00:00
|
|
|
return true;
|
2014-09-30 15:48:31 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 05:39:41 +00:00
|
|
|
if (string_is_empty(settings->directory.autoconfig))
|
2015-03-27 17:02:21 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 23:06:49 +00:00
|
|
|
|
2016-12-01 21:16:06 +00:00
|
|
|
static void input_autoconfigure_connect_handler(retro_task_t *task)
|
2015-03-27 17:05:43 +00:00
|
|
|
{
|
2016-12-03 05:09:55 +00:00
|
|
|
autoconfig_params_t *params = (autoconfig_params_t*)task->state;
|
2016-12-01 21:16:06 +00:00
|
|
|
|
2016-12-29 04:49:24 +00:00
|
|
|
if (!params || string_is_empty(params->name))
|
2016-12-01 22:03:09 +00:00
|
|
|
{
|
2016-12-04 04:53:44 +00:00
|
|
|
free(params);
|
2016-12-29 05:50:18 +00:00
|
|
|
task_set_finished(task, true);
|
2016-12-01 21:16:06 +00:00
|
|
|
return;
|
2016-12-01 22:03:09 +00:00
|
|
|
}
|
2015-07-03 02:48:06 +00:00
|
|
|
|
2016-12-01 21:16:06 +00:00
|
|
|
if ( !input_autoconfigure_joypad_from_conf_dir(params, task)
|
|
|
|
&& !input_autoconfigure_joypad_from_conf_internal(params, task))
|
2016-12-01 19:41:41 +00:00
|
|
|
{
|
|
|
|
char msg[255];
|
2015-11-15 04:27:05 +00:00
|
|
|
|
2016-12-01 19:41:41 +00:00
|
|
|
msg[0] = '\0';
|
2016-05-06 02:50:02 +00:00
|
|
|
|
2016-12-01 19:41:41 +00:00
|
|
|
RARCH_LOG("Autodetect: no profiles found for %s (%d/%d).\n",
|
|
|
|
params->name, params->vid, params->pid);
|
|
|
|
|
|
|
|
snprintf(msg, sizeof(msg), "%s (%ld/%ld) %s.",
|
|
|
|
params->name, (long)params->vid, (long)params->pid,
|
|
|
|
msg_hash_to_str(MSG_DEVICE_NOT_CONFIGURED));
|
2016-12-29 05:50:18 +00:00
|
|
|
|
|
|
|
task_set_title(task, strdup(msg));
|
2016-12-01 19:41:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-04 04:50:50 +00:00
|
|
|
free(params);
|
2016-12-29 05:50:18 +00:00
|
|
|
|
|
|
|
task_set_finished(task, true);
|
2016-12-01 21:36:38 +00:00
|
|
|
}
|
2016-12-01 21:16:06 +00:00
|
|
|
|
2016-12-01 21:36:38 +00:00
|
|
|
static void input_autoconfigure_disconnect_handler(retro_task_t *task)
|
|
|
|
{
|
2016-12-03 05:09:55 +00:00
|
|
|
autoconfig_disconnect_t *params = (autoconfig_disconnect_t*)task->state;
|
2016-12-01 21:36:38 +00:00
|
|
|
|
2016-12-29 05:50:18 +00:00
|
|
|
task_set_title(task, strdup(params->msg));
|
|
|
|
|
|
|
|
task_set_finished(task, true);
|
2016-12-01 21:36:38 +00:00
|
|
|
|
|
|
|
RARCH_LOG("%s: %s\n", msg_hash_to_str(MSG_AUTODETECT), params->msg);
|
2016-12-04 04:50:50 +00:00
|
|
|
|
|
|
|
free(params);
|
2014-09-30 15:48:31 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 21:36:38 +00:00
|
|
|
bool input_autoconfigure_disconnect(unsigned i, const char *ident)
|
2015-06-03 16:55:04 +00:00
|
|
|
{
|
2016-10-27 07:32:07 +00:00
|
|
|
char msg[255];
|
2016-12-29 04:49:24 +00:00
|
|
|
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
|
|
|
|
autoconfig_disconnect_t *state = (autoconfig_disconnect_t*)calloc(1, sizeof(*state));
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-07-10 07:06:00 +00:00
|
|
|
|
2016-12-21 00:45:19 +00:00
|
|
|
if (!state || !task)
|
|
|
|
goto error;
|
|
|
|
|
2016-12-16 11:20:31 +00:00
|
|
|
msg[0] = '\0';
|
|
|
|
|
|
|
|
state->idx = i;
|
2016-10-09 06:54:33 +00:00
|
|
|
|
2016-10-22 02:57:46 +00:00
|
|
|
snprintf(msg, sizeof(msg), "%s #%u (%s).",
|
|
|
|
msg_hash_to_str(MSG_DEVICE_DISCONNECTED_FROM_PORT),
|
|
|
|
i, ident);
|
2016-12-01 21:36:38 +00:00
|
|
|
|
|
|
|
strlcpy(state->msg, msg, sizeof(state->msg));
|
|
|
|
|
2016-12-29 04:49:24 +00:00
|
|
|
settings->input.device_names[state->idx][0] = '\0';
|
|
|
|
|
2016-12-01 21:36:38 +00:00
|
|
|
task->state = state;
|
|
|
|
task->handler = input_autoconfigure_disconnect_handler;
|
|
|
|
|
|
|
|
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (state)
|
|
|
|
free(state);
|
|
|
|
if (task)
|
|
|
|
free(task);
|
|
|
|
|
|
|
|
return false;
|
2015-06-03 16:55:04 +00:00
|
|
|
}
|
2016-12-01 21:16:06 +00:00
|
|
|
|
|
|
|
bool input_autoconfigure_connect(autoconfig_params_t *params)
|
|
|
|
{
|
2016-12-29 04:49:24 +00:00
|
|
|
unsigned i;
|
2016-12-01 21:16:06 +00:00
|
|
|
retro_task_t *task = (retro_task_t*)calloc(1, sizeof(*task));
|
|
|
|
autoconfig_params_t *state = (autoconfig_params_t*)calloc(1, sizeof(*state));
|
2016-12-16 14:18:04 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2016-12-01 21:16:06 +00:00
|
|
|
|
2016-12-16 14:18:04 +00:00
|
|
|
if (!task || !state || !settings->input.autodetect_enable)
|
2016-12-01 21:16:06 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
strlcpy(state->name, params->name, sizeof(state->name));
|
|
|
|
|
2016-12-29 04:49:24 +00:00
|
|
|
for (i = 0; i < RARCH_BIND_LIST_END; i++)
|
|
|
|
{
|
|
|
|
settings->input.autoconf_binds[params->idx][i].joykey = NO_BTN;
|
|
|
|
settings->input.autoconf_binds[params->idx][i].joyaxis = AXIS_NONE;
|
|
|
|
settings->input.autoconf_binds[params->idx][i].joykey_label[0] = '\0';
|
|
|
|
settings->input.autoconf_binds[params->idx][i].joyaxis_label[0] = '\0';
|
|
|
|
}
|
|
|
|
settings->input.autoconfigured[params->idx] = false;
|
|
|
|
|
2016-12-01 21:17:36 +00:00
|
|
|
state->idx = params->idx;
|
|
|
|
state->vid = params->vid;
|
|
|
|
state->pid = params->pid;
|
|
|
|
|
|
|
|
task->state = state;
|
2016-12-01 21:16:06 +00:00
|
|
|
task->handler = input_autoconfigure_connect_handler;
|
|
|
|
|
|
|
|
task_queue_ctl(TASK_QUEUE_CTL_PUSH, task);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (state)
|
|
|
|
free(state);
|
|
|
|
if (task)
|
|
|
|
free(task);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|