Merge pull request #1862 from rmmh/master

WiimoteReal: improve Linux Bluetooth connectivity.
This commit is contained in:
Pierre Bourdon 2015-01-10 07:42:55 +01:00
commit 98a189de9a
2 changed files with 10 additions and 3 deletions

View File

@ -166,7 +166,7 @@ WiimoteLinux::~WiimoteLinux()
// Connect to a wiimote with a known address. // Connect to a wiimote with a known address.
bool WiimoteLinux::ConnectInternal() bool WiimoteLinux::ConnectInternal()
{ {
sockaddr_l2 addr; sockaddr_l2 addr = {};
addr.l2_family = AF_BLUETOOTH; addr.l2_family = AF_BLUETOOTH;
addr.l2_bdaddr = m_bdaddr; addr.l2_bdaddr = m_bdaddr;
addr.l2_cid = 0; addr.l2_cid = 0;
@ -176,7 +176,7 @@ bool WiimoteLinux::ConnectInternal()
if ((m_cmd_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 || if ((m_cmd_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
connect(m_cmd_sock, (sockaddr*)&addr, sizeof(addr)) < 0) connect(m_cmd_sock, (sockaddr*)&addr, sizeof(addr)) < 0)
{ {
DEBUG_LOG(WIIMOTE, "Unable to open output socket to wiimote."); DEBUG_LOG(WIIMOTE, "Unable to open output socket to wiimote: %s", strerror(errno));
close(m_cmd_sock); close(m_cmd_sock);
m_cmd_sock = -1; m_cmd_sock = -1;
return false; return false;
@ -187,7 +187,7 @@ bool WiimoteLinux::ConnectInternal()
if ((m_int_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 || if ((m_int_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
connect(m_int_sock, (sockaddr*)&addr, sizeof(addr)) < 0) connect(m_int_sock, (sockaddr*)&addr, sizeof(addr)) < 0)
{ {
DEBUG_LOG(WIIMOTE, "Unable to open input socket from wiimote."); DEBUG_LOG(WIIMOTE, "Unable to open input socket from wiimote: %s", strerror(errno));
close(m_int_sock); close(m_int_sock);
close(m_cmd_sock); close(m_cmd_sock);
m_int_sock = m_cmd_sock = -1; m_int_sock = m_cmd_sock = -1;

View File

@ -530,6 +530,13 @@ void Wiimote::ThreadFunc()
bool ok = ConnectInternal(); bool ok = ConnectInternal();
if (!ok)
{
// try again, it might take a moment to settle
Common::SleepCurrentThread(100);
ok = ConnectInternal();
}
SetReady(); SetReady();
if (!ok) if (!ok)