From 141dbabe3d9830473c3631aa9147e8ba3b2a1be3 Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 9 Jul 2015 11:29:04 -0500 Subject: [PATCH 1/2] add VID/PID to the dinput_joypad struct --- input/drivers_joypad/dinput_joypad.c | 32 +++++++++++++++++++++++++++- input/input_autodetect.h | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index db13d7f441..0d0dd4525c 100644 --- a/input/drivers_joypad/dinput_joypad.c +++ b/input/drivers_joypad/dinput_joypad.c @@ -35,6 +35,9 @@ struct dinput_joypad LPDIRECTINPUTDEVICE8 joypad; DIJOYSTATE2 joy_state; char* joy_name; + char* joy_friendly_name; + int32_t vid; + int32_t pid; }; static struct dinput_joypad g_pads[MAX_USERS]; @@ -70,6 +73,8 @@ static void dinput_joypad_destroy(void) free(g_pads[i].joy_name); g_pads[i].joy_name = NULL; + free(g_pads[i].joy_friendly_name); + g_pads[i].joy_friendly_name = NULL; *settings->input.device_names[i] = '\0'; } @@ -172,6 +177,14 @@ static const char *dinput_joypad_name(unsigned pad) return NULL; } +static const char *dinput_joypad_friendly_name(unsigned pad) +{ + if (pad < MAX_USERS) + return g_pads[pad].joy_friendly_name; + + return NULL; +} + static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) { bool is_xinput_pad; @@ -196,6 +209,20 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) return DIENUM_CONTINUE; g_pads[g_joypad_cnt].joy_name = strdup(inst->tszProductName); + g_pads[g_joypad_cnt].joy_friendly_name = strdup(inst->tszInstanceName); + + /* there may be more useful info in the GUID so leave this here for a while + + printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n", + inst->guidProduct.Data1, inst->guidProduct.Data2, inst->guidProduct.Data3, + inst->guidProduct.Data4[0], inst->guidProduct.Data4[1], inst->guidProduct.Data4[2], inst->guidProduct.Data4[3], + inst->guidProduct.Data4[4], inst->guidProduct.Data4[5], inst->guidProduct.Data4[6], inst->guidProduct.Data4[7]); + printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n",*/ + + g_pads[g_joypad_cnt].vid = inst->guidProduct.Data1/0x10000; + g_pads[g_joypad_cnt].pid = inst->guidProduct.Data1%0x10000; + RARCH_LOG("PID: {%04lX} VID:{%04lX}\n", g_pads[g_joypad_cnt].pid, g_pads[g_joypad_cnt].vid); + #ifdef HAVE_XINPUT #if 0 @@ -233,8 +260,10 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) /* TODO - implement VID/PID? */ params.idx = g_joypad_cnt; strlcpy(params.name, dinput_joypad_name(g_joypad_cnt), sizeof(params.name)); + strlcpy(params.display_name, dinput_joypad_friendly_name(g_joypad_cnt), sizeof(params.driver)); strlcpy(params.driver, dinput_joypad.ident, sizeof(params.driver)); - input_config_autoconfigure_joypad(¶ms); + input_config_autoconfigure_joypad(¶ms); + RARCH_LOG("DINPUT %s %s %s\n",params.name, params.driver, params.display_name); } enum_iteration_done: @@ -257,6 +286,7 @@ static bool dinput_joypad_init(void *data) { g_xinput_pad_indexes[i] = -1; g_pads[i].joy_name = NULL; + g_pads[i].joy_friendly_name = NULL; } RARCH_LOG("Enumerating DInput joypads ...\n"); diff --git a/input/input_autodetect.h b/input/input_autodetect.h index d1bfca1f35..888ce59bef 100644 --- a/input/input_autodetect.h +++ b/input/input_autodetect.h @@ -24,6 +24,7 @@ typedef struct autoconfig_params { char name[PATH_MAX_LENGTH]; char driver[PATH_MAX_LENGTH]; + char display_name[PATH_MAX_LENGTH]; unsigned idx; int32_t vid; int32_t pid; From af978297e238f1f317a1d703d88d8782fe845bcf Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 9 Jul 2015 11:31:05 -0500 Subject: [PATCH 2/2] fix nits --- input/drivers_joypad/dinput_joypad.c | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index 0d0dd4525c..79396c4598 100644 --- a/input/drivers_joypad/dinput_joypad.c +++ b/input/drivers_joypad/dinput_joypad.c @@ -163,7 +163,7 @@ static bool guid_is_xinput_device(const GUID* product_guid) return true; } } - + free(raw_devs); raw_devs = NULL; return false; @@ -207,31 +207,31 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) g_dinput_ctx, &inst->guidInstance, pad, NULL))) #endif return DIENUM_CONTINUE; - + g_pads[g_joypad_cnt].joy_name = strdup(inst->tszProductName); g_pads[g_joypad_cnt].joy_friendly_name = strdup(inst->tszInstanceName); - + /* there may be more useful info in the GUID so leave this here for a while - - printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n", - inst->guidProduct.Data1, inst->guidProduct.Data2, inst->guidProduct.Data3, + + printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n", + inst->guidProduct.Data1, inst->guidProduct.Data2, inst->guidProduct.Data3, inst->guidProduct.Data4[0], inst->guidProduct.Data4[1], inst->guidProduct.Data4[2], inst->guidProduct.Data4[3], inst->guidProduct.Data4[4], inst->guidProduct.Data4[5], inst->guidProduct.Data4[6], inst->guidProduct.Data4[7]); - printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n",*/ + */ g_pads[g_joypad_cnt].vid = inst->guidProduct.Data1/0x10000; g_pads[g_joypad_cnt].pid = inst->guidProduct.Data1%0x10000; RARCH_LOG("PID: {%04lX} VID:{%04lX}\n", g_pads[g_joypad_cnt].pid, g_pads[g_joypad_cnt].vid); - - + + #ifdef HAVE_XINPUT #if 0 - is_xinput_pad = g_xinput_block_pads + is_xinput_pad = g_xinput_block_pads && name_is_xinput_pad(inst->tszProductName); #endif - is_xinput_pad = g_xinput_block_pads + is_xinput_pad = g_xinput_block_pads && guid_is_xinput_device(&inst->guidProduct); - + if (is_xinput_pad) { if (g_last_xinput_pad_idx < 4) @@ -244,9 +244,9 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) IDirectInputDevice8_SetCooperativeLevel(*pad, (HWND)driver->video_window, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); - IDirectInputDevice8_EnumObjects(*pad, enum_axes_cb, + IDirectInputDevice8_EnumObjects(*pad, enum_axes_cb, *pad, DIDFT_ABSAXIS); - + #ifdef HAVE_XINPUT if (!is_xinput_pad) #endif @@ -268,7 +268,7 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p) enum_iteration_done: g_joypad_cnt++; - return DIENUM_CONTINUE; + return DIENUM_CONTINUE; } static bool dinput_joypad_init(void *data) @@ -279,9 +279,9 @@ static bool dinput_joypad_init(void *data) if (!dinput_init_context()) return false; - + g_last_xinput_pad_idx = 0; - + for (i = 0; i < MAX_USERS; ++i) { g_xinput_pad_indexes[i] = -1; @@ -312,7 +312,7 @@ static bool dinput_joypad_button(unsigned port_num, uint16_t joykey) { unsigned pov; unsigned hat = GET_HAT(joykey); - unsigned elems = sizeof(pad->joy_state.rgdwPOV) / + unsigned elems = sizeof(pad->joy_state.rgdwPOV) / sizeof(pad->joy_state.rgdwPOV[0]); if (hat >= elems) @@ -340,7 +340,7 @@ static bool dinput_joypad_button(unsigned port_num, uint16_t joykey) } else { - unsigned elems = sizeof(pad->joy_state.rgbButtons) / + unsigned elems = sizeof(pad->joy_state.rgbButtons) / sizeof(pad->joy_state.rgbButtons[0]); if (joykey < elems)