~fitzsim/Main_MiSTer

e28c6616b6565c7e2116079a5af7ebe824eac989 — zakk4223 2 years ago 088dc49
input: Use sub_dev to find controller db entries: fixes some multifunctional devices (#689)

Co-authored-by: Zakk <zakk@rsdio.com>
2 files changed, 19 insertions(+), 1 deletions(-)

M gamecontroller_db.cpp
M input.cpp
M gamecontroller_db.cpp => gamecontroller_db.cpp +18 -0
@@ 195,12 195,14 @@ static bool parse_mapping_string(char *map_str, char *guid, int dev_fd, uint32_t
		uint16_t abs_cnt = 0;
		bzero(btn_map, sizeof(btn_map));
		bzero(abs_map, sizeof(abs_map));
		printf("Gamecontrollerdb: mapping buttons for %s ", guid);
		if (ioctl(dev_fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits) >= 0)
		{
			for (int i = BTN_JOYSTICK; i < KEY_MAX; i++)
			{
					if (test_bit(i, keybits))
					{
						printf("b%d->%d ", btn_cnt, i);
						btn_map[btn_cnt] = i;
						btn_cnt++;
					}


@@ 210,13 212,16 @@ static bool parse_mapping_string(char *map_str, char *guid, int dev_fd, uint32_t
			{
					if (test_bit(i, keybits))
					{	
						printf("b%d -> %d ", btn_cnt, i);
						btn_map[btn_cnt] = i;
						btn_cnt++;
					}
			}
			printf("\n");
				
		}

		printf("Gamecontrollerdb: mapping analog axes for %s ", guid);
		if (ioctl(dev_fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits) >= 0)
		{
			//The "correct" way is to test  all the way to ABS_MAX and skip any hats the device has.


@@ 226,11 231,23 @@ static bool parse_mapping_string(char *map_str, char *guid, int dev_fd, uint32_t
			{
				if (test_bit(i, absbits))
				{
						printf("a%d->%d ", abs_cnt, i);
						abs_map[abs_cnt] = i;
						abs_cnt++;
				}
			}

			//Just for debugging purposes...
			for (int i = ABS_HAT0X; i < ABS_MAX; i++)
			{
					if (test_bit(i, absbits))
					{
						printf("(debug)a%d->%d ", abs_cnt, i);
						abs_cnt++;
					}
			}
		}
		printf("\n");
	}

	char l_btn[20] = {};


@@ 321,6 338,7 @@ bool read_controller_map_from_file(char *fname, char *guid, int dev_fd, uint32_t
		printf("Gamecontrollerdb: searching for GUID %s in file %s\n", guid, fname);
		while ((line = FileReadLine(&reader)))
		{
			if (line[0] == '#') continue;
			const char *gcom = strchr(line, ',');
			if (!strncasecmp(line, guid, gcom-line))
			{

M input.cpp => input.cpp +1 -1
@@ 2288,7 2288,7 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int 
		{
			if (!load_map(get_map_name(dev, 1), &input[dev].mmap, sizeof(input[dev].mmap)))
			{
				if (!gcdb_map_for_controller(input[dev].bustype, input[dev].vid, input[dev].pid, input[dev].version, pool[dev].fd, input[dev].mmap))
				if (!gcdb_map_for_controller(input[sub_dev].bustype, input[sub_dev].vid, input[sub_dev].pid, input[sub_dev].version, pool[sub_dev].fd, input[dev].mmap))
				{
					memset(input[dev].mmap, 0, sizeof(input[dev].mmap));
					memcpy(input[dev].mmap, def_mmap, sizeof(def_mmap));