[ORBIS] some changes for input

This commit is contained in:
Antonio Jose Ramos Marquez 2021-09-19 02:28:36 +02:00 committed by Francisco Javier Trujillo Mata
parent 7a15f81b39
commit 9dd060dbc8
2 changed files with 105 additions and 10 deletions

View File

@ -30,17 +30,108 @@
#include "../input_driver.h"
static void ps4_input_free_input(void *data) { }
static void* ps4_input_initialize(const char *a) { return (void*)-1; }
typedef struct ps4_input
{
const input_device_driver_t *joypad;
} ps4_input_t;
static int16_t ps4_input_state(void *data,
rarch_joypad_info_t *joypad_info,
const struct retro_keybind **binds,
unsigned port, unsigned device,
unsigned idx, unsigned id)
{
ps4_input_t *ps4 = (ps4_input_t*)data;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
int16_t ret = 0;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[port][i].joykey != NO_BTN)
? binds[port][i].joykey : joypad_info->auto_binds[i].joykey;
const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE)
? binds[port][i].joyaxis : joypad_info->auto_binds[i].joyaxis;
if ((uint16_t)joykey != NO_BTN && ps4->joypad->button(
joypad_info->joy_idx, (uint16_t)joykey))
{
ret |= (1 << i);
continue;
}
if (((float)abs(ps4->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
{
ret |= (1 << i);
continue;
}
}
return ret;
}
else
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[port][id].joykey != NO_BTN)
? binds[port][id].joykey : joypad_info->auto_binds[id].joykey;
const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE)
? binds[port][id].joyaxis : joypad_info->auto_binds[id].joyaxis;
if ((uint16_t)joykey != NO_BTN && ps4->joypad->button(
joypad_info->joy_idx, (uint16_t)joykey))
return true;
if (((float)abs(ps4->joypad->axis(joypad_info->joy_idx, joyaxis)) / 0x8000) > joypad_info->axis_threshold)
return true;
}
break;
case RETRO_DEVICE_ANALOG:
// if (binds[port])
// return input_joypad_analog(ps4->joypad, joypad_info, port, idx, id, binds[port]);
break;
}
return 0;
}
static void ps4_input_free_input(void *data)
{
ps4_input_t *ps4 = (ps4_input_t*)data;
if (ps4 && ps4->joypad)
ps4->joypad->destroy();
free(data);
}
static void* ps4_input_initialize(const char *joypad_driver)
{
ps4_input_t *ps4 = (ps4_input_t*)calloc(1, sizeof(*ps4));
if (!ps4)
return NULL;
ps4->joypad = input_joypad_init_driver(joypad_driver, ps4);
return ps4;
}
static void ps4_input_poll(void *data)
{
ps4_input_t *ps4 = (ps4_input_t*)data;
if (ps4 && ps4->joypad)
ps4->joypad->poll();
}
static uint64_t ps4_input_get_capabilities(void *data)
{
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
}
input_driver_t input_ps4 = {
ps4_input_initialize,
NULL, /* poll */
NULL, /* input_state */
ps4_input_poll, /* poll */
ps4_input_state, /* input_state */
ps4_input_free_input,
NULL,
NULL,
@ -48,4 +139,4 @@ input_driver_t input_ps4 = {
"ps4",
NULL, /* grab_mouse */
NULL
};
};

View File

@ -30,6 +30,10 @@
#define LERP(p, f, t) ((((p * 10) * (t * 10)) / (f * 10)) / 10)
#if defined(HAVE_LIBORBIS) || defined(ORBIS)
#include <orbis/orbisPad.h>
OrbisPadConfig *confPad;
typedef struct SceUserServiceLoginUserIdList
{
int32_t userId[SCE_USER_SERVICE_MAX_LOGIN_USERS];
@ -75,7 +79,7 @@ static void *ps4_joypad_init(void *data)
num_players = 0;
scePadInit();
confPad=orbisPadGetConf();
result = sceUserServiceGetLoginUserIdList(&userIdList);
if (result == 0)
@ -98,14 +102,14 @@ static void *ps4_joypad_init(void *data)
if (index == num_players)
{
ds_joypad_states[num_players].handle[0] = scePadOpen(userId, SCE_PAD_PORT_TYPE_STANDARD, 0, NULL);
// if (ds_joypad_states[num_players].handle[0] == SCE_ORBISPAD_ERROR_ALREADY_OPENED)
// ds_joypad_states[num_players].handle[0] = scePadGetHandle(userId, SCE_PAD_PORT_TYPE_STANDARD, 0);
if (ds_joypad_states[num_players].handle[0] == SCE_ORBISPAD_ERROR_ALREADY_OPENED)
ds_joypad_states[num_players].handle[0] = confPad->padHandle;//scePadGetHandle(userId, SCE_PAD_PORT_TYPE_STANDARD, 0);
ds_joypad_states[num_players].handle[1] = scePadOpen(userId, SCE_PAD_PORT_TYPE_SPECIAL, 0, NULL);
//ds_joypad_states[num_players].handle[1] = scePadOpen(userId, SCE_PAD_PORT_TYPE_SPECIAL, 0, NULL);
// if (ds_joypad_states[num_players].handle[1] == SCE_ORBISPAD_ERROR_ALREADY_OPENED)
// ds_joypad_states[num_players].handle[1] = scePadGetHandle(userId, SCE_PAD_PORT_TYPE_SPECIAL, 0);
ds_joypad_states[num_players].handle[2] = scePadOpen(userId, SCE_PAD_PORT_TYPE_REMOTE_CONTROL, 0, NULL);
//ds_joypad_states[num_players].handle[2] = scePadOpen(userId, SCE_PAD_PORT_TYPE_REMOTE_CONTROL, 0, NULL);
// if (ds_joypad_states[num_players].handle[2] == SCE_ORBISPAD_ERROR_ALREADY_OPENED)
// ds_joypad_states[num_players].handle[2] = scePadGetHandle(userId, SCE_PAD_PORT_TYPE_REMOTE_CONTROL, 0);