RetroArch/input/input_joypad_driver.c

192 lines
4.4 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 16:46:50 +00:00
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* 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/>.
*/
#include "input_joypad_driver.h"
#include "input_keymaps.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <string/string_list.h>
#include "../general.h"
static rarch_joypad_driver_t *joypad_drivers[] = {
#ifdef __CELLOS_LV2__
&ps3_joypad,
#endif
#ifdef HAVE_WINXINPUT
&winxinput_joypad,
#endif
#ifdef GEKKO
&gx_joypad,
#endif
#ifdef _XBOX
&xdk_joypad,
#endif
#ifdef PSP
&psp_joypad,
#endif
#ifdef HAVE_DINPUT
&dinput_joypad,
#endif
#ifdef HAVE_UDEV
&udev_joypad,
#endif
#if defined(__linux) && !defined(ANDROID)
&linuxraw_joypad,
#endif
#ifdef HAVE_PARPORT
&parport_joypad,
#endif
#ifdef ANDROID
&android_joypad,
#endif
#if defined(HAVE_SDL) || defined(HAVE_SDL2)
&sdl_joypad,
#endif
#ifdef __MACH__
#ifdef HAVE_HID
&apple_hid_joypad,
#endif
#ifdef IOS
&apple_ios_joypad,
#endif
#endif
#ifdef __QNX__
&qnx_joypad,
#endif
2014-10-27 13:45:28 +00:00
&null_joypad,
NULL,
};
/**
* joypad_driver_find_handle:
* @idx : index of driver to get handle to.
*
* Returns: handle to joypad driver at index. Can be NULL
* if nothing found.
**/
const void *joypad_driver_find_handle(int idx)
{
const void *drv = joypad_drivers[idx];
if (!drv)
return NULL;
return drv;
}
/**
* joypad_driver_find_ident:
* @idx : index of driver to get handle to.
*
* Returns: Human-readable identifier of joypad driver at index. Can be NULL
* if nothing found.
**/
const char *joypad_driver_find_ident(int idx)
{
const rarch_joypad_driver_t *drv = joypad_drivers[idx];
if (!drv)
return NULL;
return drv->ident;
}
2015-01-09 23:03:04 +00:00
/**
* config_get_joypad_driver_options:
*
* Get an enumerated list of all joypad driver names, separated by '|'.
*
* Returns: string listing of all joypad driver names, separated by '|'.
**/
const char* config_get_joypad_driver_options(void)
{
union string_list_elem_attr attr;
2015-01-12 16:16:14 +00:00
unsigned i;
char *options = NULL;
int options_len = 0;
2014-12-15 16:13:08 +00:00
struct string_list *options_l = string_list_new();
attr.i = 0;
2015-01-12 16:16:14 +00:00
for (i = 0; joypad_drivers[i]; i++)
{
2015-01-12 16:16:14 +00:00
const char *opt = joypad_drivers[i]->ident;
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
2015-01-09 23:03:04 +00:00
/**
* input_joypad_init_driver:
* @ident : identifier of driver to initialize.
*
* Initialize a joypad driver of name @ident.
*
* If ident points to NULL or a zero-length string,
* equivalent to calling input_joypad_init_first().
*
* Returns: joypad driver if found, otherwise NULL.
**/
const rarch_joypad_driver_t *input_joypad_init_driver(const char *ident)
{
unsigned i;
if (!ident || !*ident)
return input_joypad_init_first();
for (i = 0; joypad_drivers[i]; i++)
{
if (strcmp(ident, joypad_drivers[i]->ident) == 0
&& joypad_drivers[i]->init())
{
RARCH_LOG("Found joypad driver: \"%s\".\n",
joypad_drivers[i]->ident);
return joypad_drivers[i];
}
}
return input_joypad_init_first();
}
2015-01-09 23:03:04 +00:00
/**
* input_joypad_init_first:
*
* Finds first suitable joypad driver and initializes.
*
* Returns: joypad driver if found, otherwise NULL.
**/
const rarch_joypad_driver_t *input_joypad_init_first(void)
{
unsigned i;
2015-01-09 23:03:04 +00:00
for (i = 0; joypad_drivers[i]; i++)
{
if (joypad_drivers[i]->init())
{
RARCH_LOG("Found joypad driver: \"%s\".\n",
joypad_drivers[i]->ident);
return joypad_drivers[i];
}
}
return NULL;
}