mirror of
https://github.com/libretro/RetroArch
synced 2025-04-09 21:45:45 +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 <screen/screen.h>
|
||||||
#include <bps/event.h>
|
#include <bps/event.h>
|
||||||
#include <bps/navigator.h>
|
#include <bps/navigator.h>
|
||||||
|
#include <sys/keycodes.h>
|
||||||
|
|
||||||
#define MAX_TOUCH 16
|
#define MAX_TOUCH 16
|
||||||
#define MAX_PADS 8
|
#define MAX_PADS 8
|
||||||
@ -33,13 +34,11 @@ static struct touches touch[MAX_TOUCH];
|
|||||||
static unsigned touch_count;
|
static unsigned touch_count;
|
||||||
|
|
||||||
//Internal helper functions
|
//Internal helper functions
|
||||||
#ifdef HAVE_BB10
|
|
||||||
#include <sys/keycodes.h>
|
|
||||||
static unsigned pads_connected;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// Static device info.
|
// Static device info.
|
||||||
|
#ifdef HAVE_BB10
|
||||||
screen_device_t handle;
|
screen_device_t handle;
|
||||||
|
#endif
|
||||||
int type;
|
int type;
|
||||||
int analogCount;
|
int analogCount;
|
||||||
int buttonCount;
|
int buttonCount;
|
||||||
@ -51,9 +50,15 @@ typedef struct {
|
|||||||
int buttons;
|
int buttons;
|
||||||
int analog0[3];
|
int analog0[3];
|
||||||
int analog1[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[] = {
|
const struct platform_bind platform_keys[] = {
|
||||||
{ SCREEN_A_GAME_BUTTON, "A button" },
|
{ 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_device_t device;
|
||||||
screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device);
|
screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device);
|
||||||
|
|
||||||
Gamepad_t* controller = NULL;
|
input_device_t* controller = NULL;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < MAX_PADS; ++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)
|
static void loadController(input_device_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)
|
|
||||||
{
|
{
|
||||||
int device;
|
int device;
|
||||||
|
|
||||||
@ -235,10 +196,66 @@ static void discoverControllers()
|
|||||||
|
|
||||||
free(devices_found);
|
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)
|
static void process_keyboard_event(screen_event_t event, int type)
|
||||||
{
|
{
|
||||||
|
input_device_t* controller = NULL;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
//Get Keyboard state
|
//Get Keyboard state
|
||||||
int sym = 0;
|
int sym = 0;
|
||||||
screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SYM, &sym);
|
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;
|
int cap = 0;
|
||||||
screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap);
|
screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap);
|
||||||
|
|
||||||
|
#ifdef HAVE_BB10
|
||||||
//Find device that pressed the key
|
//Find device that pressed the key
|
||||||
screen_device_t device;
|
screen_device_t device;
|
||||||
screen_get_event_property_pv(event, SCREEN_PROPERTY_DEVICE, (void**)&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)
|
for (i = 0; i < MAX_PADS; ++i)
|
||||||
{
|
{
|
||||||
if (device == devices[i].handle)
|
if (device == devices[i].handle)
|
||||||
@ -268,6 +284,9 @@ static void process_keyboard_event(screen_event_t event, int type)
|
|||||||
|
|
||||||
if (!controller)
|
if (!controller)
|
||||||
return;
|
return;
|
||||||
|
#else
|
||||||
|
controller = &devices[0];
|
||||||
|
#endif
|
||||||
|
|
||||||
int b;
|
int b;
|
||||||
for (b = 0; b < RARCH_FIRST_CUSTOM_BIND; ++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)
|
static void process_touch_event(screen_event_t event, int type)
|
||||||
{
|
{
|
||||||
int contact_id;
|
int contact_id;
|
||||||
@ -345,10 +364,10 @@ static void handle_screen_event(bps_event_t *event)
|
|||||||
case SCREEN_EVENT_MTOUCH_MOVE:
|
case SCREEN_EVENT_MTOUCH_MOVE:
|
||||||
process_touch_event(screen_event, type);
|
process_touch_event(screen_event, type);
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_BB10
|
|
||||||
case SCREEN_EVENT_KEYBOARD:
|
case SCREEN_EVENT_KEYBOARD:
|
||||||
process_keyboard_event(screen_event, type);
|
process_keyboard_event(screen_event, type);
|
||||||
break;
|
break;
|
||||||
|
#ifdef HAVE_BB10
|
||||||
case SCREEN_EVENT_GAMEPAD:
|
case SCREEN_EVENT_GAMEPAD:
|
||||||
case SCREEN_EVENT_JOYSTICK:
|
case SCREEN_EVENT_JOYSTICK:
|
||||||
process_gamepad_event(screen_event, type);
|
process_gamepad_event(screen_event, type);
|
||||||
@ -460,14 +479,16 @@ static void *qnx_input_init(void)
|
|||||||
for (i = 0; i < MAX_TOUCH; ++i)
|
for (i = 0; i < MAX_TOUCH; ++i)
|
||||||
touch[i].contact_id = -1;
|
touch[i].contact_id = -1;
|
||||||
|
|
||||||
#ifdef HAVE_BB10
|
|
||||||
for (i = 0; i < MAX_PADS; ++i)
|
for (i = 0; i < MAX_PADS; ++i)
|
||||||
initController(&devices[i]);
|
initController(&devices[i]);
|
||||||
|
#ifdef HAVE_BB10
|
||||||
pads_connected = 0;
|
pads_connected = 0;
|
||||||
|
|
||||||
//Find currently connected gamepads
|
//Find currently connected gamepads
|
||||||
discoverControllers();
|
discoverControllers();
|
||||||
|
#else
|
||||||
|
init_playbook_keyboard();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (void*)-1;
|
return (void*)-1;
|
||||||
@ -508,13 +529,14 @@ static int16_t qnx_input_state(void *data, const struct retro_keybind **retro_ke
|
|||||||
|
|
||||||
switch (device)
|
switch (device)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_BB10
|
|
||||||
case RETRO_DEVICE_JOYPAD:
|
case RETRO_DEVICE_JOYPAD:
|
||||||
if (g_settings.input.device[port] == DEVICE_KEYBOARD)
|
if (g_settings.input.device[port] == DEVICE_KEYBOARD)
|
||||||
|
{
|
||||||
return ((devices[port].buttons & (1 << id)) && (port < pads_connected));
|
return ((devices[port].buttons & (1 << id)) && (port < pads_connected));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return ((devices[port].buttons & retro_keybinds[port][id].joykey) && (port < pads_connected));
|
return ((devices[port].buttons & retro_keybinds[port][id].joykey) && (port < pads_connected));
|
||||||
|
#ifdef HAVE_BB10
|
||||||
case RETRO_DEVICE_ANALOG:
|
case RETRO_DEVICE_ANALOG:
|
||||||
//Need to return [-0x8000, 0x7fff]
|
//Need to return [-0x8000, 0x7fff]
|
||||||
//Gamepad API gives us [-128, 127] with (0,0) center
|
//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))
|
if (keybind_action & (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BIND))
|
||||||
*key = g_settings.input.binds[port][id].def_joykey;
|
*key = g_settings.input.binds[port][id].def_joykey;
|
||||||
|
#endif
|
||||||
if (keybind_action & (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS))
|
if (keybind_action & (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS))
|
||||||
{
|
{
|
||||||
switch (device)
|
switch (device)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_BB10
|
||||||
case DEVICE_WIIMOTE:
|
case DEVICE_WIIMOTE:
|
||||||
strlcpy(g_settings.input.device_names[port], "Wiimote",
|
strlcpy(g_settings.input.device_names[port], "Wiimote",
|
||||||
sizeof(g_settings.input.device_names[port]));
|
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.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = SCREEN_R3_GAME_BUTTON;
|
||||||
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_NONE;
|
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_NONE;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case DEVICE_KEYBOARD:
|
case DEVICE_KEYBOARD:
|
||||||
strlcpy(g_settings.input.device_names[port], "BlackBerry BT Keyboard",
|
strlcpy(g_settings.input.device_names[port], "BlackBerry BT Keyboard",
|
||||||
sizeof(g_settings.input.device_names[port]));
|
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.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = 0;
|
||||||
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_NONE;
|
g_settings.input.dpad_emulation[port] = ANALOG_DPAD_NONE;
|
||||||
break;
|
break;
|
||||||
|
#ifdef HAVE_BB10
|
||||||
case DEVICE_UNKNOWN:
|
case DEVICE_UNKNOWN:
|
||||||
strlcpy(g_settings.input.device_names[port], "Unknown",
|
strlcpy(g_settings.input.device_names[port], "Unknown",
|
||||||
sizeof(g_settings.input.device_names[port]));
|
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_L3].def_joykey = 0;
|
||||||
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = 0;
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = 0;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++)
|
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
|
//TODO: Handle keyboard mappings
|
||||||
if (keybind_action & (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL))
|
if (keybind_action & (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user