mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 04:20:28 +00:00
(BlackBerry) Modify device handling to allow keyboards on PlayBook.
This commit is contained in:
parent
df777c0264
commit
f9de811505
@ -18,6 +18,7 @@
|
||||
#include <screen/screen.h>
|
||||
#include <bps/event.h>
|
||||
#include <bps/navigator.h>
|
||||
#include <sys/keycodes.h>
|
||||
|
||||
#define MAX_TOUCH 16
|
||||
#define MAX_PADS 8
|
||||
@ -33,13 +34,11 @@ static struct touches touch[MAX_TOUCH];
|
||||
static unsigned touch_count;
|
||||
|
||||
//Internal helper functions
|
||||
#ifdef HAVE_BB10
|
||||
#include <sys/keycodes.h>
|
||||
static unsigned pads_connected;
|
||||
|
||||
typedef struct {
|
||||
// Static device info.
|
||||
#ifdef HAVE_BB10
|
||||
screen_device_t handle;
|
||||
#endif
|
||||
int type;
|
||||
int analogCount;
|
||||
int buttonCount;
|
||||
@ -51,9 +50,15 @@ typedef struct {
|
||||
int buttons;
|
||||
int analog0[3];
|
||||
int analog1[3];
|
||||
} Gamepad_t;
|
||||
} input_device_t;
|
||||
|
||||
Gamepad_t devices[MAX_PADS];
|
||||
input_device_t devices[MAX_PADS];
|
||||
|
||||
static unsigned pads_connected;
|
||||
|
||||
static void qnx_input_autodetect_gamepad(input_device_t* controller);
|
||||
|
||||
#ifdef HAVE_BB10
|
||||
|
||||
const struct platform_bind platform_keys[] = {
|
||||
{ SCREEN_A_GAME_BUTTON, "A button" },
|
||||
@ -83,7 +88,7 @@ static void process_gamepad_event(screen_event_t screen_event, int type)
|
||||
screen_device_t device;
|
||||
screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device);
|
||||
|
||||
Gamepad_t* controller = NULL;
|
||||
input_device_t* controller = NULL;
|
||||
int i;
|
||||
for (i = 0; i < MAX_PADS; ++i)
|
||||
{
|
||||
@ -111,51 +116,7 @@ static void process_gamepad_event(screen_event_t screen_event, int type)
|
||||
}
|
||||
}
|
||||
|
||||
static void initController(Gamepad_t* controller)
|
||||
{
|
||||
// Initialize controller values.
|
||||
controller->handle = 0;
|
||||
controller->type = 0;
|
||||
controller->analogCount = 0;
|
||||
controller->buttonCount = 0;
|
||||
controller->buttons = 0;
|
||||
controller->analog0[0] = controller->analog0[1] = controller->analog0[2] = 0;
|
||||
controller->analog1[0] = controller->analog1[1] = controller->analog1[2] = 0;
|
||||
memset(controller->id, 0, sizeof(controller->id));
|
||||
}
|
||||
|
||||
static void qnx_input_autodetect_gamepad(Gamepad_t* controller)
|
||||
{
|
||||
int device;
|
||||
|
||||
//ID: A-BBBB-CCCC-D.D
|
||||
//A is the device's index in the array returned by screen_get_context_property_pv()
|
||||
//BBBB is the device's Vendor ID (in hexadecimal)
|
||||
//CCCC is the device's Product ID (also in hexadecimal)
|
||||
//D.D is the device's version number
|
||||
if (strstr(controller->id, "057E-0306"))
|
||||
{
|
||||
device = DEVICE_WIIMOTE;
|
||||
}
|
||||
else if (strstr(controller->id, "0A5C-8502"))
|
||||
{
|
||||
device = DEVICE_KEYBOARD;
|
||||
}
|
||||
else if (controller->id)
|
||||
{
|
||||
device = DEVICE_UNKNOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
device = DEVICE_NONE;
|
||||
}
|
||||
|
||||
if (driver.input->set_keybinds)
|
||||
driver.input->set_keybinds((void*)controller, device, pads_connected, 0,
|
||||
(1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS));
|
||||
}
|
||||
|
||||
static void loadController(Gamepad_t* controller)
|
||||
static void loadController(input_device_t* controller)
|
||||
{
|
||||
int device;
|
||||
|
||||
@ -235,10 +196,66 @@ static void discoverControllers()
|
||||
|
||||
free(devices_found);
|
||||
}
|
||||
#else
|
||||
void init_playbook_keyboard()
|
||||
{
|
||||
strlcpy(devices[0].id, "0A5C-8502", sizeof(devices[0].id));
|
||||
qnx_input_autodetect_gamepad(&devices[0]);
|
||||
pads_connected = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void initController(input_device_t* controller)
|
||||
{
|
||||
// Initialize controller values.
|
||||
#ifdef HAVE_BB10
|
||||
controller->handle = 0;
|
||||
#endif
|
||||
controller->type = 0;
|
||||
controller->analogCount = 0;
|
||||
controller->buttonCount = 0;
|
||||
controller->buttons = 0;
|
||||
controller->analog0[0] = controller->analog0[1] = controller->analog0[2] = 0;
|
||||
controller->analog1[0] = controller->analog1[1] = controller->analog1[2] = 0;
|
||||
memset(controller->id, 0, sizeof(controller->id));
|
||||
}
|
||||
|
||||
static void qnx_input_autodetect_gamepad(input_device_t* controller)
|
||||
{
|
||||
int device;
|
||||
|
||||
//ID: A-BBBB-CCCC-D.D
|
||||
//A is the device's index in the array returned by screen_get_context_property_pv()
|
||||
//BBBB is the device's Vendor ID (in hexadecimal)
|
||||
//CCCC is the device's Product ID (also in hexadecimal)
|
||||
//D.D is the device's version number
|
||||
if (strstr(controller->id, "057E-0306"))
|
||||
{
|
||||
device = DEVICE_WIIMOTE;
|
||||
}
|
||||
else if (strstr(controller->id, "0A5C-8502"))
|
||||
{
|
||||
device = DEVICE_KEYBOARD;
|
||||
}
|
||||
else if (controller->id)
|
||||
{
|
||||
device = DEVICE_UNKNOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
device = DEVICE_NONE;
|
||||
}
|
||||
|
||||
if (driver.input->set_keybinds)
|
||||
driver.input->set_keybinds((void*)controller, device, pads_connected, 0,
|
||||
(1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS));
|
||||
}
|
||||
|
||||
static void process_keyboard_event(screen_event_t event, int type)
|
||||
{
|
||||
input_device_t* controller = NULL;
|
||||
int i = 0;
|
||||
|
||||
//Get Keyboard state
|
||||
int sym = 0;
|
||||
screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SYM, &sym);
|
||||
@ -251,12 +268,11 @@ static void process_keyboard_event(screen_event_t event, int type)
|
||||
int cap = 0;
|
||||
screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap);
|
||||
|
||||
#ifdef HAVE_BB10
|
||||
//Find device that pressed the key
|
||||
screen_device_t device;
|
||||
screen_get_event_property_pv(event, SCREEN_PROPERTY_DEVICE, (void**)&device);
|
||||
|
||||
Gamepad_t* controller = NULL;
|
||||
int i;
|
||||
for (i = 0; i < MAX_PADS; ++i)
|
||||
{
|
||||
if (device == devices[i].handle)
|
||||
@ -268,6 +284,9 @@ static void process_keyboard_event(screen_event_t event, int type)
|
||||
|
||||
if (!controller)
|
||||
return;
|
||||
#else
|
||||
controller = &devices[0];
|
||||
#endif
|
||||
|
||||
int b;
|
||||
for (b = 0; b < RARCH_FIRST_CUSTOM_BIND; ++b)
|
||||
@ -286,7 +305,7 @@ static void process_keyboard_event(screen_event_t event, int type)
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void process_touch_event(screen_event_t event, int type)
|
||||
{
|
||||
int contact_id;
|
||||
@ -345,10 +364,10 @@ static void handle_screen_event(bps_event_t *event)
|
||||
case SCREEN_EVENT_MTOUCH_MOVE:
|
||||
process_touch_event(screen_event, type);
|
||||
break;
|
||||
#ifdef HAVE_BB10
|
||||
case SCREEN_EVENT_KEYBOARD:
|
||||
process_keyboard_event(screen_event, type);
|
||||
break;
|
||||
#ifdef HAVE_BB10
|
||||
case SCREEN_EVENT_GAMEPAD:
|
||||
case SCREEN_EVENT_JOYSTICK:
|
||||
process_gamepad_event(screen_event, type);
|
||||
@ -460,14 +479,16 @@ static void *qnx_input_init(void)
|
||||
for (i = 0; i < MAX_TOUCH; ++i)
|
||||
touch[i].contact_id = -1;
|
||||
|
||||
#ifdef HAVE_BB10
|
||||
|
||||
for (i = 0; i < MAX_PADS; ++i)
|
||||
initController(&devices[i]);
|
||||
|
||||
#ifdef HAVE_BB10
|
||||
pads_connected = 0;
|
||||
|
||||
//Find currently connected gamepads
|
||||
discoverControllers();
|
||||
#else
|
||||
init_playbook_keyboard();
|
||||
#endif
|
||||
|
||||
return (void*)-1;
|
||||
@ -508,13 +529,14 @@ static int16_t qnx_input_state(void *data, const struct retro_keybind **retro_ke
|
||||
|
||||
switch (device)
|
||||
{
|
||||
#ifdef HAVE_BB10
|
||||
case RETRO_DEVICE_JOYPAD:
|
||||
if (g_settings.input.device[port] == DEVICE_KEYBOARD)
|
||||
{
|
||||
return ((devices[port].buttons & (1 << id)) && (port < pads_connected));
|
||||
}
|
||||
else
|
||||
return ((devices[port].buttons & retro_keybinds[port][id].joykey) && (port < pads_connected));
|
||||
|
||||
#ifdef HAVE_BB10
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
//Need to return [-0x8000, 0x7fff]
|
||||
//Gamepad API gives us [-128, 127] with (0,0) center
|
||||
@ -614,11 +636,12 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port,
|
||||
|
||||
if (keybind_action & (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BIND))
|
||||
*key = g_settings.input.binds[port][id].def_joykey;
|
||||
|
||||
#endif
|
||||
if (keybind_action & (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS))
|
||||
{
|
||||
switch (device)
|
||||
{
|
||||
#ifdef HAVE_BB10
|
||||
case DEVICE_WIIMOTE:
|
||||
strlcpy(g_settings.input.device_names[port], "Wiimote",
|
||||
sizeof(g_settings.input.device_names[port]));
|
||||
@ -641,6 +664,7 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port,
|
||||
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = SCREEN_R3_GAME_BUTTON;
|
||||
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_NONE;
|
||||
break;
|
||||
#endif
|
||||
case DEVICE_KEYBOARD:
|
||||
strlcpy(g_settings.input.device_names[port], "BlackBerry BT Keyboard",
|
||||
sizeof(g_settings.input.device_names[port]));
|
||||
@ -663,6 +687,7 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port,
|
||||
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = 0;
|
||||
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_NONE;
|
||||
break;
|
||||
#ifdef HAVE_BB10
|
||||
case DEVICE_UNKNOWN:
|
||||
strlcpy(g_settings.input.device_names[port], "Unknown",
|
||||
sizeof(g_settings.input.device_names[port]));
|
||||
@ -707,6 +732,7 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port,
|
||||
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joykey = 0;
|
||||
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = 0;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++)
|
||||
@ -716,6 +742,7 @@ static void qnx_input_set_keybinds(void *data, unsigned device, unsigned port,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_BB10
|
||||
//TODO: Handle keyboard mappings
|
||||
if (keybind_action & (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user