(input) Namespace functions

This commit is contained in:
twinaphex 2015-04-03 01:37:20 +02:00
parent 5eeee04acf
commit 5fd1ff826a
4 changed files with 91 additions and 92 deletions

View File

@ -261,7 +261,7 @@ static void wiimote_pressed_buttons(struct wiimote_t* wm, uint8_t* msg)
wm->btns = now;
}
static int classic_ctrl_handshake(struct wiimote_t* wm,
static int wiimote_classic_ctrl_handshake(struct wiimote_t* wm,
struct classic_ctrl_t* cc, uint8_t* data, uint16_t len)
{
memset(cc, 0, sizeof(*cc));
@ -269,14 +269,14 @@ static int classic_ctrl_handshake(struct wiimote_t* wm,
return 1;
}
static float normalize_and_interpolate(float min, float max, float t)
static float wiimote_normalize_and_interpolate(float min, float max, float t)
{
if (min == max)
return 0.0f;
return (t - min) / (max - min);
}
static void process_axis(struct axis_t* axis, uint8_t raw)
static void wiimote_process_axis(struct axis_t* axis, uint8_t raw)
{
if (!axis->has_center)
{
@ -293,10 +293,10 @@ static void process_axis(struct axis_t* axis, uint8_t raw)
axis->raw_value = raw;
if (raw < axis->center)
axis->value = -normalize_and_interpolate(
axis->value = -wiimote_normalize_and_interpolate(
axis->center, axis->min, raw);
else if (raw > axis->center)
axis->value = normalize_and_interpolate(
axis->value = wiimote_normalize_and_interpolate(
axis->center, axis->max, raw);
else
axis->value = 0;
@ -309,11 +309,11 @@ static void classic_ctrl_event(struct classic_ctrl_t* cc, uint8_t* msg)
cc->btns = ~swap_if_little16(*(int16_t*)(msg + 4)) & CLASSIC_CTRL_BUTTON_ALL;
process_axis(&cc->ljs.x, (msg[0] & 0x3F));
process_axis(&cc->ljs.y, (msg[1] & 0x3F));
process_axis(&cc->rjs.x, ((msg[0] & 0xC0) >> 3) |
wiimote_process_axis(&cc->ljs.x, (msg[0] & 0x3F));
wiimote_process_axis(&cc->ljs.y, (msg[1] & 0x3F));
wiimote_process_axis(&cc->rjs.x, ((msg[0] & 0xC0) >> 3) |
((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7));
process_axis(&cc->rjs.y, (msg[2] & 0x1F));
wiimote_process_axis(&cc->rjs.y, (msg[2] & 0x1F));
}
/*
@ -578,7 +578,7 @@ static int wiimote_handshake(struct wiimote_t* wm,
if(event != WM_RPT_READ)
return 0;
classic_ctrl_handshake(wm, &wm->exp.cc.classic, data,len);
wiimote_classic_ctrl_handshake(wm, &wm->exp.cc.classic, data,len);
wm->handshake_state = 3;
continue;
case 6:

View File

@ -205,7 +205,7 @@ static void parport_joypad_poll(void)
}
}
static void destroy_pad(struct parport_joypad *pad)
static void parport_free_pad(struct parport_joypad *pad)
{
char data = pad->saved_data;
@ -295,7 +295,7 @@ static bool parport_joypad_init(void)
else
{
RARCH_WARN("[Joypad]: All pins low on %s, assuming nothing connected\n", path);
destroy_pad(pad);
parport_free_pad(pad);
}
}
input_config_autoconfigure_joypad(&params);
@ -313,9 +313,7 @@ static void parport_joypad_destroy(void)
{
pad = (struct parport_joypad*)&parport_pads[i];
if (pad->fd >= 0)
{
destroy_pad(pad);
}
parport_free_pad(pad);
}
memset(parport_pads, 0, sizeof(parport_pads));
for (i = 0; i < MAX_USERS; i++)

View File

@ -74,7 +74,7 @@ static struct udev *g_udev;
static struct udev_monitor *g_udev_mon;
static struct udev_joypad udev_pads[MAX_USERS];
static INLINE int16_t compute_axis(const struct input_absinfo *info, int value)
static INLINE int16_t udev_compute_axis(const struct input_absinfo *info, int value)
{
int range = info->maximum - info->minimum;
int axis = (value - info->minimum) * 0xffffll / range - 0x7fffll;
@ -127,15 +127,15 @@ static void udev_poll_pad(struct udev_joypad *pad, unsigned p)
case ABS_HAT3X:
case ABS_HAT3Y:
{
code -= ABS_HAT0X;
pad->hats[code >> 1][code & 1] = events[i].value;
code -= ABS_HAT0X;
pad->hats[code >> 1][code & 1] = events[i].value;
break;
}
default:
{
unsigned axis = pad->axes_bind[code];
pad->axes[axis] = compute_axis(&pad->absinfo[axis], events[i].value);
unsigned axis = pad->axes_bind[code];
pad->axes[axis] = udev_compute_axis(&pad->absinfo[axis], events[i].value);
break;
}
}
@ -148,7 +148,7 @@ static void udev_poll_pad(struct udev_joypad *pad, unsigned p)
}
}
static bool hotplug_available(void)
static bool udev_hotplug_available(void)
{
struct pollfd fds = {0};
@ -159,7 +159,8 @@ static bool hotplug_available(void)
return (poll(&fds, 1, 0) == 1) && (fds.revents & POLLIN);
}
static void check_device(struct udev_device *dev, const char *path, bool hotplugged);
static void udev_check_device(struct udev_device *dev, const char *path, bool hotplugged);
static void udev_joypad_remove_device(const char *path);
static void udev_joypad_handle_hotplug(void)
@ -178,7 +179,7 @@ static void udev_joypad_handle_hotplug(void)
if (!strcmp(action, "add"))
{
RARCH_LOG("[udev]: Hotplug add: %s.\n", devnode);
check_device(dev, devnode, true);
udev_check_device(dev, devnode, true);
}
else if (!strcmp(action, "remove"))
{
@ -264,7 +265,7 @@ static bool udev_set_rumble(unsigned i, enum retro_rumble_effect effect, uint16_
static void udev_joypad_poll(void)
{
unsigned i;
while (hotplug_available())
while (udev_hotplug_available())
udev_joypad_handle_hotplug();
for (i = 0; i < MAX_USERS; i++)
@ -275,7 +276,7 @@ static void udev_joypad_poll(void)
(((1UL << ((nr) % (sizeof(long) * CHAR_BIT))) & ((addr)[(nr) / (sizeof(long) * CHAR_BIT)])) != 0)
#define NBITS(x) ((((x) - 1) / (sizeof(long) * CHAR_BIT)) + 1)
static int open_joystick(const char *path)
static int udev_open_joystick(const char *path)
{
unsigned long evbit[NBITS(EV_MAX)] = {0};
unsigned long keybit[NBITS(KEY_MAX)] = {0};
@ -301,7 +302,7 @@ error:
return -1;
}
static int find_vacant_pad(void)
static int udev_find_vacant_pad(void)
{
unsigned i;
@ -311,7 +312,7 @@ static int find_vacant_pad(void)
return -1;
}
static void free_pad(unsigned pad, bool hotplug)
static void udev_free_pad(unsigned pad, bool hotplug)
{
settings_t *settings = config_get_ptr();
autoconfig_params_t params = {{0}};
@ -336,7 +337,7 @@ static void free_pad(unsigned pad, bool hotplug)
}
}
static bool add_pad(struct udev_device *dev, unsigned p, int fd, const char *path)
static bool udev_add_pad(struct udev_device *dev, unsigned p, int fd, const char *path)
{
int i;
const char *buf;
@ -404,7 +405,7 @@ static bool add_pad(struct udev_device *dev, unsigned p, int fd, const char *pat
continue;
if (abs->maximum > abs->minimum)
{
pad->axes[axes] = compute_axis(abs, abs->value);
pad->axes[axes] = udev_compute_axis(abs, abs->value);
pad->axes_bind[i] = axes++;
}
}
@ -438,7 +439,7 @@ static bool add_pad(struct udev_device *dev, unsigned p, int fd, const char *pat
return true;
}
static void check_device(struct udev_device *dev, const char *path, bool hotplugged)
static void udev_check_device(struct udev_device *dev, const char *path, bool hotplugged)
{
int pad, fd;
unsigned i;
@ -456,15 +457,15 @@ static void check_device(struct udev_device *dev, const char *path, bool hotplug
}
}
pad = find_vacant_pad();
pad = udev_find_vacant_pad();
if (pad < 0)
return;
fd = open_joystick(path);
fd = udev_open_joystick(path);
if (fd < 0)
return;
if (add_pad(dev, pad, fd, path))
if (udev_add_pad(dev, pad, fd, path))
{
#ifndef IS_JOYCONFIG
if (hotplugged)
@ -499,7 +500,7 @@ static void udev_joypad_remove_device(const char *path)
rarch_main_msg_queue_push(msg, 0, 60, false);
RARCH_LOG("[udev]: %s\n", msg);
#endif
free_pad(i, true);
udev_free_pad(i, true);
break;
}
}
@ -510,7 +511,7 @@ static void udev_joypad_destroy(void)
unsigned i;
for (i = 0; i < MAX_USERS; i++)
free_pad(i, false);
udev_free_pad(i, false);
if (g_udev_mon)
udev_monitor_unref(g_udev_mon);
@ -560,7 +561,7 @@ static bool udev_joypad_init(void)
const char *devnode = udev_device_get_devnode(dev);
if (devnode)
check_device(dev, devnode, false);
udev_check_device(dev, devnode, false);
udev_device_unref(dev);
}

View File

@ -101,7 +101,7 @@ extern int g_xinput_pad_indexes[MAX_USERS];
extern bool g_xinput_block_pads;
/* For xinput1_n.dll */
static HINSTANCE g_winxinput_dll;
static HINSTANCE g_xinput_dll;
/* Function pointer, to be assigned with GetProcAddress */
typedef uint32_t (__stdcall *XInputGetStateEx_t)(uint32_t, XINPUT_STATE*);
@ -111,17 +111,17 @@ typedef uint32_t (__stdcall *XInputSetState_t)(uint32_t, XINPUT_VIBRATION*);
static XInputSetState_t g_XInputSetState;
/* Guide button may or may not be available */
static bool g_winxinput_guide_button_supported;
static bool g_xinput_guide_button_supported;
typedef struct
{
XINPUT_STATE xstate;
bool connected;
} winxinput_joypad_state;
} xinput_joypad_state;
static XINPUT_VIBRATION g_xinput_rumble_states[4];
static winxinput_joypad_state g_winxinput_states[4];
static xinput_joypad_state g_xinput_states[4];
static INLINE int pad_index_to_xuser_index(unsigned pad)
{
@ -139,7 +139,7 @@ static const char* const XBOX_CONTROLLER_NAMES[4] =
"XInput Controller (User 4)"
};
const char* winxinput_joypad_name (unsigned pad)
const char *xinput_joypad_name(unsigned pad)
{
int xuser = pad_index_to_xuser_index(pad);
@ -149,14 +149,14 @@ const char* winxinput_joypad_name (unsigned pad)
return XBOX_CONTROLLER_NAMES[xuser];
}
static bool winxinput_joypad_init(void)
static bool xinput_joypad_init(void)
{
unsigned i, autoconf_pad;
XINPUT_STATE dummy_state;
const char *version = "1.4";
settings_t *settings = config_get_ptr();
g_winxinput_dll = NULL;
g_xinput_dll = NULL;
/* Find the correct path to load the DLL from.
* Usually this will be from the system directory,
@ -169,14 +169,14 @@ static bool winxinput_joypad_init(void)
*/
/* Using dylib_* complicates building joyconfig. */
g_winxinput_dll = LoadLibrary("xinput1_4.dll");
if (!g_winxinput_dll)
g_xinput_dll = LoadLibrary("xinput1_4.dll");
if (!g_xinput_dll)
{
g_winxinput_dll = LoadLibrary("xinput1_3.dll");
g_xinput_dll = LoadLibrary("xinput1_3.dll");
version = "1.3";
}
if (!g_winxinput_dll)
if (!g_xinput_dll)
{
RARCH_ERR("Failed to load XInput, ensure DirectX and controller drivers are up to date.\n");
return false;
@ -187,50 +187,50 @@ static bool winxinput_joypad_init(void)
/* If we get here then an xinput DLL is correctly loaded.
* First try to load ordinal 100 (XInputGetStateEx).
*/
g_XInputGetStateEx = (XInputGetStateEx_t) GetProcAddress(g_winxinput_dll, (const char*)100);
g_winxinput_guide_button_supported = true;
g_XInputGetStateEx = (XInputGetStateEx_t) GetProcAddress(g_xinput_dll, (const char*)100);
g_xinput_guide_button_supported = true;
if (!g_XInputGetStateEx)
{
/* no ordinal 100. (Presumably a wrapper.) Load the ordinary
* XInputGetState, at the cost of losing guide button support.
*/
g_winxinput_guide_button_supported = false;
g_XInputGetStateEx = (XInputGetStateEx_t) GetProcAddress(g_winxinput_dll, "XInputGetState");
g_xinput_guide_button_supported = false;
g_XInputGetStateEx = (XInputGetStateEx_t) GetProcAddress(g_xinput_dll, "XInputGetState");
if (!g_XInputGetStateEx)
{
RARCH_ERR("Failed to init XInput: DLL is invalid or corrupt.\n");
FreeLibrary(g_winxinput_dll);
FreeLibrary(g_xinput_dll);
return false; /* DLL was loaded but did not contain the correct function. */
}
RARCH_WARN("XInput: No guide button support.\n");
}
g_XInputSetState = (XInputSetState_t) GetProcAddress(g_winxinput_dll, "XInputSetState");
g_XInputSetState = (XInputSetState_t) GetProcAddress(g_xinput_dll, "XInputSetState");
if (!g_XInputSetState)
{
RARCH_ERR("Failed to init XInput: DLL is invalid or corrupt.\n");
FreeLibrary(g_winxinput_dll);
FreeLibrary(g_xinput_dll);
return false; /* DLL was loaded but did not contain the correct function. */
}
/* Zero out the states. */
for (i = 0; i < 4; ++i)
memset(&g_winxinput_states[i], 0, sizeof(winxinput_joypad_state));
memset(&g_xinput_states[i], 0, sizeof(xinput_joypad_state));
/* Do a dummy poll to check which controllers are connected. */
for (i = 0; i < 4; ++i)
{
g_winxinput_states[i].connected = !(g_XInputGetStateEx(i, &dummy_state) == ERROR_DEVICE_NOT_CONNECTED);
if (g_winxinput_states[i].connected)
g_xinput_states[i].connected = !(g_XInputGetStateEx(i, &dummy_state) == ERROR_DEVICE_NOT_CONNECTED);
if (g_xinput_states[i].connected)
RARCH_LOG("Found XInput controller, user #%u\n", i);
}
if ((!g_winxinput_states[0].connected) &&
(!g_winxinput_states[1].connected) &&
(!g_winxinput_states[2].connected) &&
(!g_winxinput_states[3].connected))
if ((!g_xinput_states[0].connected) &&
(!g_xinput_states[1].connected) &&
(!g_xinput_states[2].connected) &&
(!g_xinput_states[3].connected))
return false;
g_xinput_block_pads = true;
@ -250,13 +250,13 @@ static bool winxinput_joypad_init(void)
autoconfig_params_t params = {{0}};
strlcpy(settings->input.device_names[autoconf_pad],
winxinput_joypad_name(autoconf_pad),
xinput_joypad_name(autoconf_pad),
sizeof(settings->input.device_names[autoconf_pad]));
/* TODO - implement VID/PID? */
params.idx = autoconf_pad;
strlcpy(params.name, winxinput_joypad_name(autoconf_pad), sizeof(params.name));
strlcpy(params.driver, winxinput_joypad.ident, sizeof(params.driver));
strlcpy(params.name, xinput_joypad_name(autoconf_pad), sizeof(params.name));
strlcpy(params.driver, xinput_joypad.ident, sizeof(params.driver));
input_config_autoconfigure_joypad(&params);
}
}
@ -264,24 +264,24 @@ static bool winxinput_joypad_init(void)
return true;
}
static bool winxinput_joypad_query_pad(unsigned pad)
static bool xinput_joypad_query_pad(unsigned pad)
{
int xuser = pad_index_to_xuser_index(pad);
if (xuser > -1)
return g_winxinput_states[xuser].connected;
return g_xinput_states[xuser].connected;
return dinput_joypad.query_pad(pad);
}
static void winxinput_joypad_destroy(void)
static void xinput_joypad_destroy(void)
{
unsigned i;
for (i = 0; i < 4; ++i)
memset(&g_winxinput_states[i], 0, sizeof(winxinput_joypad_state));
memset(&g_xinput_states[i], 0, sizeof(xinput_joypad_state));
FreeLibrary(g_winxinput_dll);
FreeLibrary(g_xinput_dll);
g_winxinput_dll = NULL;
g_xinput_dll = NULL;
g_XInputGetStateEx = NULL;
g_XInputSetState = NULL;
@ -306,7 +306,7 @@ static const uint16_t button_index_to_bitmap_code[] = {
XINPUT_GAMEPAD_GUIDE
};
static bool winxinput_joypad_button(unsigned port_num, uint16_t joykey)
static bool xinput_joypad_button(unsigned port_num, uint16_t joykey)
{
uint16_t btn_word;
int xuser;
@ -319,10 +319,10 @@ static bool winxinput_joypad_button(unsigned port_num, uint16_t joykey)
if (xuser == -1)
return dinput_joypad.button(port_num, joykey);
if (!(g_winxinput_states[xuser].connected))
if (!(g_xinput_states[xuser].connected))
return false;
btn_word = g_winxinput_states[xuser].xstate.Gamepad.wButtons;
btn_word = g_xinput_states[xuser].xstate.Gamepad.wButtons;
if (GET_HAT_DIR(joykey))
{
@ -341,7 +341,7 @@ static bool winxinput_joypad_button(unsigned port_num, uint16_t joykey)
}
/* non-hat button. */
num_buttons = g_winxinput_guide_button_supported ? 11 : 10;
num_buttons = g_xinput_guide_button_supported ? 11 : 10;
if (joykey < num_buttons)
return btn_word & button_index_to_bitmap_code[joykey];
@ -349,7 +349,7 @@ static bool winxinput_joypad_button(unsigned port_num, uint16_t joykey)
return false;
}
static int16_t winxinput_joypad_axis (unsigned port_num, uint32_t joyaxis)
static int16_t xinput_joypad_axis (unsigned port_num, uint32_t joyaxis)
{
int xuser;
int16_t val = 0;
@ -366,7 +366,7 @@ static int16_t winxinput_joypad_axis (unsigned port_num, uint32_t joyaxis)
if (xuser == -1)
return dinput_joypad.axis(port_num, joyaxis);
if (!(g_winxinput_states[xuser].connected))
if (!(g_xinput_states[xuser].connected))
return 0;
/* triggers (axes 4,5) cannot be negative */
@ -381,7 +381,7 @@ static int16_t winxinput_joypad_axis (unsigned port_num, uint32_t joyaxis)
is_pos = true;
}
XINPUT_GAMEPAD* pad = &(g_winxinput_states[xuser].xstate.Gamepad);
XINPUT_GAMEPAD* pad = &(g_xinput_states[xuser].xstate.Gamepad);
switch (axis)
{
@ -417,25 +417,25 @@ static int16_t winxinput_joypad_axis (unsigned port_num, uint32_t joyaxis)
return val;
}
static void winxinput_joypad_poll(void)
static void xinput_joypad_poll(void)
{
unsigned i;
for (i = 0; i < 4; ++i)
{
if (g_winxinput_states[i].connected)
if (g_xinput_states[i].connected)
{
if (g_XInputGetStateEx(i,
&(g_winxinput_states[i].xstate))
&(g_xinput_states[i].xstate))
== ERROR_DEVICE_NOT_CONNECTED)
g_winxinput_states[i].connected = false;
g_xinput_states[i].connected = false;
}
}
dinput_joypad.poll();
}
static bool winxinput_joypad_rumble(unsigned pad,
static bool xinput_joypad_rumble(unsigned pad,
enum retro_rumble_effect effect, uint16_t strength)
{
int xuser = pad_index_to_xuser_index(pad);
@ -457,15 +457,15 @@ static bool winxinput_joypad_rumble(unsigned pad,
== ERROR_SUCCESS;
}
rarch_joypad_driver_t winxinput_joypad = {
winxinput_joypad_init,
winxinput_joypad_query_pad,
winxinput_joypad_destroy,
winxinput_joypad_button,
rarch_joypad_driver_t xinput_joypad = {
xinput_joypad_init,
xinput_joypad_query_pad,
xinput_joypad_destroy,
xinput_joypad_button,
NULL,
winxinput_joypad_axis,
winxinput_joypad_poll,
winxinput_joypad_rumble,
winxinput_joypad_name,
"winxinput",
xinput_joypad_axis,
xinput_joypad_poll,
xinput_joypad_rumble,
xinput_joypad_name,
"xinput",
};