(joypad_connection.c) Cleanups
This commit is contained in:
parent
4c7c1094e2
commit
b263df08f6
|
@ -21,9 +21,12 @@ int pad_connection_find_vacant_pad(joypad_connection_t *joyconn)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
|
if (!joyconn)
|
||||||
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < MAX_USERS; i++)
|
for (i = 0; i < MAX_USERS; i++)
|
||||||
{
|
{
|
||||||
joypad_connection_t *conn = joyconn ? (joypad_connection_t*)&joyconn[i] : NULL;
|
joypad_connection_t *conn = &joyconn[i];
|
||||||
|
|
||||||
if (conn && !conn->connected)
|
if (conn && !conn->connected)
|
||||||
return i;
|
return i;
|
||||||
|
@ -66,6 +69,7 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn,
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
joypad_connection_t* s = (joypad_connection_t*)&joyconn[pad];
|
joypad_connection_t* s = (joypad_connection_t*)&joyconn[pad];
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
{
|
{
|
||||||
const char* name;
|
const char* name;
|
||||||
|
@ -104,51 +108,51 @@ int32_t pad_connection_pad_init(joypad_connection_t *joyconn,
|
||||||
return pad;
|
return pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pad_connection_pad_deinit(joypad_connection_t *s, uint32_t pad)
|
void pad_connection_pad_deinit(joypad_connection_t *joyconn, uint32_t pad)
|
||||||
{
|
{
|
||||||
if (!s || !s->connected)
|
if (!joyconn || !joyconn->connected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (s->iface)
|
if (joyconn->iface)
|
||||||
{
|
{
|
||||||
s->iface->set_rumble(s->data, RETRO_RUMBLE_STRONG, 0);
|
joyconn->iface->set_rumble(joyconn->data, RETRO_RUMBLE_STRONG, 0);
|
||||||
s->iface->set_rumble(s->data, RETRO_RUMBLE_WEAK, 0);
|
joyconn->iface->set_rumble(joyconn->data, RETRO_RUMBLE_WEAK, 0);
|
||||||
|
|
||||||
if (s->iface->deinit)
|
if (joyconn->iface->deinit)
|
||||||
s->iface->deinit(s->data);
|
joyconn->iface->deinit(joyconn->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
s->iface = NULL;
|
joyconn->iface = NULL;
|
||||||
s->connected = false;
|
joyconn->connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pad_connection_packet(joypad_connection_t *s, uint32_t pad,
|
void pad_connection_packet(joypad_connection_t *joyconn, uint32_t pad,
|
||||||
uint8_t* data, uint32_t length)
|
uint8_t* data, uint32_t length)
|
||||||
{
|
{
|
||||||
if (!s->connected)
|
if (!joyconn->connected)
|
||||||
return;
|
return;
|
||||||
if (s->iface && s->data && s->iface->packet_handler)
|
if (joyconn->iface && joyconn->data && joyconn->iface->packet_handler)
|
||||||
s->iface->packet_handler(s->data, data, length);
|
joyconn->iface->packet_handler(joyconn->data, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t pad_connection_get_buttons(joypad_connection_t *s, unsigned pad)
|
uint64_t pad_connection_get_buttons(joypad_connection_t *joyconn, unsigned pad)
|
||||||
{
|
{
|
||||||
if (!s->iface)
|
if (!joyconn->iface)
|
||||||
return 0;
|
return 0;
|
||||||
return s->iface->get_buttons(s->data);
|
return joyconn->iface->get_buttons(joyconn->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t pad_connection_get_axis(joypad_connection_t *s,
|
int16_t pad_connection_get_axis(joypad_connection_t *joyconn,
|
||||||
unsigned idx, unsigned i)
|
unsigned idx, unsigned i)
|
||||||
{
|
{
|
||||||
if (!s->iface)
|
if (!joyconn->iface)
|
||||||
return 0;
|
return 0;
|
||||||
return s->iface->get_axis(s->data, i);
|
return joyconn->iface->get_axis(joyconn->data, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pad_connection_has_interface(joypad_connection_t *s, unsigned pad)
|
bool pad_connection_has_interface(joypad_connection_t *joyconn, unsigned pad)
|
||||||
{
|
{
|
||||||
if (s && s->connected && s->iface)
|
if (joyconn && joyconn->connected && joyconn->iface)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -158,22 +162,19 @@ void pad_connection_destroy(joypad_connection_t *joyconn)
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_USERS; i ++)
|
for (i = 0; i < MAX_USERS; i ++)
|
||||||
{
|
pad_connection_pad_deinit(&joyconn[i], i);
|
||||||
joypad_connection_t *s = (joypad_connection_t*)&joyconn[i];
|
|
||||||
pad_connection_pad_deinit(s, i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pad_connection_rumble(joypad_connection_t *s,
|
bool pad_connection_rumble(joypad_connection_t *joyconn,
|
||||||
unsigned pad, enum retro_rumble_effect effect, uint16_t strength)
|
unsigned pad, enum retro_rumble_effect effect, uint16_t strength)
|
||||||
{
|
{
|
||||||
if (!s->connected)
|
if (!joyconn->connected)
|
||||||
return false;
|
return false;
|
||||||
if (!s->iface)
|
if (!joyconn->iface)
|
||||||
return false;
|
return false;
|
||||||
if (!s->iface->set_rumble)
|
if (!joyconn->iface->set_rumble)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
s->iface->set_rumble(s->data, effect, strength);
|
joyconn->iface->set_rumble(joyconn->data, effect, strength);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue