From cbd8819fb39bef4aa759ffb140ce700c5b327b69 Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 6 Dec 2015 22:58:54 -0500 Subject: [PATCH 1/4] new workaround for pads implemented as two independents hid devices --- input/drivers/android_input.c | 133 ++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 54 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 25259d4d2e..846974839e 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -89,6 +89,7 @@ typedef struct android_input } android_input_t; static void frontend_android_get_version_sdk(int32_t *sdk); +static void frontend_android_get_name(char *s, size_t len); bool (*engine_lookup_name)(char *buf, int *vendorId, int *productId, size_t size, int id); @@ -466,6 +467,9 @@ static int xperia2 = -1; static int archos1 = -1; static int archos2 = -1; +static int primary_id = -1; +static int secondary_id = -1; + static INLINE int android_input_poll_event_type_motion( android_input_data_t *android_data, AInputEvent *event, int port, int source) @@ -588,6 +592,10 @@ static void handle_hotplug(android_input_data_t *android_data, int productId = 0; bool back_mapped = false; settings_t *settings = config_get_ptr(); + char device_model[256] = {0}; + frontend_android_get_name(device_model, sizeof(device_model)); + + RARCH_LOG("Device model: (%s).\n", device_model); if (*port > MAX_PADS) { @@ -602,12 +610,15 @@ static void handle_hotplug(android_input_data_t *android_data, } /* FIXME - per-device hacks for nVidia Shield, Xperia Play and others - * For Xperia Play We need to keep 'count' of the amount of similar devices - * and group them in a single port. - * - * For the NVIDIA Shield we must make sure that the built-in controllers always - * map to the port - * + + * Built-in controller is always user 1 + * Back button is on a separate HID device with no VID/PID + * so we overwrite the id to make it act as one device + * other device names should use the normal process + + * This process depends on autoconf, but can work with user + * created autoconfs properly + * For TTT HT - keep track of how many of these 'pads' are already * connected, and based on that, assign one of them to be User 1 and * the other to be User 2. @@ -615,32 +626,69 @@ static void handle_hotplug(android_input_data_t *android_data, * If this is finally implemented right, then these port conditionals can go. */ - /* Xperia Play */ - if (strstr(device_name, "keypad-game-zeus") || - strstr(device_name, "keypad-zeus")) + /* NVIDIA Shield Portable */ + if(strstr(device_model, "SHIELD\0") && ( + strstr(device_name, "Virtual") || strstr(device_name, "gpio") || + strstr(device_name,"NVIDIA Corporation NVIDIA Controller v01.01"))) { - if (xperia1 < 0) + /* only use the hack if the device is one of the built-in devices */ + RARCH_LOG("NVIDIA Shield Detected: %s\n", device_model); { - RARCH_LOG("zeus_pad 1 detected: %u\n", id); - xperia1 = id; + if ( primary_id < 0 ) + primary_id = id; + else + secondary_id = id; + + if ( secondary_id > 0) + return; + + strlcpy (name_buf, "NVIDIA SHIELD Portable", sizeof(name_buf)); + RARCH_LOG("Device Name: %s\n", name_buf); + *port = 0; } - else - { - RARCH_LOG("zeus_pad 2 detected: %u\n", id); - xperia2 = id; - } - strlcpy(name_buf, device_name, sizeof(name_buf)); } - /* Archos Gamepad */ - else if (strstr(device_name, "joy_key") || strstr(device_name, "joystick")) + /* GPD XD */ + else if(strstr(device_model, "XD") && ( + strstr(device_name, "Virtual") || strstr(device_name, "rk29-keypad") || + strstr(device_name,"Playstation3") || strstr(device_name,"XBOX"))) + { + /* only use the hack if the device is one of the built-in devices */ + RARCH_LOG("GPD XD Detected: %s\n", device_model); + { + if ( primary_id < 0 ) + primary_id = id; + else + secondary_id = id; + + if ( secondary_id > 0) + return; + + strlcpy (name_buf, "GPD XD", sizeof(name_buf)); + RARCH_LOG("Device Name: %s\n", name_buf); + *port = 0; + } + } + + /* XPERIA Play */ + else if(strstr(device_model, "R800") && ( + strstr(device_name, "keypad-game-zeus") || strstr(device_name, "keypad-zeus"))) { - if (archos1 < 0) - archos1 = id; - else - archos2 = id; - *port = 0; - strlcpy(name_buf, "Archos Gamepad", sizeof(name_buf)); + /* only use the hack if the device is one of the built-in devices */ + RARCH_LOG("Sony XPERIA Play Detected: %s\n", device_model); + { + if ( primary_id < 0 ) + primary_id = id; + else + secondary_id = id; + + if ( secondary_id > 0) + return; + + strlcpy (name_buf, "XPERIA Play", sizeof(name_buf)); + RARCH_LOG("Device Name: %s\n", name_buf); + *port = 0; + } } else if (strstr(device_name, "iControlPad-")) @@ -665,32 +713,7 @@ static void handle_hotplug(android_input_data_t *android_data, strlcpy(name_buf, "SideWinder Classic", sizeof(name_buf)); } - /* NVIDIA Shield Portable - * Built-in controller is always user 1 - * Back button is on a separate HID device with no VID/PID - * so we bind that controller to user 1 too and overwrite - * whenever a gamepad button is pressed - */ - else if (strstr(device_name, "NVIDIA Corporation NVIDIA Controller v01.01")) - { - *port = 0; - strlcpy(name_buf, device_name, sizeof(name_buf)); - } - else if ((strstr(device_name, "Virtual") || strstr(device_name, "gpio")) && - strstr(android_data->pad_states[0].name,"NVIDIA Corporation NVIDIA Controller v01.01")) - { - *port = 0; - strlcpy(name_buf, "NVIDIA SHIELD Portable", sizeof(name_buf)); - } - /* Other NVIDIA Shield Devices - * NVIDIA button on the controller is on a separate HID device - * so whenever that button is hit, bind that device to user 1 and - * overwrite it whenever a SHIELD Controller button is pressed - * - * In this case we won't map back (4) to menu, instead we map the - * NVIDIA button (84) using an autoconf file - */ else if (strstr(device_name, "NVIDIA Corporation NVIDIA Controller v01.03") && !strstr(android_data->pad_states[0].name,"NVIDIA Corporation NVIDIA Controller v01.0")) { @@ -747,7 +770,6 @@ static void handle_hotplug(android_input_data_t *android_data, strlcpy(settings->input.device_names[*port], name_buf, sizeof(settings->input.device_names[*port])); - /* this is not a built in or fixed device, assign a new port */ if (*port < 0) *port = android_data->pads_connected; @@ -756,7 +778,7 @@ static void handle_hotplug(android_input_data_t *android_data, bool autoconfigured; autoconfig_params_t params = {{0}}; - RARCH_LOG("Port %d: %s VID/PID: %d/%d\n", *port, name_buf, params.vid, params.pid); + RARCH_LOG("Pads Connected: %d Port: %d\n %s VID/PID: %d/%d\n",android_data->pads_connected, *port, name_buf, params.vid, params.pid); strlcpy(params.name, name_buf, sizeof(params.name)); params.idx = *port; @@ -797,6 +819,9 @@ static int android_input_get_id(AInputEvent *event) if (id == archos2) id = archos1; + if (id == secondary_id) + id = primary_id; + return id; } @@ -821,7 +846,7 @@ static void android_input_poll_input(void *data) if (port < 0) handle_hotplug(android_data, android_app, - &port, id, source); + &port, id, source); switch (type_event) { From 17aa00db1a61edcf858634c94c777aa2a782974d Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 6 Dec 2015 23:20:47 -0500 Subject: [PATCH 2/4] change variables --- input/drivers/android_input.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 846974839e..20283f7e8a 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -462,13 +462,8 @@ static void *android_input_init(void) return android; } -static int xperia1 = -1; -static int xperia2 = -1; -static int archos1 = -1; -static int archos2 = -1; - -static int primary_id = -1; -static int secondary_id = -1; +int primary_id = -1; +int secondary_id = -1; static INLINE int android_input_poll_event_type_motion( android_input_data_t *android_data, AInputEvent *event, @@ -812,13 +807,6 @@ static int android_input_get_id(AInputEvent *event) { int id = AInputEvent_getDeviceId(event); - /* Needs to be cleaned up */ - if (id == xperia2) - id = xperia1; - - if (id == archos2) - id = archos1; - if (id == secondary_id) id = primary_id; From e28450368ff7b8ae9f21a2dcf59630615ae71de8 Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 6 Dec 2015 23:39:42 -0500 Subject: [PATCH 3/4] reset the ids when the driver is reinitialized --- input/drivers/android_input.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 20283f7e8a..a43a4860a3 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -48,6 +48,9 @@ struct input_pointer int16_t full_x, full_y; }; +int primary_id = -1; +int secondary_id = -1; + enum { AXIS_X = 0, @@ -425,6 +428,9 @@ static bool android_input_init_handle(void) RARCH_LOG("Set engine_handle_dpad to 'Get Axis Value' (for reading extra analog sticks)"); engine_handle_dpad = engine_handle_dpad_getaxisvalue; } + primary_id = -1; + secondary_id = -1; + return true; } @@ -462,9 +468,6 @@ static void *android_input_init(void) return android; } -int primary_id = -1; -int secondary_id = -1; - static INLINE int android_input_poll_event_type_motion( android_input_data_t *android_data, AInputEvent *event, int port, int source) @@ -604,6 +607,7 @@ static void handle_hotplug(android_input_data_t *android_data, return; } + RARCH_LOG("Device Name: %s\n IDS: %d, %d", name_buf, primary_id, secondary_id); /* FIXME - per-device hacks for nVidia Shield, Xperia Play and others * Built-in controller is always user 1 @@ -638,7 +642,6 @@ static void handle_hotplug(android_input_data_t *android_data, return; strlcpy (name_buf, "NVIDIA SHIELD Portable", sizeof(name_buf)); - RARCH_LOG("Device Name: %s\n", name_buf); *port = 0; } } @@ -660,7 +663,6 @@ static void handle_hotplug(android_input_data_t *android_data, return; strlcpy (name_buf, "GPD XD", sizeof(name_buf)); - RARCH_LOG("Device Name: %s\n", name_buf); *port = 0; } } @@ -681,7 +683,6 @@ static void handle_hotplug(android_input_data_t *android_data, return; strlcpy (name_buf, "XPERIA Play", sizeof(name_buf)); - RARCH_LOG("Device Name: %s\n", name_buf); *port = 0; } } From 08f42beefbdcf5766e960fe711503fb83ec2e75c Mon Sep 17 00:00:00 2001 From: radius Date: Wed, 9 Dec 2015 10:00:32 -0500 Subject: [PATCH 4/4] add ARCHOS gamepad --- input/drivers/android_input.c | 54 ++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index a43a4860a3..e6994beb84 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -647,25 +647,25 @@ static void handle_hotplug(android_input_data_t *android_data, } /* GPD XD */ - else if(strstr(device_model, "XD") && ( - strstr(device_name, "Virtual") || strstr(device_name, "rk29-keypad") || - strstr(device_name,"Playstation3") || strstr(device_name,"XBOX"))) - { - /* only use the hack if the device is one of the built-in devices */ - RARCH_LOG("GPD XD Detected: %s\n", device_model); - { - if ( primary_id < 0 ) - primary_id = id; - else - secondary_id = id; + else if(strstr(device_model, "XD") && ( + strstr(device_name, "Virtual") || strstr(device_name, "rk29-keypad") || + strstr(device_name,"Playstation3") || strstr(device_name,"XBOX"))) + { + /* only use the hack if the device is one of the built-in devices */ + RARCH_LOG("GPD XD Detected: %s\n", device_model); + { + if ( primary_id < 0 ) + primary_id = id; + else + secondary_id = id; - if ( secondary_id > 0) - return; + if ( secondary_id > 0) + return; - strlcpy (name_buf, "GPD XD", sizeof(name_buf)); - *port = 0; - } - } + strlcpy (name_buf, "GPD XD", sizeof(name_buf)); + *port = 0; + } + } /* XPERIA Play */ else if(strstr(device_model, "R800") && ( @@ -687,6 +687,26 @@ static void handle_hotplug(android_input_data_t *android_data, } } + /* ARCHOS Gamepad */ + else if(strstr(device_model, "ARCHOS GAMEPAD") && ( + strstr(device_name, "joy_key") || strstr(device_name, "joystick"))) + { + /* only use the hack if the device is one of the built-in devices */ + RARCH_LOG("ARCHOS GAMEPAD Detected: %s\n", device_model); + { + if ( primary_id < 0 ) + primary_id = id; + else + secondary_id = id; + + if ( secondary_id > 0) + return; + + strlcpy (name_buf, "ARCHOS GamePad", sizeof(name_buf)); + *port = 0; + } + } + else if (strstr(device_name, "iControlPad-")) strlcpy(name_buf, "iControlPad HID Joystick profile", sizeof(name_buf));