2014-08-30 01:46:57 +00:00
|
|
|
/* 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
|
|
|
|
* Copyright (C) 2012-2015 - Michael Lelli
|
2014-08-30 01:46:57 +00:00
|
|
|
* Copyright (C) 2013-2014 - Steven Crowe
|
2015-07-03 02:48:06 +00:00
|
|
|
*
|
2015-11-29 15:18:29 +00: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-
|
2014-08-30 01:46:57 +00:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-11-29 15:18:29 +00:00
|
|
|
#include "../drivers_keyboard/keyboard_event_android.h"
|
|
|
|
|
2014-08-30 01:46:57 +00:00
|
|
|
static const char *android_joypad_name(unsigned pad)
|
|
|
|
{
|
2015-03-20 21:41:15 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-04-02 23:02:46 +00:00
|
|
|
return settings ? settings->input.device_names[pad] : NULL;
|
2014-08-30 01:46:57 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 16:22:54 +00:00
|
|
|
static bool android_joypad_init(void *data)
|
2014-08-30 01:46:57 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-05 14:51:58 +00:00
|
|
|
static bool android_joypad_button(unsigned port, uint16_t joykey)
|
2014-08-30 01:46:57 +00:00
|
|
|
{
|
2015-11-29 15:18:29 +00:00
|
|
|
uint8_t *buf = android_keyboard_state_get(port);
|
2015-12-02 21:33:27 +00:00
|
|
|
struct android_app *android_app = (struct android_app*)g_android;
|
2014-08-30 01:46:57 +00:00
|
|
|
|
2015-11-29 15:18:29 +00:00
|
|
|
if (port >= MAX_PADS)
|
2014-08-30 01:46:57 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (GET_HAT_DIR(joykey))
|
|
|
|
{
|
|
|
|
unsigned h = GET_HAT(joykey);
|
|
|
|
if (h > 0)
|
|
|
|
return false;
|
2014-09-09 16:15:17 +00:00
|
|
|
|
2014-08-30 01:46:57 +00:00
|
|
|
switch (GET_HAT_DIR(joykey))
|
|
|
|
{
|
2014-09-09 16:15:17 +00:00
|
|
|
case HAT_LEFT_MASK:
|
2015-12-02 21:33:27 +00:00
|
|
|
return android_app->hat_state[port][0] == -1;
|
2014-09-09 16:15:17 +00:00
|
|
|
case HAT_RIGHT_MASK:
|
2015-12-02 21:33:27 +00:00
|
|
|
return android_app->hat_state[port][0] == 1;
|
2014-09-09 16:15:17 +00:00
|
|
|
case HAT_UP_MASK:
|
2015-12-02 21:33:27 +00:00
|
|
|
return android_app->hat_state[port][1] == -1;
|
2014-09-09 16:15:17 +00:00
|
|
|
case HAT_DOWN_MASK:
|
2015-12-02 21:33:27 +00:00
|
|
|
return android_app->hat_state[port][1] == 1;
|
2014-09-09 16:15:17 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2014-08-30 01:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-05 14:51:58 +00:00
|
|
|
|
|
|
|
return joykey < LAST_KEYCODE && BIT_GET(buf, joykey);
|
2014-08-30 01:46:57 +00:00
|
|
|
}
|
|
|
|
|
2014-10-05 14:51:58 +00:00
|
|
|
static int16_t android_joypad_axis(unsigned port, uint32_t joyaxis)
|
2014-08-30 01:46:57 +00:00
|
|
|
{
|
2015-04-02 23:02:46 +00:00
|
|
|
int val = 0;
|
2015-12-02 21:33:27 +00:00
|
|
|
struct android_app *android_app = (struct android_app*)g_android;
|
2015-01-10 23:07:59 +00:00
|
|
|
|
2015-11-29 15:18:29 +00:00
|
|
|
if (joyaxis == AXIS_NONE)
|
2015-01-10 23:07:59 +00:00
|
|
|
return 0;
|
2014-08-30 01:46:57 +00:00
|
|
|
|
|
|
|
if (AXIS_NEG_GET(joyaxis) < MAX_AXIS)
|
|
|
|
{
|
2015-12-02 21:33:27 +00:00
|
|
|
val = android_app->analog_state[port][AXIS_NEG_GET(joyaxis)];
|
2015-11-29 15:18:29 +00:00
|
|
|
if (val > 0)
|
|
|
|
val = 0;
|
2014-08-30 01:46:57 +00:00
|
|
|
}
|
|
|
|
else if (AXIS_POS_GET(joyaxis) < MAX_AXIS)
|
|
|
|
{
|
2015-12-02 21:33:27 +00:00
|
|
|
val = android_app->analog_state[port][AXIS_POS_GET(joyaxis)];
|
2015-11-29 15:18:29 +00:00
|
|
|
if (val < 0)
|
|
|
|
val = 0;
|
2014-08-30 01:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void android_joypad_poll(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool android_joypad_query_pad(unsigned pad)
|
|
|
|
{
|
2015-11-29 15:35:51 +00:00
|
|
|
return (pad < MAX_USERS);
|
2014-08-30 01:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void android_joypad_destroy(void)
|
|
|
|
{
|
2015-11-29 15:18:29 +00:00
|
|
|
unsigned i, j;
|
2015-12-02 21:33:27 +00:00
|
|
|
struct android_app *android_app = (struct android_app*)g_android;
|
2015-11-29 15:18:29 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_PADS; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < 2; j++)
|
2015-12-02 21:33:27 +00:00
|
|
|
android_app->hat_state[i][j] = 0;
|
2015-11-29 15:18:29 +00:00
|
|
|
for (j = 0; j < MAX_AXIS; j++)
|
2015-12-02 21:33:27 +00:00
|
|
|
android_app->analog_state[i][j] = 0;
|
2015-11-29 15:18:29 +00:00
|
|
|
}
|
2014-08-30 01:46:57 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 14:37:59 +00:00
|
|
|
input_device_driver_t android_joypad = {
|
2014-08-30 01:46:57 +00:00
|
|
|
android_joypad_init,
|
|
|
|
android_joypad_query_pad,
|
|
|
|
android_joypad_destroy,
|
|
|
|
android_joypad_button,
|
2015-02-15 00:57:29 +00:00
|
|
|
NULL,
|
2014-08-30 01:46:57 +00:00
|
|
|
android_joypad_axis,
|
|
|
|
android_joypad_poll,
|
|
|
|
NULL,
|
|
|
|
android_joypad_name,
|
|
|
|
"android",
|
|
|
|
};
|