2012-12-31 18:02:20 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-01 01:37:37 +01:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2012-12-31 18:02:20 +01:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-01-09 05:12:56 +01:00
|
|
|
#include "../../../frontend/frontend_android.h"
|
2013-01-06 06:10:07 +01:00
|
|
|
#include "jni_macros.h"
|
2012-12-31 18:02:20 +01:00
|
|
|
#include "input_autodetect.h"
|
|
|
|
|
2013-01-05 07:20:02 +01:00
|
|
|
static void input_autodetect_get_device_name(void *data, char *buf, size_t size, int id)
|
2012-12-31 18:02:20 +01:00
|
|
|
{
|
2013-01-05 07:20:02 +01:00
|
|
|
struct android_app *android_app = (struct android_app*)data;
|
2013-01-02 21:54:35 +01:00
|
|
|
buf[0] = '\0';
|
|
|
|
|
2013-01-05 07:20:02 +01:00
|
|
|
JavaVM *vm = android_app->activity->vm;
|
2012-12-31 18:02:20 +01:00
|
|
|
JNIEnv *env = NULL;
|
|
|
|
(*vm)->AttachCurrentThread(vm, &env, 0);
|
|
|
|
|
|
|
|
jclass input_device_class = NULL;
|
|
|
|
FIND_CLASS(env, input_device_class, "android/view/InputDevice");
|
2013-01-02 21:54:35 +01:00
|
|
|
if (!input_device_class)
|
|
|
|
goto end;
|
2012-12-31 18:02:20 +01:00
|
|
|
|
|
|
|
jmethodID method = NULL;
|
|
|
|
GET_STATIC_METHOD_ID(env, method, input_device_class, "getDevice", "(I)Landroid/view/InputDevice;");
|
2013-01-02 21:54:35 +01:00
|
|
|
if (!method)
|
|
|
|
goto end;
|
2012-12-31 18:02:20 +01:00
|
|
|
|
|
|
|
jobject device = NULL;
|
|
|
|
CALL_OBJ_STATIC_METHOD_PARAM(env, device, input_device_class, method, (jint)id);
|
2013-01-02 21:54:35 +01:00
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to find device for ID: %d\n", id);
|
|
|
|
goto end;
|
|
|
|
}
|
2012-12-31 18:02:20 +01:00
|
|
|
|
|
|
|
jmethodID getName = NULL;
|
|
|
|
GET_METHOD_ID(env, getName, input_device_class, "getName", "()Ljava/lang/String;");
|
2013-01-02 23:53:40 +01:00
|
|
|
if (!getName)
|
2013-01-02 21:54:35 +01:00
|
|
|
goto end;
|
2012-12-31 18:02:20 +01:00
|
|
|
|
|
|
|
jobject name = NULL;
|
|
|
|
CALL_OBJ_METHOD(env, name, device, getName);
|
2013-01-02 21:54:35 +01:00
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to find name for device ID: %d\n", id);
|
|
|
|
goto end;
|
|
|
|
}
|
2012-12-31 18:02:20 +01:00
|
|
|
|
|
|
|
const char *str = (*env)->GetStringUTFChars(env, name, 0);
|
2013-01-02 21:54:35 +01:00
|
|
|
if (str)
|
|
|
|
strlcpy(buf, str, size);
|
2012-12-31 18:02:20 +01:00
|
|
|
(*env)->ReleaseStringUTFChars(env, name, str);
|
|
|
|
|
2013-01-02 21:54:35 +01:00
|
|
|
end:
|
2012-12-31 18:02:20 +01:00
|
|
|
(*vm)->DetachCurrentThread(vm);
|
|
|
|
}
|
|
|
|
|
2013-02-03 19:06:54 +01:00
|
|
|
void input_autodetect_setup (void *data, char *msg, size_t sizeof_msg, unsigned port, unsigned id, int source)
|
2012-12-31 18:02:20 +01:00
|
|
|
{
|
2013-01-05 07:20:02 +01:00
|
|
|
struct android_app *android_app = (struct android_app*)data;
|
2012-12-31 18:02:20 +01:00
|
|
|
|
2013-03-13 23:17:33 +01:00
|
|
|
unsigned device;
|
2012-12-31 18:02:20 +01:00
|
|
|
char name_buf[256];
|
2013-01-05 17:35:50 +01:00
|
|
|
name_buf[0] = 0;
|
2012-12-31 18:02:20 +01:00
|
|
|
|
2013-03-16 17:51:45 +01:00
|
|
|
if (port > MAX_PADS)
|
2012-12-31 18:02:20 +01:00
|
|
|
{
|
2013-01-05 17:35:50 +01:00
|
|
|
snprintf(msg, sizeof_msg, "Max number of pads reached.\n");
|
2013-02-03 19:06:54 +01:00
|
|
|
return;
|
2012-12-31 18:02:20 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 07:20:02 +01:00
|
|
|
char *current_ime = android_app->current_ime;
|
2013-02-03 20:04:48 +01:00
|
|
|
input_autodetect_get_device_name(android_app, name_buf, sizeof(name_buf), id);
|
2013-02-03 21:26:53 +01:00
|
|
|
RARCH_LOG("device name: %s\n", name_buf);
|
2013-02-03 20:04:48 +01:00
|
|
|
|
2013-06-16 18:18:15 +02:00
|
|
|
/* Shitty hack put back in again */
|
|
|
|
if (strstr(name_buf, "keypad-game-zeus") || strstr(name_buf, "keypad-zeus"))
|
|
|
|
{
|
|
|
|
if (zeus_id < 0)
|
|
|
|
{
|
|
|
|
RARCH_LOG("zeus_pad 1 detected: %d\n", id);
|
|
|
|
zeus_id = id;
|
|
|
|
zeus_port = port;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_LOG("zeus_pad 2 detected: %d\n", id);
|
|
|
|
zeus_second_id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 14:23:54 -05:00
|
|
|
if (g_settings.input.autodetect_enable)
|
|
|
|
{
|
2013-03-13 23:17:33 +01:00
|
|
|
device = 0;
|
2013-02-03 18:49:05 +01:00
|
|
|
|
2013-03-13 23:17:33 +01:00
|
|
|
if (strstr(name_buf,"Logitech") && strstr(name_buf, "RumblePad 2"))
|
|
|
|
device = DEVICE_LOGITECH_RUMBLEPAD2;
|
|
|
|
else if (strstr(name_buf, "Logitech") && strstr(name_buf, "Dual Action"))
|
|
|
|
device = DEVICE_LOGITECH_DUAL_ACTION;
|
2013-06-16 18:25:17 +02:00
|
|
|
else if (strstr(name_buf, "Logitech") && strstr(name_buf, "Precision"))
|
|
|
|
device = DEVICE_LOGITECH_PRECISION_GAMEPAD;
|
2013-02-17 22:58:06 +01:00
|
|
|
else if (strstr(name_buf, "shooter-keypad"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_ICONTROLPAD_BLUEZ_IME;
|
2013-03-30 08:55:44 +01:00
|
|
|
else if (strstr(name_buf, "SEGA VIRTUA STICK High Grade"))
|
|
|
|
device = DEVICE_SEGA_VIRTUA_STICK_HIGH_GRADE;
|
2013-02-11 02:12:21 +01:00
|
|
|
else if (strstr(name_buf, "TTT THT Arcade console 2P USB Play"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_TTT_THT_ARCADE;
|
2013-02-26 15:50:06 +01:00
|
|
|
else if (strstr(name_buf, "TOMMO NEOGEOX Arcade Stick"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_TOMMO_NEOGEOX_ARCADE;
|
|
|
|
else if (strstr(name_buf, "MadCatz") && strstr(name_buf, "PC USB Wired Stick"))
|
|
|
|
device = DEVICE_MADCATZ_PC_USB_STICK;
|
|
|
|
else if (strstr(name_buf, "Logicool") && strstr(name_buf, "RumblePad 2"))
|
|
|
|
device = DEVICE_LOGICOOL_RUMBLEPAD2;
|
2013-03-05 14:25:30 +01:00
|
|
|
else if (strstr(name_buf, "Sun4i-keypad"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_IDROID_X360;
|
|
|
|
else if (strstr(name_buf, "Zeemote") && strstr(name_buf, "Steelseries free"))
|
|
|
|
device = DEVICE_ZEEMOTE_STEELSERIES;
|
|
|
|
else if (strstr(name_buf, "HuiJia USB GamePad"))
|
|
|
|
device = DEVICE_HUIJIA_USB_SNES;
|
|
|
|
else if (strstr(name_buf, "Smartjoy Family Super Smartjoy 2"))
|
|
|
|
device = DEVICE_SUPER_SMARTJOY;
|
2013-02-08 02:57:21 +01:00
|
|
|
else if (strstr(name_buf, "Jess Tech Dual Analog Rumble Pad"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_SAITEK_RUMBLE_P480;
|
2013-01-05 17:09:13 +01:00
|
|
|
else if (strstr(name_buf, "Microsoft"))
|
|
|
|
{
|
|
|
|
if (strstr(name_buf, "Dual Strike"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_MS_SIDEWINDER_DUAL_STRIKE;
|
|
|
|
else if (strstr(name_buf, "SideWinder"))
|
|
|
|
device = DEVICE_MS_SIDEWINDER;
|
|
|
|
else if (strstr(name_buf, "X-Box 360") || strstr(name_buf, "X-Box")
|
2013-02-08 02:59:28 +01:00
|
|
|
|| strstr(name_buf, "Xbox 360 Wireless Receiver"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_MS_XBOX;
|
2012-12-31 18:02:20 +01:00
|
|
|
}
|
2013-01-26 19:42:11 +01:00
|
|
|
else if (strstr(name_buf, "WiseGroup"))
|
2012-12-31 18:02:20 +01:00
|
|
|
{
|
2013-01-28 06:09:07 +01:00
|
|
|
if (strstr(name_buf, "TigerGame") || strstr(name_buf, "Game Controller Adapter")
|
|
|
|
|| strstr(name_buf, "JC-PS102U") || strstr(name_buf, "Dual USB Joypad"))
|
2013-01-26 19:42:11 +01:00
|
|
|
{
|
2013-03-04 16:42:26 +01:00
|
|
|
if (strstr(name_buf, "WiseGroup"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_WISEGROUP_PLAYSTATION2;
|
|
|
|
else if (strstr(name_buf, "JC-PS102U"))
|
|
|
|
device = DEVICE_JCPS102_PLAYSTATION2;
|
2013-01-29 00:57:03 +01:00
|
|
|
else
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_GENERIC_PLAYSTATION2_CONVERTER;
|
2013-01-26 19:42:11 +01:00
|
|
|
}
|
2012-12-31 18:02:20 +01:00
|
|
|
}
|
2013-01-05 17:09:13 +01:00
|
|
|
else if (strstr(name_buf, "PLAYSTATION(R)3") || strstr(name_buf, "Dualshock3")
|
2013-06-03 16:24:31 +02:00
|
|
|
|| strstr(name_buf,"Sixaxis") || strstr(name_buf, "Gasia,Co") ||
|
2013-01-05 18:13:30 +01:00
|
|
|
(strstr(name_buf, "Gamepad 0") || strstr(name_buf, "Gamepad 1") ||
|
|
|
|
strstr(name_buf, "Gamepad 2") || strstr(name_buf, "Gamepad 3")))
|
2012-12-31 18:02:20 +01:00
|
|
|
{
|
2013-03-13 23:17:33 +01:00
|
|
|
if (strstr(name_buf, "Gamepad 0") || strstr(name_buf, "Gamepad 1") ||
|
|
|
|
strstr(name_buf, "Gamepad 2") || strstr(name_buf, "Gamepad 3"))
|
|
|
|
device = DEVICE_PLAYSTATION3_VERSION1;
|
2013-01-05 18:13:30 +01:00
|
|
|
else
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_PLAYSTATION3_VERSION2;
|
2012-12-31 18:02:20 +01:00
|
|
|
}
|
2013-01-05 17:09:13 +01:00
|
|
|
else if (strstr(name_buf, "MOGA"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_MOGA;
|
2013-01-05 17:09:13 +01:00
|
|
|
else if (strstr(name_buf, "Sony Navigation Controller"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_PSMOVE_NAVI;
|
2013-05-13 10:21:06 +02:00
|
|
|
else if (strstr(name_buf, "OUYA Game Controller"))
|
|
|
|
device = DEVICE_OUYA;
|
2013-03-08 05:53:55 +01:00
|
|
|
else if (strstr(name_buf, "adc joystick"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_JXD_S7300B;
|
2013-01-26 22:59:34 +01:00
|
|
|
else if (strstr(name_buf, "idroid:con"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_IDROID_CON;
|
2013-01-27 04:59:11 +01:00
|
|
|
else if (strstr(name_buf, "NYKO PLAYPAD PRO"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_NYKO_PLAYPAD_PRO;
|
2013-02-13 22:51:57 +01:00
|
|
|
else if (strstr(name_buf, "2-Axis, 8-Button"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_GENIUS_MAXFIRE_G08XU;
|
|
|
|
else if (strstr(name_buf, "USB,2-axis 8-button gamepad"))
|
|
|
|
device = DEVICE_USB_2_AXIS_8_BUTTON_GAMEPAD;
|
|
|
|
else if (strstr(name_buf, "BUFFALO BGC-FC801"))
|
|
|
|
device = DEVICE_BUFFALO_BGC_FC801;
|
(Android) Add gamepads to autodetection - (Archos gamepad, Xperia Play,
Xbox 1 Titanium X-Joyconverter, Xbox 360 wired, Red Samurai BT, Mayflash
Wii Classic variant, RetroUSB NES, RetroUSB SNES, Buffalo SNES,
Logicool F710, Elecom PS1/PS2)
2013-01-28 01:59:07 +01:00
|
|
|
else if (strstr(name_buf, "RetroUSB.com RetroPad"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_RETROUSB_RETROPAD;
|
(Android) Add gamepads to autodetection - (Archos gamepad, Xperia Play,
Xbox 1 Titanium X-Joyconverter, Xbox 360 wired, Red Samurai BT, Mayflash
Wii Classic variant, RetroUSB NES, RetroUSB SNES, Buffalo SNES,
Logicool F710, Elecom PS1/PS2)
2013-01-28 01:59:07 +01:00
|
|
|
else if (strstr(name_buf, "RetroUSB.com SNES RetroPort"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_RETROUSB_SNES_RETROPORT;
|
2013-01-05 17:09:13 +01:00
|
|
|
else if (strstr(name_buf, "CYPRESS USB"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_CYPRESS_USB;
|
|
|
|
else if (strstr(name_buf, "Mayflash Wii Classic"))
|
|
|
|
device = DEVICE_MAYFLASH_WII_CLASSIC;
|
|
|
|
else if (strstr(name_buf, "SZMy-power LTD CO. Dual Box WII"))
|
|
|
|
device = DEVICE_SZMY_POWER_DUAL_BOX_WII;
|
2013-01-05 17:09:13 +01:00
|
|
|
else if (strstr(name_buf, "Toodles 2008 ChImp"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_TOODLES_2008_CHIMP;
|
(Android) Add gamepads to autodetection - (Archos gamepad, Xperia Play,
Xbox 1 Titanium X-Joyconverter, Xbox 360 wired, Red Samurai BT, Mayflash
Wii Classic variant, RetroUSB NES, RetroUSB SNES, Buffalo SNES,
Logicool F710, Elecom PS1/PS2)
2013-01-28 01:59:07 +01:00
|
|
|
else if (strstr(name_buf, "joy_key"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_ARCHOS_GAMEPAD;
|
2013-01-26 20:55:21 +01:00
|
|
|
else if (strstr(name_buf, "matrix_keyboard"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_JXD_S5110;
|
2013-02-03 22:43:18 +01:00
|
|
|
else if (strstr(name_buf, "keypad-zeus") || (strstr(name_buf, "keypad-game-zeus")))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_XPERIA_PLAY;
|
(Android) Add gamepads to autodetection - (Archos gamepad, Xperia Play,
Xbox 1 Titanium X-Joyconverter, Xbox 360 wired, Red Samurai BT, Mayflash
Wii Classic variant, RetroUSB NES, RetroUSB SNES, Buffalo SNES,
Logicool F710, Elecom PS1/PS2)
2013-01-28 01:59:07 +01:00
|
|
|
else if (strstr(name_buf, "Broadcom Bluetooth HID"))
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_BROADCOM_BLUETOOTH_HID;
|
|
|
|
else if (strstr(name_buf, "USB Gamepad"))
|
|
|
|
device = DEVICE_THRUST_PREDATOR;
|
|
|
|
else if (strstr(name_buf, "DragonRise"))
|
|
|
|
device = DEVICE_DRAGONRISE;
|
2013-05-26 01:13:24 +02:00
|
|
|
else if (strstr(name_buf, "Thrustmaster T Mini"))
|
|
|
|
device = DEVICE_THRUSTMASTER_T_MINI;
|
|
|
|
else if (strstr(name_buf, "2Axes 11Keys Game Pad"))
|
|
|
|
device = DEVICE_TOMEE_NES_USB;
|
2013-06-04 11:14:14 +02:00
|
|
|
else if (strstr(name_buf, "rk29-keypad") || strstr(name_buf, "GAMEMID"))
|
|
|
|
device = DEVICE_GAMEMID;
|
2013-06-06 12:29:34 +02:00
|
|
|
else if (strstr(name_buf, "USB Gamepad"))
|
|
|
|
device = DEVICE_DEFENDER_GAME_RACER_CLASSIC;
|
2013-01-29 20:48:53 +01:00
|
|
|
|
2013-02-04 00:43:13 +01:00
|
|
|
if (strstr(current_ime, "net.obsidianx.android.mogaime"))
|
|
|
|
{
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_MOGA_IME;
|
2013-02-04 00:43:13 +01:00
|
|
|
snprintf(name_buf, sizeof(name_buf), "MOGA IME");
|
|
|
|
}
|
|
|
|
else if (strstr(current_ime, "com.ccpcreations.android.WiiUseAndroid"))
|
2013-01-02 23:53:40 +01:00
|
|
|
{
|
2013-03-13 23:17:33 +01:00
|
|
|
device = DEVICE_CCPCREATIONS_WIIUSE_IME;
|
2013-01-05 04:58:30 +01:00
|
|
|
snprintf(name_buf, sizeof(name_buf), "ccpcreations WiiUse");
|
2013-01-02 23:53:40 +01:00
|
|
|
}
|
2013-01-05 17:09:13 +01:00
|
|
|
|
2013-03-13 23:17:33 +01:00
|
|
|
if (source == AINPUT_SOURCE_KEYBOARD)
|
|
|
|
device = DEVICE_KEYBOARD_RETROPAD;
|
2013-01-05 17:09:13 +01:00
|
|
|
|
2013-03-14 02:24:57 +01:00
|
|
|
if (driver.input->set_keybinds)
|
|
|
|
driver.input->set_keybinds(driver.input_data, device, port, id,
|
|
|
|
(1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS));
|
2012-12-31 18:02:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name_buf[0] != 0)
|
2013-03-13 23:17:33 +01:00
|
|
|
snprintf(msg, sizeof_msg, "Port %d: %s.\n", port, name_buf);
|
2012-12-31 18:02:20 +01:00
|
|
|
}
|