RetroArch/input/drivers_joypad/qnx_joypad.c

146 lines
3.7 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
* Copyright (C) 2013-2014 - CatalystG
*
* 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_autodetect.h"
static const char *qnx_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;
}
static bool qnx_joypad_init(void *data)
{
unsigned autoconf_pad;
2015-03-20 21:41:15 +00:00
settings_t *settings = config_get_ptr();
(void)data;
2015-01-05 00:58:00 +00:00
for (autoconf_pad = 0; autoconf_pad < MAX_USERS; autoconf_pad++)
{
2015-03-27 15:57:58 +00:00
autoconfig_params_t params = {{0}};
2015-03-20 21:41:15 +00:00
strlcpy(settings->input.device_names[autoconf_pad], "None",
sizeof(settings->input.device_names[autoconf_pad]));
2015-03-27 15:57:58 +00:00
/* TODO - implement VID/PID? */
2015-03-27 15:57:58 +00:00
params.idx = autoconf_pad;
strlcpy(params.name, qnx_joypad_name(autoconf_pad), sizeof(params.name));
strlcpy(params.driver, qnx_joypad.ident, sizeof(params.driver));
input_config_autoconfigure_joypad(&params);
}
return true;
}
static bool qnx_joypad_button(unsigned port_num, uint16_t joykey)
{
2015-03-21 21:55:50 +00:00
driver_t *driver = driver_get_ptr();
qnx_input_t *qnx = (qnx_input_t*)driver->input_data;
if (!qnx || port_num >= MAX_PADS)
return false;
return qnx->pad_state[port_num] & (1ULL << joykey);
}
2015-02-15 00:57:29 +00:00
static uint64_t qnx_joypad_get_buttons(unsigned port_num)
{
2015-03-21 21:55:50 +00:00
driver_t *driver = driver_get_ptr();
qnx_input_t *qnx = (qnx_input_t*)driver->input_data;
2015-02-15 00:57:29 +00:00
if (!qnx || port_num >= MAX_PADS)
return 0;
return qnx->pad_state[port_num];
}
static int16_t qnx_joypad_axis(unsigned port_num, uint32_t joyaxis)
{
2015-04-02 23:02:46 +00:00
int val = 0;
int axis = -1;
bool is_neg = false;
bool is_pos = false;
2015-03-21 21:55:50 +00:00
driver_t *driver = driver_get_ptr();
qnx_input_t *qnx = (qnx_input_t*)driver->input_data;
if (!qnx || joyaxis == AXIS_NONE || port_num >= MAX_PADS)
return 0;
if (AXIS_NEG_GET(joyaxis) < 4)
{
axis = AXIS_NEG_GET(joyaxis);
is_neg = true;
}
else if (AXIS_POS_GET(joyaxis) < 4)
{
axis = AXIS_POS_GET(joyaxis);
is_pos = true;
}
switch (axis)
{
2014-09-09 16:15:17 +00:00
case 0:
val = qnx->analog_state[port_num][0][0];
break;
case 1:
val = qnx->analog_state[port_num][0][1];
break;
case 2:
val = qnx->analog_state[port_num][1][0];
break;
case 3:
val = qnx->analog_state[port_num][1][1];
break;
}
if (is_neg && val > 0)
val = 0;
else if (is_pos && val < 0)
val = 0;
return val;
}
static void qnx_joypad_poll(void)
{
}
static bool qnx_joypad_query_pad(unsigned pad)
{
2015-03-21 21:55:50 +00:00
driver_t *driver = driver_get_ptr();
qnx_input_t *qnx = (qnx_input_t*)driver->input_data;
2015-01-05 00:58:00 +00:00
return (qnx && pad < MAX_USERS && qnx->pad_state[pad]);
}
static void qnx_joypad_destroy(void)
{
}
input_device_driver_t qnx_joypad = {
qnx_joypad_init,
qnx_joypad_query_pad,
qnx_joypad_destroy,
qnx_joypad_button,
2015-02-15 00:57:29 +00:00
qnx_joypad_get_buttons,
qnx_joypad_axis,
qnx_joypad_poll,
NULL,
qnx_joypad_name,
"qnx",
};