fix hotplug detection on wii

This commit is contained in:
Toad King 2015-05-12 20:34:54 -05:00
parent b5c0e4060d
commit 0112847082

View File

@ -39,8 +39,9 @@
#define WPADProbe WPAD_Probe
#endif
#define WPAD_EXP_SICKSAXIS 253
#define WPAD_EXP_GAMECUBE 254
#define WPAD_EXP_SICKSAXIS 252
#define WPAD_EXP_GAMECUBE 253
#define WPAD_EXP_NOCONTROLLER 254
#ifdef HW_RVL
#ifdef HAVE_LIBSICKSAXIS
@ -114,7 +115,7 @@ enum
#define WII_JOYSTICK_THRESHOLD (40 * 256)
static uint64_t pad_state[MAX_PADS];
static uint32_t pad_type[MAX_PADS];
static uint32_t pad_type[MAX_PADS] = { WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER };
static int16_t analog_state[MAX_PADS][2][2];
static bool g_menu;
#ifdef HW_RVL
@ -171,36 +172,15 @@ static const char *gx_joypad_name(unsigned pad)
return NULL;
}
static const char *gx_joypad_name_static(unsigned pad)
{
switch (pad_type[pad])
{
#ifdef HW_RVL
case WPAD_EXP_NONE:
return "Wiimote Controller";
case WPAD_EXP_NUNCHUK:
return "Nunchuk Controller";
case WPAD_EXP_CLASSIC:
return "Classic Controller";
#ifdef HAVE_LIBSICKSAXIS
case WPAD_EXP_SICKSAXIS:
return "Sixaxis Controller";
#endif
#endif
case WPAD_EXP_GAMECUBE:
return "GameCube Controller";
}
return NULL;
}
static void handle_hotplug(unsigned port, uint32_t ptype)
{
pad_type[port] = ptype;
if (ptype != WPAD_EXP_NOCONTROLLER)
{
autoconfig_params_t params = {{0}};
settings_t *settings = config_get_ptr();
pad_type[port] = ptype;
if (!settings->input.autodetect_enable)
return;
@ -213,46 +193,7 @@ static void handle_hotplug(unsigned port, uint32_t ptype)
strlcpy(params.name, gx_joypad_name(port), sizeof(params.name));
strlcpy(params.driver, gx_joypad.ident, sizeof(params.driver));
input_config_autoconfigure_joypad(&params);
}
static bool gx_joypad_init(void)
{
int autoconf_pad;
autoconfig_params_t params = {{0}};
settings_t *settings = config_get_ptr();
SYS_SetResetCallback(reset_cb);
#ifdef HW_RVL
SYS_SetPowerCallback(power_callback);
#endif
PAD_Init();
#ifdef HW_RVL
WPADInit();
#endif
#ifdef HAVE_LIBSICKSAXIS
int i;
USB_Initialize();
ss_init();
for (i = 0; i < MAX_PADS; i++)
ss_initialize(&dev[i]);
#endif
for (autoconf_pad = 0; autoconf_pad < MAX_PADS; autoconf_pad++)
{
pad_type[autoconf_pad] = WPAD_EXP_GAMECUBE;
strlcpy(settings->input.device_names[autoconf_pad],
gx_joypad_name_static(autoconf_pad),
sizeof(settings->input.device_names[autoconf_pad]));
/* TODO - implement VID/PID? */
params.idx = autoconf_pad;
strlcpy(params.name, gx_joypad_name_static(autoconf_pad), sizeof(params.name));
strlcpy(params.driver, gx_joypad.ident, sizeof(params.driver));
input_config_autoconfigure_joypad(&params);
}
return true;
}
static bool gx_joypad_button(unsigned port, uint16_t joykey)
@ -424,7 +365,7 @@ static void gx_joypad_poll(void)
for (port = 0; port < MAX_PADS; port++)
{
uint32_t down = 0, ptype = 0;
uint32_t down = 0, ptype = WPAD_EXP_NOCONTROLLER;
uint64_t *state_cur = &pad_state[port];
#ifdef HW_RVL
@ -510,8 +451,6 @@ static void gx_joypad_poll(void)
}
}
else
#else
ptype = WPAD_EXP_GAMECUBE;
#endif
{
if (gcpad & (1 << port))
@ -619,9 +558,33 @@ static void gx_joypad_poll(void)
*lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE);
}
static bool gx_joypad_init(void)
{
SYS_SetResetCallback(reset_cb);
#ifdef HW_RVL
SYS_SetPowerCallback(power_callback);
#endif
PAD_Init();
#ifdef HW_RVL
WPADInit();
#endif
#ifdef HAVE_LIBSICKSAXIS
int i;
USB_Initialize();
ss_init();
for (i = 0; i < MAX_PADS; i++)
ss_initialize(&dev[i]);
#endif
gx_joypad_poll();
return true;
}
static bool gx_joypad_query_pad(unsigned pad)
{
return pad < MAX_USERS && pad_state[pad];
return pad < MAX_USERS && pad_type[pad] != WPAD_EXP_NOCONTROLLER;
}
static void gx_joypad_destroy(void)