From 4b67cf83c8429258476bdb48c2f3f25c6d6ffbb7 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 14 Aug 2014 04:52:39 +0200 Subject: [PATCH] (Apple) apple_joypad_ps3/apple_joypad_wii - cleanups --- input/apple_joypad_ps3.c | 10 ++++++---- input/apple_joypad_wii.c | 30 ++++++++++++++---------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/input/apple_joypad_ps3.c b/input/apple_joypad_ps3.c index da8b01e29e..7bd2f38fc7 100644 --- a/input/apple_joypad_ps3.c +++ b/input/apple_joypad_ps3.c @@ -23,12 +23,9 @@ struct hidpad_ps3_data { struct apple_pad_connection* connection; - uint8_t data[512]; - uint32_t slot; bool have_led; - 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) { struct hidpad_ps3_data* device = (struct hidpad_ps3_data*)calloc(1, sizeof(struct hidpad_ps3_data)); + + if (!device) + return NULL; + device->connection = connection; 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) { - free(device); + if (device) + free(device); } static uint32_t hidpad_ps3_get_buttons(struct hidpad_ps3_data* device) diff --git a/input/apple_joypad_wii.c b/input/apple_joypad_wii.c index 66dd14f34c..3c43f1e1c7 100644 --- a/input/apple_joypad_wii.c +++ b/input/apple_joypad_wii.c @@ -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)); + if (!device) + return NULL; + device->connection = connection; device->unid = slot; 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) { - free(device); + if (device) + free(device); } 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; } -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; + switch (packet[1]) { case WM_RPT_BTN: - { wiimote_pressed_buttons(device, msg); break; - } - case WM_RPT_READ: - { 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; - } - case WM_RPT_CTRL_STATUS: - { wiimote_pressed_buttons(device, msg); wiimote_handshake(device,WM_RPT_CTRL_STATUS,msg,-1); break; - } - case WM_RPT_BTN_EXP: - { wiimote_pressed_buttons(device, msg); wiimote_handle_expansion(device, msg+2); break; - } } - g_current_input_data.pad_buttons[device->unid] = device->btns | (device->exp.cc.classic.btns << 16); - for (int i = 0; i < 4; i ++) + g_current_input_data.pad_buttons[device->unid] = device->btns | + (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); }