(input/connect) Style nits

This commit is contained in:
twinaphex 2021-10-06 02:52:19 +02:00
parent f81a231481
commit 55bf2b0083
8 changed files with 170 additions and 176 deletions

View File

@ -30,10 +30,11 @@ struct hidpad_nesusb_data
uint32_t buttons;
};
static void* hidpad_nesusb_init(void *data, uint32_t slot, hid_driver_t *driver)
static void* hidpad_nesusb_init(void *data,
uint32_t slot, hid_driver_t *driver)
{
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_nesusb_data* device = (struct hidpad_nesusb_data*)
struct hidpad_nesusb_data* device = (struct hidpad_nesusb_data*)
calloc(1, sizeof(struct hidpad_nesusb_data));
if (!device)
@ -86,7 +87,8 @@ static int16_t hidpad_nesusb_get_axis(void *data, unsigned axis)
return 0;
}
static void hidpad_nesusb_packet_handler(void *data, uint8_t *packet, uint16_t size)
static void hidpad_nesusb_packet_handler(void *data,
uint8_t *packet, uint16_t size)
{
uint32_t i, pressed_keys;
static const uint32_t button_mapping[17] =
@ -116,8 +118,7 @@ static void hidpad_nesusb_packet_handler(void *data, uint8_t *packet, uint16_t s
memcpy(device->data, packet, size);
device->buttons = 0;
pressed_keys = device->data[7] | (device->data[6] << 8);
pressed_keys = device->data[7] | (device->data[6] << 8);
for (i = 0; i < 16; i ++)
if (button_mapping[i] != NO_BTN)
@ -134,14 +135,14 @@ static void hidpad_nesusb_set_rumble(void *data,
const char * hidpad_nesusb_get_name(void *data)
{
(void)data;
/* For now we return a single static name */
return "Generic NES USB Controller";
(void)data;
/* For now we return a single static name */
return "Generic NES USB Controller";
}
static int32_t hidpad_nesusb_button(void *data, uint16_t joykey)
{
struct hidpad_nesusb_data *pad = (struct hidpad_nesusb_data*)data;
struct hidpad_nesusb_data *pad = (struct hidpad_nesusb_data*)data;
if (!pad || joykey > 31)
return 0;
return pad->buttons & (1 << joykey);

View File

@ -32,8 +32,8 @@ struct hidpad_ps2adapter_data
static void* hidpad_ps2adapter_init(void *data, uint32_t slot, hid_driver_t *driver)
{
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_ps2adapter_data* device = (struct hidpad_ps2adapter_data*)
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_ps2adapter_data* device = (struct hidpad_ps2adapter_data*)
calloc(1, sizeof(struct hidpad_ps2adapter_data));
if (!device)
@ -53,7 +53,8 @@ static void* hidpad_ps2adapter_init(void *data, uint32_t slot, hid_driver_t *dri
static void hidpad_ps2adapter_deinit(void *data)
{
struct hidpad_ps2adapter_data *device = (struct hidpad_ps2adapter_data*)data;
struct hidpad_ps2adapter_data *device =
(struct hidpad_ps2adapter_data*)data;
if (device)
free(device);
@ -61,8 +62,8 @@ static void hidpad_ps2adapter_deinit(void *data)
static void hidpad_ps2adapter_get_buttons(void *data, input_bits_t *state)
{
struct hidpad_ps2adapter_data *device = (struct hidpad_ps2adapter_data*)
data;
struct hidpad_ps2adapter_data *device =
(struct hidpad_ps2adapter_data*)data;
if (device)
{
@ -137,7 +138,8 @@ static void hidpad_ps2adapter_packet_handler(void *data, uint8_t *packet, uint16
if (!device)
return;
/* Check if the data corresponds to the first controller, exit otherwise */
/* Check if the data corresponds to the first controller,
* exit otherwise */
if (packet[1] != 1)
return;
@ -153,10 +155,10 @@ static void hidpad_ps2adapter_packet_handler(void *data, uint8_t *packet, uint16
/* Now process the hat values as if they were pad buttons */
hat_value = PS2_H_GET(device->data[6]);
device->buttons |= PS2_H_LEFT(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
device->buttons |= PS2_H_LEFT(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
device->buttons |= PS2_H_RIGHT(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
device->buttons |= PS2_H_UP(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
device->buttons |= PS2_H_DOWN(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
device->buttons |= PS2_H_UP(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
device->buttons |= PS2_H_DOWN(hat_value) ? (UINT64_C(1) << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
}
static void hidpad_ps2adapter_set_rumble(void *data,

View File

@ -26,7 +26,8 @@
#define DS3_ACTIVATION_REPORT_ID 0xf4
#define DS3_RUMBLE_REPORT_ID 0x01
typedef struct ds3_instance {
typedef struct ds3_instance
{
hid_driver_t *hid_driver;
void *handle;
int slot;
@ -40,13 +41,14 @@ typedef struct ds3_instance {
static void ds3_update_pad_state(ds3_instance_t *instance);
static void ds3_update_analog_state(ds3_instance_t *instance);
static uint8_t ds3_activation_packet[] = {
static uint8_t ds3_activation_packet[] =
{
#if defined(IOS)
0x53, 0xF4,
0x53, 0xF4,
#elif defined(HAVE_WIIUSB_HID)
0x02,
0x02,
#endif
0x42, 0x0c, 0x00, 0x00
0x42, 0x0c, 0x00, 0x00
};
#if defined(WIIU)
@ -76,7 +78,9 @@ static uint8_t ds3_control_packet[] = {
};
static int32_t ds3_send_control_packet(void *data, uint32_t slot, hid_driver_t *driver) {
static int32_t ds3_send_control_packet(
void *data, uint32_t slot, hid_driver_t *driver)
{
int32_t result = 0;
uint8_t packet_buffer[64] = {0};
memcpy(packet_buffer, ds3_control_packet, sizeof(ds3_control_packet));
@ -98,19 +102,21 @@ static int32_t ds3_send_control_packet(void *data, uint32_t slot, hid_driver_t *
return result;
}
static int32_t ds3_send_activation_packet(void *data, uint32_t slot, hid_driver_t *driver) {
#ifdef WIIU
static int32_t ds3_send_activation_packet(void *data,
uint32_t slot, hid_driver_t *driver)
{
#ifdef WIIU
return driver->set_report(data, HID_REPORT_FEATURE, DS3_ACTIVATION_REPORT_ID, ds3_activation_packet, sizeof(ds3_activation_packet));
#else
#else
driver->send_control(data, ds3_activation_packet, sizeof(ds3_activation_packet));
return 0;
#endif
#endif
}
static void *ds3_pad_init(void *data, uint32_t slot, hid_driver_t *driver)
{
int errors = 0;
ds3_instance_t *instance = (ds3_instance_t *)calloc(1, sizeof(ds3_instance_t));
int errors = 0;
driver->set_protocol(data, 1);
@ -125,13 +131,13 @@ static void *ds3_pad_init(void *data, uint32_t slot, hid_driver_t *driver)
goto error;
instance->hid_driver = driver;
instance->handle = data;
instance->slot = slot;
instance->led_set = true;
instance->handle = data;
instance->slot = slot;
instance->led_set = true;
return instance;
error:
error:
free(instance);
return NULL;
}
@ -160,16 +166,17 @@ static void ds3_get_buttons(void *data, input_bits_t *state)
}
}
static void ds3_packet_handler(void *data, uint8_t *packet, uint16_t size)
static void ds3_packet_handler(void *data,
uint8_t *packet, uint16_t size)
{
ds3_instance_t *instance = (ds3_instance_t *)data;
if(!instance) {
if(!instance)
return;
}
if (!instance->led_set)
{
ds3_send_control_packet(instance->handle, instance->slot, instance->hid_driver);
ds3_send_control_packet(instance->handle,
instance->slot, instance->hid_driver);
instance->led_set = true;
}
@ -244,12 +251,12 @@ static void ds3_update_pad_state(ds3_instance_t *instance)
instance->buttons = 0;
pressed_keys = instance->data[2] |
(instance->data[3] << 8) |
((instance->data[4] & 0x01) << 16);
(instance->data[3] << 8) |
((instance->data[4] & 0x01) << 16);
for (i = 0; i < 17; i++)
instance->buttons |= (pressed_keys & (1 << i)) ?
(1 << button_mapping[i]) : 0;
instance->buttons |= (pressed_keys & (1 << i)) ?
(1 << button_mapping[i]) : 0;
}
static void ds3_update_analog_state(ds3_instance_t *instance)
@ -277,4 +284,4 @@ pad_connection_interface_t pad_connection_ps3 = {
ds3_get_name,
ds3_button,
false,
};
};

View File

@ -238,12 +238,12 @@ static void hidpad_ps4_get_buttons(void *data, input_bits_t* state)
static int16_t hidpad_ps4_get_axis(void *data, unsigned axis)
{
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
struct ps4 *rpt = device ? (struct ps4*)&device->data : NULL;
if (device && (axis < 4))
{
int val = rpt ? rpt->hatvalue[axis] : 0;
val = (val << 8) - 0x8000;
struct ps4 *rpt = device ? (struct ps4*)&device->data : NULL;
int val = rpt ? rpt->hatvalue[axis] : 0;
val = (val << 8) - 0x8000;
return (abs(val) > 0x1000) ? val : 0;
}
@ -288,12 +288,13 @@ static void hidpad_ps4_set_rumble(void *data,
static int32_t hidpad_ps4_button(void *data, uint16_t joykey)
{
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
struct ps4 *rpt = device ?
struct ps4 *rpt = device ?
(struct ps4*)&device->data : NULL;
if (!device || !rpt || joykey > 31)
return 0;
switch(joykey) {
switch (joykey)
{
case RETRO_DEVICE_ID_JOYPAD_R3:
return rpt->btn.r3;
case RETRO_DEVICE_ID_JOYPAD_L3:
@ -326,10 +327,11 @@ static int32_t hidpad_ps4_button(void *data, uint16_t joykey)
case RARCH_MENU_TOGGLE:
return rpt->btn.ps;
default:
return 0;
break;
}
}
return 0;
}
pad_connection_interface_t pad_connection_ps4 = {
hidpad_ps4_init,

View File

@ -32,8 +32,10 @@ struct hidpad_ps4_hori_mini_data
static void* hidpad_ps4_hori_mini_init(void *data, uint32_t slot, hid_driver_t *driver)
{
struct pad_connection *connection = (struct pad_connection*)data;
struct hidpad_ps4_hori_mini_data *device = (struct hidpad_ps4_hori_mini_data*)calloc(1, sizeof(struct hidpad_ps4_hori_mini_data));
struct pad_connection *connection = (struct pad_connection*)data;
struct hidpad_ps4_hori_mini_data *device =
(struct hidpad_ps4_hori_mini_data*)
calloc(1, sizeof(struct hidpad_ps4_hori_mini_data));
if (!device)
return NULL;
@ -59,9 +61,12 @@ static void hidpad_ps4_hori_mini_deinit(void *data)
free(device);
}
static void hidpad_ps4_hori_mini_get_buttons(void *data, input_bits_t *state)
static void hidpad_ps4_hori_mini_get_buttons(
void *data, input_bits_t *state)
{
struct hidpad_ps4_hori_mini_data *device = (struct hidpad_ps4_hori_mini_data*)data;
struct hidpad_ps4_hori_mini_data *device =
(struct hidpad_ps4_hori_mini_data*)data;
if ( device )
{
/* copy 32 bits : needed for PS button? */
@ -74,7 +79,8 @@ static void hidpad_ps4_hori_mini_get_buttons(void *data, input_bits_t *state)
static int16_t hidpad_ps4_hori_mini_get_axis(void *data, unsigned axis)
{
int val;
struct hidpad_ps4_hori_mini_data *device = (struct hidpad_ps4_hori_mini_data*)data;
struct hidpad_ps4_hori_mini_data *device =
(struct hidpad_ps4_hori_mini_data*)data;
if (!device || axis >= 4)
return 0;
@ -109,7 +115,8 @@ static void hidpad_ps4_hori_mini_packet_handler(void *data,
17,
18
};
struct hidpad_ps4_hori_mini_data *device = (struct hidpad_ps4_hori_mini_data*)data;
struct hidpad_ps4_hori_mini_data *device =
(struct hidpad_ps4_hori_mini_data*)data;
if (!device)
return;
@ -173,14 +180,15 @@ static void hidpad_ps4_hori_mini_set_rumble(void *data,
const char * hidpad_ps4_hori_mini_get_name(void *data)
{
(void)data;
/* For now we return a single static name */
return "HORI mini wired PS4";
(void)data;
/* For now we return a single static name */
return "HORI mini wired PS4";
}
static int32_t hidpad_ps4_hori_mini_button(void *data, uint16_t joykey)
{
struct hidpad_ps4_hori_mini_data *pad = (struct hidpad_ps4_hori_mini_data*)data;
struct hidpad_ps4_hori_mini_data *pad =
(struct hidpad_ps4_hori_mini_data*)data;
if (!pad || joykey > 31)
return 0;
return pad->buttons & (1 << joykey);

View File

@ -32,8 +32,8 @@ struct hidpad_psxadapter_data
static void* hidpad_psxadapter_init(void *data, uint32_t slot, hid_driver_t *driver)
{
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_psxadapter_data* device = (struct hidpad_psxadapter_data*)
struct pad_connection* connection = (struct pad_connection*)data;
struct hidpad_psxadapter_data* device = (struct hidpad_psxadapter_data*)
calloc(1, sizeof(struct hidpad_psxadapter_data));
if (!device)
@ -53,7 +53,8 @@ static void* hidpad_psxadapter_init(void *data, uint32_t slot, hid_driver_t *dri
static void hidpad_psxadapter_deinit(void *data)
{
struct hidpad_psxadapter_data *device = (struct hidpad_psxadapter_data*)data;
struct hidpad_psxadapter_data *device =
(struct hidpad_psxadapter_data*)data;
if (device)
free(device);
@ -61,24 +62,26 @@ static void hidpad_psxadapter_deinit(void *data)
static void hidpad_psxadapter_get_buttons(void *data, input_bits_t *state)
{
struct hidpad_psxadapter_data *device = (struct hidpad_psxadapter_data*)
data;
struct hidpad_psxadapter_data *device =
(struct hidpad_psxadapter_data*)data;
if (device)
if (device)
{
BITS_COPY16_PTR(state, device->buttons);
}
BITS_COPY16_PTR(state, device->buttons);
}
else
BIT256_CLEAR_ALL_PTR(state);
BIT256_CLEAR_ALL_PTR(state);
}
static int16_t hidpad_psxadapter_get_axis(void *data, unsigned axis)
{
int val = 0;
struct hidpad_psxadapter_data *device = (struct hidpad_psxadapter_data*)data;
struct hidpad_psxadapter_data *device =
(struct hidpad_psxadapter_data*)data;
if (!device || axis >= 4 ||
(device->data[2]==0x7F) ) /* digital mode detection */
if ( !device
|| axis >= 4
|| (device->data[2]==0x7F) ) /* digital mode detection */
return 0;
switch (axis)
@ -105,13 +108,14 @@ static int16_t hidpad_psxadapter_get_axis(void *data, unsigned axis)
return 0;
}
#define PSX_H_GET(a) (a & 0x0F) /*HAT MASK = 0x0F */
#define PSX_H_LEFT(a) (a == 0x05) || (a == 0x06) || (a == 0x07)
#define PSX_H_GET(a) (a & 0x0F) /*HAT MASK = 0x0F */
#define PSX_H_LEFT(a) (a == 0x05) || (a == 0x06) || (a == 0x07)
#define PSX_H_RIGHT(a) (a == 0x01) || (a == 0x02) || (a == 0x03)
#define PSX_H_UP(a) (a == 0x07) || (a == 0x00) || (a == 0x01)
#define PSX_H_DOWN(a) (a == 0x03) || (a == 0x04) || (a == 0x05)
#define PSX_H_UP(a) (a == 0x07) || (a == 0x00) || (a == 0x01)
#define PSX_H_DOWN(a) (a == 0x03) || (a == 0x04) || (a == 0x05)
static void hidpad_psxadapter_packet_handler(void *data, uint8_t *packet, uint16_t size)
static void hidpad_psxadapter_packet_handler(void *data,
uint8_t *packet, uint16_t size)
{
uint32_t i, pressed_keys;
int16_t hat_value;
@ -134,7 +138,8 @@ static void hidpad_psxadapter_packet_handler(void *data, uint8_t *packet, uint16
RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_Y,
};
struct hidpad_psxadapter_data *device = (struct hidpad_psxadapter_data*)data;
struct hidpad_psxadapter_data *device =
(struct hidpad_psxadapter_data*)data;
if (!device)
return;
@ -143,7 +148,7 @@ static void hidpad_psxadapter_packet_handler(void *data, uint8_t *packet, uint16
device->buttons = 0;
pressed_keys = device->data[7] | (device->data[6] << 8);
pressed_keys = device->data[7] | (device->data[6] << 8);
for (i = 0; i < 16; i ++)
if (button_mapping[i] != NO_BTN)
@ -185,7 +190,8 @@ const char * hidpad_psxadapter_get_name(void *data)
static int32_t hidpad_psxadapter_button(void *data, uint16_t joykey)
{
struct hidpad_psxadapter_data *pad = (struct hidpad_psxadapter_data*)data;
struct hidpad_psxadapter_data *pad =
(struct hidpad_psxadapter_data*)data;
if (!pad || joykey > 31)
return 0;
return pad->buttons & (1 << joykey);

View File

@ -187,14 +187,6 @@ static int wiimote_send(struct connect_wii_wiimote_t* wm,
memcpy(buf+2, msg, len);
#ifdef WIIMOTE_DBG
int x;
printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
for (x = 2; x < len+2; ++x)
printf("%.2x ", buf[x]);
printf("\n");
#endif
wm->driver->send_control(wm->connection, buf, len + 2);
return 1;
}
@ -211,10 +203,6 @@ static void wiimote_status(struct connect_wii_wiimote_t* wm)
if (!wm || !wiimote_is_connected(wm))
return;
#ifdef WIIMOTE_DBG
printf("Requested wiimote status.\n");
#endif
wiimote_send(wm, WM_CMD_CTRL_STATUS, &buf, 1);
}
@ -349,15 +337,6 @@ static int wiimote_write_data(struct connect_wii_wiimote_t* wm,
if (!data || !len)
return 0;
#ifdef WIIMOTE_DBG
int i = 0;
printf("Writing %i bytes to memory location 0x%x...\n", len, addr);
printf("Write data is: ");
for (; i < len; ++i)
printf("%x ", data[i]);
printf("\n");
#endif
/* the offset is in big endian */
*buf32 = swap_if_little32(addr);
@ -398,9 +377,6 @@ static int wiimote_read_data(struct connect_wii_wiimote_t* wm, uint32_t addr,
*buf32 = swap_if_little32(addr);
*buf16 = swap_if_little16(len);
#ifdef WIIMOTE_DBG
printf("Request read at address: 0x%x length: %i", addr, len);
#endif
wiimote_send(wm, WM_CMD_READ_DATA, buf, 6);
return 1;
@ -454,11 +430,6 @@ static int wiimote_handshake(struct connect_wii_wiimote_t* wm,
WM_CTRL_STATUS_BYTE1_ATTACHMENT)
attachment = 1;
#ifdef WIIMOTE_DBG
printf("attachment %d %d\n",attachment,
WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP));
#endif
if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
{
uint8_t buf = 0;
@ -512,9 +483,6 @@ static int wiimote_handshake(struct connect_wii_wiimote_t* wm,
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_HANDSHAKE_COMPLETE))
{
#ifdef WIIMOTE_DBG
printf("rehandshake\n");
#endif
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
/* forzamos un handshake por si venimos
* de un hanshake completo. */
@ -532,17 +500,11 @@ static int wiimote_handshake(struct connect_wii_wiimote_t* wm,
}
case 2:
/* Find handshake no expansion. */
#ifdef WIIMOTE_DBG
printf("Finalizado HANDSHAKE SIN EXPANSION\n");
#endif
wiimote_data_report(wm,WM_RPT_BTN);
wm->handshake_state = 6;
continue;
case 3:
/* Find handshake expansion. */
#ifdef WIIMOTE_DBG
printf("Finalizado HANDSHAKE CON EXPANSION\n");
#endif
wiimote_data_report(wm,WM_RPT_BTN_EXP);
wm->handshake_state = 6;
continue;
@ -674,13 +636,13 @@ static int16_t hidpad_wii_get_axis(void *data, unsigned axis)
static void hidpad_wii_get_buttons(void *data, input_bits_t *state)
{
struct connect_wii_wiimote_t* device = (struct connect_wii_wiimote_t*)data;
if ( device )
{
/* TODO/FIXME - Broken? this doesn't match retropad! */
uint32_t b = device->btns | (device->exp.cc.classic.btns << 16);
BITS_COPY32_PTR(state, b);
}
struct connect_wii_wiimote_t* device = (struct connect_wii_wiimote_t*)data;
if ( device )
{
/* TODO/FIXME - Broken? this doesn't match retropad! */
uint32_t b = device->btns | (device->exp.cc.classic.btns << 16);
BITS_COPY32_PTR(state, b);
}
}
static void hidpad_wii_packet_handler(void *data,

View File

@ -58,14 +58,14 @@ struct hidpad_wiiugca_data
const char *GAMECUBE_PAD = "GameCube controller";
const char *WAVEBIRD_PAD = "WaveBird controller";
const char *DEVICE_NAME = "Wii U GC Controller Adapter";
const char *DEVICE_NAME = "Wii U GC Controller Adapter";
static void* hidpad_wiiugca_init(void *data, uint32_t slot, hid_driver_t *driver)
{
#ifdef WIIU
static uint8_t magic_data[] = {0x13}; /* Special command to enable reading */
static uint8_t magic_data[] = {0x13 }; /* Special command to enable reading */
#else
static uint8_t magic_data[] = {0x01, 0x13}; /* Special command to enable reading */
static uint8_t magic_data[] = {0x01, 0x13}; /* Special command to enable reading */
#endif
int i;
gca_device_data_t * device = (gca_device_data_t *)calloc(1, sizeof(gca_device_data_t));
@ -79,15 +79,16 @@ static void* hidpad_wiiugca_init(void *data, uint32_t slot, hid_driver_t *driver
return NULL;
}
device->handle = data;
for(i = 0; i < GCA_MAX_PAD; i++) {
device->pad_data[i].datatype = GCA_TYPE_PAD;
device->handle = data;
for (i = 0; i < GCA_MAX_PAD; i++)
{
device->pad_data[i].datatype = GCA_TYPE_PAD;
device->pad_data[i].device_data = device;
device->pad_data[i].joypad = NULL;
device->pad_data[i].pad_index = i;
device->pad_data[i].joypad = NULL;
device->pad_data[i].pad_index = i;
}
device->driver = driver;
device->driver = driver;
device->driver->send_control(device->handle, magic_data, sizeof(magic_data));
@ -105,10 +106,14 @@ static void hidpad_wiiugca_deinit(void *device_data)
static void hidpad_wiiugca_get_buttons(void *pad_data, input_bits_t *state)
{
gca_pad_data_t *pad = (gca_pad_data_t *)pad_data;
if (pad) {
if(pad->datatype == GCA_TYPE_PAD) {
if (pad)
{
if(pad->datatype == GCA_TYPE_PAD)
{
BITS_COPY16_PTR(state, pad->buttons);
} else {
}
else
{
gca_device_data_t *device = (gca_device_data_t *)pad_data;
BITS_COPY16_PTR(state, device->pad_data[0].buttons);
}
@ -121,8 +126,8 @@ static void hidpad_wiiugca_get_buttons(void *pad_data, input_bits_t *state)
static int16_t hidpad_wiiugca_get_axis(void *pad_data, unsigned axis)
{
gca_pad_data_t *pad = (gca_pad_data_t *)pad_data;
axis_data axis_data;
gca_pad_data_t *pad = (gca_pad_data_t *)pad_data;
gamepad_read_axis_data(axis, &axis_data);
@ -131,13 +136,12 @@ static int16_t hidpad_wiiugca_get_axis(void *pad_data, unsigned axis)
if(pad->datatype == GCA_TYPE_PAD)
return gamepad_get_axis_value(pad->analog, &axis_data);
else {
gca_device_data_t *device = (gca_device_data_t *)pad_data;
return gamepad_get_axis_value(device->pad_data[0].analog, &axis_data);
}
gca_device_data_t *device = (gca_device_data_t *)pad_data;
return gamepad_get_axis_value(device->pad_data[0].analog, &axis_data);
}
static void update_button_state(gca_pad_data_t *pad) {
static void update_button_state(gca_pad_data_t *pad)
{
uint32_t i, pressed_keys;
static const uint32_t button_mapping[12] =
@ -167,7 +171,8 @@ static void update_button_state(gca_pad_data_t *pad) {
(1 << button_mapping[i]) : 0;
}
static void update_analog_state(gca_pad_data_t *pad) {
static void update_analog_state(gca_pad_data_t *pad)
{
int pad_axis;
int16_t interpolated;
unsigned stick, axis;
@ -189,18 +194,16 @@ static void update_analog_state(gca_pad_data_t *pad) {
}
}
static void hidpad_wiiugca_pad_packet_handler(gca_pad_data_t *pad, uint8_t *packet, size_t size) {
if(size > 9) {
static void hidpad_wiiugca_pad_packet_handler(gca_pad_data_t *pad, uint8_t *packet, size_t size)
{
if (size > 9)
return;
}
memcpy(pad->data, packet, size);
update_button_state(pad);
update_analog_state(pad);
}
static void hidpad_wiiugca_packet_handler(void *device_data, uint8_t *packet, uint16_t size)
{
uint32_t i;
@ -225,9 +228,7 @@ static void hidpad_wiiugca_packet_handler(void *device_data, uint8_t *packet, ui
hidpad_wiiugca_pad_packet_handler(&device->pad_data[port], &device->data[i], 9);
}
else
{
device->connected[port] = 0;
}
}
}
@ -242,81 +243,86 @@ static void hidpad_wiiugca_set_rumble(void *data,
const char *hidpad_wiiugca_get_name(void *pad_data)
{
gca_pad_data_t *pad = (gca_pad_data_t *)pad_data;
if(!pad || pad->datatype != GCA_TYPE_PAD) {
if(!pad || pad->datatype != GCA_TYPE_PAD)
return DEVICE_NAME;
}
switch(pad->device_data->connected[pad->pad_index]) {
switch(pad->device_data->connected[pad->pad_index])
{
case 0:
return DEVICE_NAME;
case GCA_WAVEBIRD_CONNECTED:
return WAVEBIRD_PAD;
default:
return GAMECUBE_PAD;
break;
}
/* For now we return a single static name */
/* For now we return a single static name */
return GAMECUBE_PAD;
}
static int32_t hidpad_wiiugca_button(void *pad_data, uint16_t joykey) {
static int32_t hidpad_wiiugca_button(void *pad_data, uint16_t joykey)
{
gca_pad_data_t *pad = (gca_pad_data_t *)pad_data;
if(!pad) return 0;
if (!pad)
return 0;
if(pad->datatype != GCA_TYPE_PAD) {
if (pad->datatype != GCA_TYPE_PAD)
{
gca_device_data_t *device = (gca_device_data_t *)pad_data;
pad = &device->pad_data[0];
}
if (!pad->device_data || joykey > 31 || pad->joypad == NULL)
if (!pad->device_data || joykey > 31 || !pad->joypad)
return 0;
return pad->buttons & (1 << joykey);
}
static void *hidpad_wiiugca_pad_init(void *device_data, int pad_index, joypad_connection_t *joypad) {
static void *hidpad_wiiugca_pad_init(void *device_data, int pad_index, joypad_connection_t *joypad)
{
gca_device_data_t *device = (gca_device_data_t *)device_data;
if(!device || pad_index < 0 || pad_index >= GCA_MAX_PAD || joypad == NULL || device->pad_data[pad_index].joypad != NULL || !device->connected[pad_index]) {
if(!device || pad_index < 0 || pad_index >= GCA_MAX_PAD || !joypad || device->pad_data[pad_index].joypad || !device->connected[pad_index])
return NULL;
}
device->pad_data[pad_index].joypad = joypad;
return &device->pad_data[pad_index];
}
static void hidpad_wiiugca_pad_deinit(void *pad_data) {
static void hidpad_wiiugca_pad_deinit(void *pad_data)
{
gca_pad_data_t *pad = (gca_pad_data_t *)pad_data;
if(!pad) {
if(!pad)
return;
}
pad->joypad = NULL;
}
static int8_t hidpad_wiiugca_status(void *device_data, int pad_index) {
static int8_t hidpad_wiiugca_status(void *device_data, int pad_index)
{
gca_device_data_t *device = (gca_device_data_t *)device_data;
int8_t result = 0;
if(!device || pad_index < 0 || pad_index >= GCA_MAX_PAD) return 0;
if(!device || pad_index < 0 || pad_index >= GCA_MAX_PAD)
return 0;
if(device->connected[pad_index]) {
if (device->connected[pad_index])
result |= PAD_CONNECT_READY;
}
if(device->pad_data[pad_index].joypad != NULL) {
if (device->pad_data[pad_index].joypad)
result |= PAD_CONNECT_BOUND;
}
return result;
}
static joypad_connection_t *hidpad_wiiugca_joypad(void *device_data, int pad_index) {
static joypad_connection_t *hidpad_wiiugca_joypad(void *device_data, int pad_index)
{
gca_device_data_t *device = (gca_device_data_t *)device_data;
if(!device || pad_index < 0 || pad_index >= GCA_MAX_PAD) return 0;
if(!device || pad_index < 0 || pad_index >= GCA_MAX_PAD)
return 0;
return device->pad_data[pad_index].joypad;
}