(iOS BTstack) Remove the need to select pad type when connecting

This commit is contained in:
meancoot 2013-04-04 17:58:51 -04:00
parent a49f0ef576
commit 1534ddee3a
6 changed files with 288 additions and 318 deletions

View File

@ -15,7 +15,7 @@
#import <UIKit/UIKit.h>
@interface RetroArch_iOS : UINavigationController<UIApplicationDelegate, UINavigationControllerDelegate, UIAlertViewDelegate>
@interface RetroArch_iOS : UINavigationController<UIApplicationDelegate, UINavigationControllerDelegate>
+ (void)displayErrorMessage:(NSString*)message;

View File

@ -13,6 +13,8 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
// I take back everything I ever said about bad bluetooth stacks, this shit is hard.
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdio.h>
@ -23,9 +25,28 @@
#include "btpad.h"
#include "wiimote.h"
static btpad_connection_t btpad_connection;
static bool btpad_connection_test(uint16_t handle, bd_addr_t address)
{
if (handle && btpad_connection.handle && handle != btpad_connection.handle)
return false;
btpad_connection.handle = handle ? handle : btpad_connection.handle;
if (address && btpad_connection.has_address && (BD_ADDR_CMP(address, btpad_connection.address)))
return false;
if (address)
{
btpad_connection.has_address = true;
memcpy(btpad_connection.address, address, sizeof(bd_addr_t));
}
return true;
}
static struct btpad_interface* btpad_iface;
static void* btpad_device;
static bool btpad_want_wiimote;
// MAIN THREAD ONLY
uint32_t btpad_get_buttons()
@ -38,20 +59,6 @@ int16_t btpad_get_axis(unsigned axis)
return (btpad_device && btpad_iface) ? btpad_iface->get_axis(btpad_device, axis) : 0;
}
void btpad_set_pad_type(bool wiimote)
{
btpad_want_wiimote = wiimote;
}
static void btpad_connect_pad(bool wiimote)
{
ios_add_log_message("BTpad: Connecting to %s", wiimote ? "WiiMote" : "PS3");
btpad_iface = (wiimote) ? &btpad_wii : &btpad_ps3;
btpad_device = btpad_iface->connect();
}
static void btpad_disconnect_pad()
{
if (btpad_iface && btpad_device)
@ -62,16 +69,204 @@ static void btpad_disconnect_pad()
btpad_device = 0;
btpad_iface = 0;
}
if (btpad_connection.handle)
bt_send_cmd_ptr(hci_disconnect_ptr, btpad_connection.handle, 0x15);
memset(&btpad_connection, 0, sizeof(btpad_connection_t));
}
static void btpad_connect_pad()
{
if (btpad_connection.state == BTPAD_CONNECTED)
btpad_disconnect_pad();
memset(&btpad_connection, 0, sizeof(btpad_connection_t));
ios_add_log_message("BTpad: Registering HID INTERRUPT service");
bt_send_cmd_ptr(l2cap_register_service_ptr, PSM_HID_INTERRUPT, 672);
}
void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
{
if (packet_type == HCI_EVENT_PACKET && packet[0] == BTSTACK_EVENT_STATE)
bd_addr_t event_addr;
if (packet_type == HCI_EVENT_PACKET)
{
if (packet[2] == HCI_STATE_WORKING)
btpad_connect_pad(btpad_want_wiimote);
else if(packet[2] > HCI_STATE_WORKING && btpad_iface && btpad_device)
btpad_disconnect_pad();
switch (packet[0])
{
case BTSTACK_EVENT_STATE:
if (packet[2] == HCI_STATE_WORKING)
btpad_connect_pad();
else if(packet[2] > HCI_STATE_WORKING && btpad_iface && btpad_device)
btpad_disconnect_pad();
break;
case L2CAP_EVENT_SERVICE_REGISTERED:
{
uint32_t psm = READ_BT_16(packet, 3);
if (psm == PSM_HID_INTERRUPT)
{
ios_add_log_message("BTpad: HID INTERRUPT service registered");
ios_add_log_message("BTpad: Registering HID CONTROL service");
bt_send_cmd_ptr(l2cap_register_service_ptr, PSM_HID_CONTROL, 672);
}
else if(psm == PSM_HID_CONTROL)
{
ios_add_log_message("BTpad: HID CONTROL service registered");
ios_add_log_message("BTpad: Starting inquiry");
bt_send_cmd_ptr(hci_inquiry_ptr, HCI_INQUIRY_LAP, 3, 1);
}
}
break;
case HCI_EVENT_INQUIRY_RESULT:
{
if (packet[2])
{
bt_flip_addr_ptr(event_addr, &packet[3]);
if (btpad_connection_test(0, event_addr))
{
btpad_connection.state = BTPAD_WANT_INQ_COMPLETE;
btpad_connection.page_scan_repetition_mode = packet [3 + packet[2] * (6)];
btpad_connection.class = READ_BT_24(packet, 3 + packet[2] * (6+1+1+1));
btpad_connection.clock_offset = READ_BT_16(packet, 3 + packet[2] * (6+1+1+1+3)) & 0x7fff;
ios_add_log_message("BTpad: Inquiry found device");
}
}
}
break;
case HCI_EVENT_INQUIRY_COMPLETE:
{
if (btpad_connection.state == BTPAD_WANT_INQ_COMPLETE)
{
ios_add_log_message("BTpad: Got inquiry complete; connecting\n");
bt_send_cmd_ptr(l2cap_create_channel_ptr, btpad_connection.address, PSM_HID_CONTROL);
}
else if(btpad_connection.state == BTPAD_EMPTY)
{
if (btpad_connection.laps < 40)
{
btpad_connection.laps ++;
bt_send_cmd_ptr(hci_inquiry_ptr, HCI_INQUIRY_LAP, 3, 1);
}
else
ios_add_log_message("BTpad: Did not find wiimote, will stop searching");
}
}
break;
case L2CAP_EVENT_CHANNEL_OPENED:
{
const uint8_t status = packet[2];
bt_flip_addr_ptr(event_addr, &packet[3]);
const uint16_t handle = READ_BT_16(packet, 9);
const uint16_t psm = READ_BT_16(packet, 11);
const uint16_t channel_id = READ_BT_16(packet, 13);
if (!btpad_connection_test(handle, event_addr))
{
ios_add_log_message("BTpad: Incoming L2CAP connection not recognized; ignoring");
break;
}
if (status == 0)
{
ios_add_log_message("BTpad: L2CAP channel opened for psm: %02X", psm);
if (psm == PSM_HID_CONTROL)
{
btpad_connection.channels[0] = channel_id;
ios_add_log_message("BTpad: Got HID CONTROL channel; Opening INTERRUPT");
bt_send_cmd_ptr(l2cap_create_channel_ptr, btpad_connection.address, PSM_HID_INTERRUPT);
}
else if (psm == PSM_HID_INTERRUPT)
{
btpad_connection.channels[1] = channel_id;
ios_add_log_message("BTpad: Got HID INTERRUPT channel; Requesting name");
bt_send_cmd_ptr(hci_remote_name_request_ptr, btpad_connection.address, btpad_connection.page_scan_repetition_mode,
0, btpad_connection.clock_offset | 0x8000);
}
else
ios_add_log_message("BTpad: Got unknown L2CAP channel, ignoring");
}
else
ios_add_log_message("BTpad: Failed to open WiiMote L2CAP channel for PSM: %02X", psm);
}
break;
case L2CAP_EVENT_INCOMING_CONNECTION:
{
bt_flip_addr_ptr(event_addr, &packet[2]);
const uint16_t handle = READ_BT_16(packet, 8);
const uint32_t psm = READ_BT_16(packet, 10);
const uint32_t channel_id = READ_BT_16(packet, 12);
const unsigned interrupt = (psm == PSM_HID_INTERRUPT) ? 1 : 0;
ios_add_log_message("BTpad: Incoming L2CAP connection for PSM: %02X", psm);
if (!btpad_connection_test(handle, event_addr))
{
ios_add_log_message("BTpad: Connection is for unregnized handle or address, denying");
// TODO: Check error code
bt_send_cmd_ptr(l2cap_decline_connection_ptr, 0x15);
break;
}
btpad_connection.channels[interrupt] = channel_id;
bt_send_cmd_ptr(l2cap_accept_connection_ptr, btpad_connection.channels[interrupt]);
ios_add_log_message("BTpad: L2CAP Connection accepted");
if (btpad_connection.channels[0] && btpad_connection.channels[1])
{
ios_add_log_message("BTpad: Got both L2CAP channels, requesting name");
bt_send_cmd_ptr(hci_remote_name_request_ptr, btpad_connection.address, 0, 0, 0);
}
}
break;
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
{
bt_flip_addr_ptr(event_addr, &packet[3]);
if (!btpad_connection_test(0, event_addr))
{
ios_add_log_message("BTpad: Got unexpected remote name, ignoring");
break;
}
ios_add_log_message("BTpad: Got %200s", (char*)&packet[9]);
if (strncmp((char*)&packet[9], "PLAYSTATION(R)3 Controller", 26) == 0)
btpad_iface = &btpad_ps3;
else if (strncmp((char*)&packet[9], "Nintendo RVL-CNT-01", 19) == 0)
btpad_iface = &btpad_wii;
if (btpad_iface)
{
btpad_device = btpad_iface->connect(&btpad_connection);
btpad_connection.state = BTPAD_CONNECTED;
}
}
break;
case HCI_EVENT_PIN_CODE_REQUEST:
{
ios_add_log_message("BTpad: Sending PIN");
bt_flip_addr_ptr(event_addr, &packet[2]);
bt_send_cmd_ptr(hci_pin_code_request_reply_ptr, event_addr, 6, &packet[2]);
}
break;
}
}
if (btpad_device && btpad_iface)

View File

@ -16,14 +16,36 @@
#ifndef __IOS_RARCH_BTPAD_H__
#define __IOS_RARCH_BTPAD_H__
#include "btstack/btstack.h"
uint32_t btpad_get_buttons();
int16_t btpad_get_axis(unsigned axis);
void btpad_set_pad_type(bool wiimote);
// Private interface
enum btpad_state { BTPAD_EMPTY, BTPAD_WANT_INQ_COMPLETE, BTPAD_CONNECTED };
typedef struct
{
enum btpad_state state;
uint16_t handle;
bool has_address;
bd_addr_t address;
uint32_t laps;
uint32_t page_scan_repetition_mode;
uint32_t class;
uint32_t clock_offset;
uint16_t channels[2]; //0: Control, 1: Interrupt
bool connected;
} btpad_connection_t;
struct btpad_interface
{
void* (*connect)();
void* (*connect)(const btpad_connection_t* connection);
void (*disconnect)(void* device);
void (*set_leds)(void* device, unsigned leds);

View File

@ -23,15 +23,10 @@
#include "btdynamic.h"
#include "btpad.h"
enum btpad_ps3_state { BTPAD_PS3_INITIALIZING, BTPAD_PS3_PENDING, BTPAD_PS3_WANT_NAME, BTPAD_PS3_CONNECTED };
struct btpad_ps3_data
{
enum btpad_ps3_state state;
uint8_t data[512];
bool have_address;
bd_addr_t address;
uint32_t handle;
uint32_t channels[2];
@ -39,28 +34,34 @@ struct btpad_ps3_data
bool have_led;
};
static void* btpad_ps3_connect()
static void btpad_ps3_setleds(struct btpad_ps3_data* device, unsigned leds);
static void* btpad_ps3_connect(const btpad_connection_t* connection)
{
struct btpad_ps3_data* device = malloc(sizeof(struct btpad_ps3_data));
memset(device, 0, sizeof(*device));
ios_add_log_message("BTstack PS3: Registering HID INTERRUPT service");
bt_send_cmd_ptr(l2cap_register_service_ptr, PSM_HID_INTERRUPT, 672);
device->state = BTPAD_PS3_INITIALIZING;
memcpy(device->address, connection->address, BD_ADDR_LEN);
device->handle = connection->handle;
device->channels[0] = connection->channels[0];
device->channels[1] = connection->channels[1];
// Magic packet to start reports
static uint8_t data[] = {0x53, 0xF4, 0x42, 0x03, 0x00, 0x00};
bt_send_l2cap_ptr(device->channels[0], data, 6);
// Without this the digital buttons won't be reported
btpad_ps3_setleds(device, 1);
return device;
}
static void btpad_ps3_disconnect(struct btpad_ps3_data* device)
{
ios_add_log_message("BTstack PS3: Disconnecting.");
bt_send_cmd_ptr(hci_disconnect_ptr, device->handle, 0x15);
free(device);
}
static void btpad_ps3_setleds(struct btpad_ps3_data* device, unsigned leds)
{
// TODO: Can this be modified to turn of motion tracking?
static uint8_t report_buffer[] = {
0x52, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
@ -79,7 +80,7 @@ static void btpad_ps3_setleds(struct btpad_ps3_data* device, unsigned leds)
static uint32_t btpad_ps3_get_buttons(struct btpad_ps3_data* device)
{
return (device->state == BTPAD_PS3_CONNECTED) ? device->data[3] | (device->data[4] << 8) | ((device->data[5] & 1) << 16): 0;
return device->data[3] | (device->data[4] << 8) | ((device->data[5] & 1) << 16);
}
static int16_t btpad_ps3_get_axis(struct btpad_ps3_data* device, unsigned axis)
@ -96,96 +97,7 @@ static int16_t btpad_ps3_get_axis(struct btpad_ps3_data* device, unsigned axis)
static void btpad_ps3_packet_handler(struct btpad_ps3_data* device, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
{
if (packet_type == HCI_EVENT_PACKET)
{
if (device->state == BTPAD_PS3_INITIALIZING)
{
if (packet[0] == L2CAP_EVENT_SERVICE_REGISTERED)
{
uint32_t psm = READ_BT_16(packet, 3);
if (psm == PSM_HID_INTERRUPT)
{
ios_add_log_message("BTstack PS3: HID INTERRUPT service registered");
ios_add_log_message("BTstack PS3: Registering HID CONTROL service");
bt_send_cmd_ptr(l2cap_register_service_ptr, PSM_HID_CONTROL, 672);
}
else if(psm == PSM_HID_CONTROL)
{
ios_add_log_message("BTstack PS3: HID CONTROL service registered");
ios_add_log_message("BTstack PS3: Waiting for connection");
device->state = BTPAD_PS3_PENDING;
}
}
}
else if(device->state == BTPAD_PS3_PENDING)
{
if (packet[0] == L2CAP_EVENT_INCOMING_CONNECTION)
{
const uint32_t psm = READ_BT_16(packet, 10);
const unsigned interrupt = (psm == PSM_HID_INTERRUPT) ? 1 : 0;
ios_add_log_message("BTstack PS3: Incoming L2CAP connection for PSM: %02X", psm);
bd_addr_t address;
bt_flip_addr_ptr(address, &packet[2]);
if (!device->have_address || BD_ADDR_CMP(device->address, address) == 0)
{
device->have_address = true;
bt_flip_addr_ptr(device->address, &packet[2]);
device->handle = READ_BT_16(packet, 8);
device->channels[interrupt] = READ_BT_16(packet, 12);
bt_send_cmd_ptr(l2cap_accept_connection_ptr, device->channels[interrupt]);
ios_add_log_message("BTstack PS3: Connection accepted");
if (device->channels[0] && device->channels[1])
{
ios_add_log_message("BTstack PS3: Got both channels, requesting name");
bt_send_cmd_ptr(hci_remote_name_request_ptr, device->address, 0, 0, 0);
device->state = BTPAD_PS3_WANT_NAME;
}
}
else
ios_add_log_message("BTstack PS3: Connection unexpected; ignoring");
}
}
else if(device->state == BTPAD_PS3_WANT_NAME)
{
if (packet[0] == HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE)
{
bd_addr_t event_addr;
bt_flip_addr_ptr(event_addr, &packet[3]);
if (BD_ADDR_CMP(event_addr, device->address) == 0)
{
if (strncmp((char*)&packet[9], "PLAYSTATION(R)3 Controller", 26) == 0)
{
ios_add_log_message("BTstack PS3: Got 'PLAYSTATION(R)3 Controller'; Sending startup packets");
// Special packet to tell PS3 controller to send reports
uint8_t data[] = {0x53, 0xF4, 0x42, 0x03, 0x00, 0x00};
bt_send_l2cap_ptr(device->channels[0], data, 6);
btpad_ps3_setleds(device, 1);
device->state = BTPAD_PS3_CONNECTED;
}
else
{
ios_add_log_message("BTstack PS3: Got %200s; Will keep looking", (char*)&packet[9]);
device->have_address = 0;
device->handle = 0;
device->channels[0] = 0;
device->channels[1] = 0;
device->state = BTPAD_PS3_PENDING;
}
}
}
}
}
else if (packet_type == L2CAP_DATA_PACKET && packet[0] == 0xA1)
if (packet_type == L2CAP_DATA_PACKET && packet[0] == 0xA1)
{
if (!device->have_led)
{

View File

@ -24,51 +24,39 @@
#include "btpad.h"
#include "wiimote.h"
enum btpad_wii_state { BTPAD_WII_WAITING, BTPAD_WII_PENDING, BTPAD_WII_WANT_NAME, BTPAD_WII_CONNECTING, BTPAD_WII_CONNECTED };
struct btpad_wii_data
static void* btpad_wii_connect(const btpad_connection_t* connection)
{
enum btpad_wii_state state;
struct wiimote_t wiimote;
bd_addr_t address;
uint32_t page_scan_repetition_mode;
uint32_t class;
uint32_t clock_offset;
};
struct wiimote_t* device = malloc(sizeof(struct wiimote_t));
memset(device, 0, sizeof(struct wiimote_t));
static void* btpad_wii_connect()
{
struct btpad_wii_data* device = malloc(sizeof(struct btpad_wii_data));
memset(device, 0, sizeof(struct btpad_wii_data));
memcpy(device->addr, connection->address, BD_ADDR_LEN);
ios_add_log_message("BTstack Wii: Waiting for connection");
bt_send_cmd_ptr(hci_inquiry_ptr, HCI_INQUIRY_LAP, 3, 0);
device->wiiMoteConHandle = connection->handle;
device->c_source_cid = connection->channels[0];
device->i_source_cid = connection->channels[1];
device->state = WIIMOTE_STATE_CONNECTED;
device->exp.type = EXP_NONE;
device->state = BTPAD_WII_WAITING;
wiimote_handshake(device, -1, NULL, -1);
return device;
}
static void btpad_wii_disconnect(struct btpad_wii_data* device)
{
ios_add_log_message("BTstack Wii: Disconnecting.");
bt_send_cmd_ptr(hci_disconnect_ptr, device->wiimote.wiiMoteConHandle, 0x15);
free(device);
}
static void btpad_wii_setleds(struct btpad_wii_data* device, unsigned leds)
static void btpad_wii_disconnect(struct wiimote_t* device)
{
}
static uint32_t btpad_wii_get_buttons(struct btpad_wii_data* device)
static void btpad_wii_setleds(struct wiimote_t* device, unsigned leds)
{
return (device->state == BTPAD_WII_CONNECTED) ? device->wiimote.btns | (device->wiimote.exp.classic.btns << 16) : 0;
// TODO
}
static int16_t btpad_wii_get_axis(struct btpad_wii_data* device, unsigned axis)
static uint32_t btpad_wii_get_buttons(struct wiimote_t* device)
{
return device->btns | (device->exp.classic.btns << 16);
}
static int16_t btpad_wii_get_axis(struct wiimote_t* device, unsigned axis)
{
/* TODO
if (device->.exp.type == EXP_CLASSIC)
@ -87,133 +75,9 @@ static int16_t btpad_wii_get_axis(struct btpad_wii_data* device, unsigned axis)
return 0;
}
static void btpad_wii_packet_handler(struct btpad_wii_data* device, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
static void btpad_wii_packet_handler(struct wiimote_t* device, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
{
if (packet_type == HCI_EVENT_PACKET && packet[0] == HCI_EVENT_PIN_CODE_REQUEST)
{
ios_add_log_message("BTstack Wii: Sending PIN");
bd_addr_t event_addr;
bt_flip_addr_ptr(event_addr, &packet[2]);
bt_send_cmd_ptr(hci_pin_code_request_reply_ptr, event_addr, 6, &packet[2]);
}
if (packet_type == HCI_EVENT_PACKET)
{
if (device->state == BTPAD_WII_WAITING)
{
switch (packet[0])
{
case HCI_EVENT_INQUIRY_RESULT:
{
if (packet[2])
{
ios_add_log_message("BTstack Wii: Inquiry found device");
device->state = BTPAD_WII_PENDING;
bt_flip_addr_ptr(device->address, &packet[3]);
device->page_scan_repetition_mode = packet [3 + packet[2] * (6)];
device->class = READ_BT_24(packet, 3 + packet[2] * (6+1+1+1));
device->clock_offset = READ_BT_16(packet, 3 + packet[2] * (6+1+1+1+3)) & 0x7fff;
}
break;
}
case HCI_EVENT_INQUIRY_COMPLETE:
{
bt_send_cmd_ptr(hci_inquiry_ptr, HCI_INQUIRY_LAP, 3, 0);
break;
}
}
}
else if(device->state == BTPAD_WII_PENDING)
{
if (packet[0] == HCI_EVENT_INQUIRY_COMPLETE)
{
ios_add_log_message("BTstack Wii: Got inquiry complete; requesting name\n");
device->state = BTPAD_WII_WANT_NAME;
bt_send_cmd_ptr(hci_remote_name_request_ptr, device->address, device->page_scan_repetition_mode,
0, device->clock_offset | 0x8000);
}
}
else if(device->state == BTPAD_WII_WANT_NAME)
{
if (packet[0] == HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE)
{
bd_addr_t event_addr;
bt_flip_addr_ptr(event_addr, &packet[3]);
if (BD_ADDR_CMP(event_addr, device->address) == 0)
{
if (strncmp((char*)&packet[9], "Nintendo RVL-CNT-01", 19) == 0)
{
ios_add_log_message("BTstack Wii: Got Nintendo RVL-CNT-01; Connecting");
device->state = BTPAD_WII_CONNECTING;
bt_send_cmd_ptr(l2cap_create_channel_ptr, device->address, PSM_HID_CONTROL);
}
else
{
ios_add_log_message("BTstack Wii: Unrecognized device %s; Will keep looking", (char*)&packet[9]);
memset(device, 0, sizeof(*device));
device->state = BTPAD_WII_WAITING;
bt_send_cmd_ptr(hci_inquiry_ptr, HCI_INQUIRY_LAP, 3, 0);
}
}
else
ios_add_log_message("BTstack Wii: Connection unexpected; ignoring");
}
}
else if(device->state == BTPAD_WII_CONNECTING)
{
if (packet[0] == L2CAP_EVENT_CHANNEL_OPENED)
{
bd_addr_t event_addr;
bt_flip_addr_ptr(event_addr, &packet[3]);
if (BD_ADDR_CMP(device->address, event_addr) != 0)
{
ios_add_log_message("BTstack Wii: Incoming L2CAP connection not recognized; ignoring");
return;
}
const uint16_t psm = READ_BT_16(packet, 11);
if (packet[2] == 0)
{
ios_add_log_message("BTstack: WiiMote L2CAP channel opened: %02X\n", psm);
if (psm == PSM_HID_CONTROL)
{
ios_add_log_message("BTstack Wii: Got HID CONTROL channel; Opening INTERRUPT");
bt_send_cmd_ptr(l2cap_create_channel_ptr, device->address, PSM_HID_INTERRUPT);
memset(&device->wiimote, 0, sizeof(struct wiimote_t));
device->wiimote.c_source_cid = READ_BT_16(packet, 13);
device->wiimote.wiiMoteConHandle = READ_BT_16(packet, 9);
memcpy(&device->wiimote.addr, &device->address, BD_ADDR_LEN);
device->wiimote.exp.type = EXP_NONE;
}
else if (psm == PSM_HID_INTERRUPT)
{
ios_add_log_message("BTstack Wii: Got HID INTERRUPT channel; Connected");
device->state = BTPAD_WII_CONNECTED;
device->wiimote.i_source_cid = READ_BT_16(packet, 13);
device->wiimote.state = WIIMOTE_STATE_CONNECTED;
wiimote_handshake(&device->wiimote, -1, NULL, -1);
}
}
else
{
ios_add_log_message("BTstack Wii: Failed to open WiiMote L2CAP channel for PSM: %02X", psm);
}
}
}
}
else if(packet_type == L2CAP_DATA_PACKET)
if(packet_type == L2CAP_DATA_PACKET)
{
byte* msg = packet + 2;
@ -221,34 +85,29 @@ static void btpad_wii_packet_handler(struct btpad_wii_data* device, uint8_t pack
{
case WM_RPT_BTN:
{
wiimote_pressed_buttons(&device->wiimote, msg);
break;
wiimote_pressed_buttons(device, msg);
return;
}
case WM_RPT_READ:
{
wiimote_pressed_buttons(&device->wiimote, msg);
byte len = ((msg[2] & 0xF0) >> 4) + 1;
byte *data = (msg + 5);
wiimote_handshake(&device->wiimote, WM_RPT_READ, data, len);
wiimote_pressed_buttons(device, msg);
wiimote_handshake(device, WM_RPT_READ, msg + 5, ((msg[2] & 0xF0) >> 4) + 1);
return;
}
case WM_RPT_CTRL_STATUS:
{
wiimote_pressed_buttons(&device->wiimote, msg);
wiimote_handshake(&device->wiimote,WM_RPT_CTRL_STATUS,msg,-1);
wiimote_pressed_buttons(device, msg);
wiimote_handshake(device,WM_RPT_CTRL_STATUS,msg,-1);
return;
}
case WM_RPT_BTN_EXP:
{
wiimote_pressed_buttons(&device->wiimote, msg);
wiimote_handle_expansion(&device->wiimote, msg+2);
break;
wiimote_pressed_buttons(device, msg);
wiimote_handle_expansion(device, msg+2);
return;
}
}
}

View File

@ -433,26 +433,8 @@ static void event_reload_config(void* userdata)
{
if (btstack_is_loaded() && !btstack_is_running())
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"RetroArch"
message:@"Choose Pad Type"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Wii", @"PS3", nil];
[alert show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (btstack_is_loaded())
{
btpad_set_pad_type(buttonIndex == alertView.firstOtherButtonIndex);
if (buttonIndex != alertView.cancelButtonIndex)
{
btstack_start();
[self.topViewController.navigationItem setRightBarButtonItem:[self createBluetoothButton] animated:YES];
}
btstack_start();
[self.topViewController.navigationItem setRightBarButtonItem:[self createBluetoothButton] animated:YES];
}
}