input: Controller unique mapping (preliminary)

Add ini option `unique_mapping` which makes controller mappings unique to the physical port the controller is connected to.
Calculates a uint32_t unique_hash for each device during enumeration.

Co-authored-by: Martin Donlon <github-martin@donlons.com>
This commit is contained in:
Alexey Melnikov
2023-05-21 02:14:27 +08:00
committed by GitHub
parent 9307e54f1d
commit 0ebf137532
5 changed files with 36 additions and 3 deletions

View File

@@ -30,6 +30,7 @@
#include "support.h"
#include "profiling.h"
#include "gamecontroller_db.h"
#include "str_util.h"
#define NUMDEV 30
#define NUMPLAYERS 6
@@ -1189,6 +1190,7 @@ typedef struct
char mac[64];
int bind;
uint32_t unique_hash;
char devname[32];
char id[80];
char name[128];
@@ -1440,15 +1442,23 @@ int get_map_cancel()
static char *get_map_name(int dev, int def)
{
static char name[128];
if (def || is_menu()) sprintf(name, "input_%s%s_v3.map", input[dev].idstr, input[dev].mod ? "_m" : "");
else sprintf(name, "%s_input_%s%s_v3.map", user_io_get_core_name(), input[dev].idstr, input[dev].mod ? "_m" : "");
char id[32];
if (cfg.unique_mapping) sprintfz(id, "%08x", input[dev].unique_hash);
else strcpyz(id, input[dev].idstr);
if (def || is_menu()) sprintf(name, "input_%s%s_v3.map", id, input[dev].mod ? "_m" : "");
else sprintf(name, "%s_input_%s%s_v3.map", user_io_get_core_name(), id, input[dev].mod ? "_m" : "");
return name;
}
static char *get_kbdmap_name(int dev)
{
static char name[128];
sprintf(name, "kbd_%s.map", input[dev].idstr);
if (cfg.unique_mapping) sprintfz(name, "kbd_%08x.map", input[dev].unique_hash);
else sprintfz(name, "kbd_%s.map", input[dev].idstr);
return name;
}
@@ -3385,6 +3395,12 @@ void mergedevs()
strcpy(input[i].id, id);
strcpy(input[i].sysfs, sysfs);
strcpy(input[i].mac, uniq);
int unique_hash = str_hash(input[i].id);
unique_hash = str_hash(input[i].mac, unique_hash);
unique_hash = str_hash(input[i].idstr, unique_hash);
input[i].unique_hash = unique_hash;
input[i].timeout = (strlen(uniq) && strstr(sysfs, "bluetooth")) ? (cfg.bt_auto_disconnect * 10) : 0;
}
}