(Apple) apple_joypad_ps3/apple_joypad_wii - cleanups

This commit is contained in:
twinaphex 2014-08-14 04:52:39 +02:00
parent 88af50ab82
commit 4b67cf83c8
2 changed files with 20 additions and 20 deletions

View File

@ -23,12 +23,9 @@
struct hidpad_ps3_data struct hidpad_ps3_data
{ {
struct apple_pad_connection* connection; struct apple_pad_connection* connection;
uint8_t data[512]; uint8_t data[512];
uint32_t slot; uint32_t slot;
bool have_led; bool have_led;
uint16_t motors[2]; uint16_t motors[2];
}; };
@ -57,6 +54,10 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device)
static void* hidpad_ps3_connect(struct apple_pad_connection* connection, uint32_t slot) static void* hidpad_ps3_connect(struct apple_pad_connection* connection, uint32_t slot)
{ {
struct hidpad_ps3_data* device = (struct hidpad_ps3_data*)calloc(1, sizeof(struct hidpad_ps3_data)); struct hidpad_ps3_data* device = (struct hidpad_ps3_data*)calloc(1, sizeof(struct hidpad_ps3_data));
if (!device)
return NULL;
device->connection = connection; device->connection = connection;
device->slot = slot; device->slot = slot;
@ -74,7 +75,8 @@ static void* hidpad_ps3_connect(struct apple_pad_connection* connection, uint32_
static void hidpad_ps3_disconnect(struct hidpad_ps3_data* device) static void hidpad_ps3_disconnect(struct hidpad_ps3_data* device)
{ {
free(device); if (device)
free(device);
} }
static uint32_t hidpad_ps3_get_buttons(struct hidpad_ps3_data* device) static uint32_t hidpad_ps3_get_buttons(struct hidpad_ps3_data* device)

View File

@ -24,6 +24,9 @@ static void* hidpad_wii_connect(struct apple_pad_connection* connection, uint32_
{ {
struct wiimote_t* device = (struct wiimote_t*)calloc(1, sizeof(struct wiimote_t)); struct wiimote_t* device = (struct wiimote_t*)calloc(1, sizeof(struct wiimote_t));
if (!device)
return NULL;
device->connection = connection; device->connection = connection;
device->unid = slot; device->unid = slot;
device->state = WIIMOTE_STATE_CONNECTED; device->state = WIIMOTE_STATE_CONNECTED;
@ -36,7 +39,8 @@ static void* hidpad_wii_connect(struct apple_pad_connection* connection, uint32_
static void hidpad_wii_disconnect(struct wiimote_t* device) static void hidpad_wii_disconnect(struct wiimote_t* device)
{ {
free(device); if (device)
free(device);
} }
static int16_t hidpad_wii_get_axis(struct wiimote_t* device, unsigned axis) static int16_t hidpad_wii_get_axis(struct wiimote_t* device, unsigned axis)
@ -61,41 +65,35 @@ static int16_t hidpad_wii_get_axis(struct wiimote_t* device, unsigned axis)
return 0; return 0;
} }
static void hidpad_wii_packet_handler(struct wiimote_t* device, uint8_t *packet, uint16_t size) static void hidpad_wii_packet_handler(struct wiimote_t* device,
uint8_t *packet, uint16_t size)
{ {
int i;
byte* msg = packet + 2; byte* msg = packet + 2;
switch (packet[1]) switch (packet[1])
{ {
case WM_RPT_BTN: case WM_RPT_BTN:
{
wiimote_pressed_buttons(device, msg); wiimote_pressed_buttons(device, msg);
break; break;
}
case WM_RPT_READ: case WM_RPT_READ:
{
wiimote_pressed_buttons(device, msg); wiimote_pressed_buttons(device, msg);
wiimote_handshake(device, WM_RPT_READ, msg + 5, ((msg[2] & 0xF0) >> 4) + 1); wiimote_handshake(device, WM_RPT_READ, msg + 5,
((msg[2] & 0xF0) >> 4) + 1);
break; break;
}
case WM_RPT_CTRL_STATUS: case WM_RPT_CTRL_STATUS:
{
wiimote_pressed_buttons(device, msg); wiimote_pressed_buttons(device, msg);
wiimote_handshake(device,WM_RPT_CTRL_STATUS,msg,-1); wiimote_handshake(device,WM_RPT_CTRL_STATUS,msg,-1);
break; break;
}
case WM_RPT_BTN_EXP: case WM_RPT_BTN_EXP:
{
wiimote_pressed_buttons(device, msg); wiimote_pressed_buttons(device, msg);
wiimote_handle_expansion(device, msg+2); wiimote_handle_expansion(device, msg+2);
break; break;
}
} }
g_current_input_data.pad_buttons[device->unid] = device->btns | (device->exp.cc.classic.btns << 16); g_current_input_data.pad_buttons[device->unid] = device->btns |
for (int i = 0; i < 4; i ++) (device->exp.cc.classic.btns << 16);
for (i = 0; i < 4; i++)
g_current_input_data.pad_axis[device->unid][i] = hidpad_wii_get_axis(device, i); g_current_input_data.pad_axis[device->unid][i] = hidpad_wii_get_axis(device, i);
} }