Merge branch 'linux-wiimote-crash-fix'
This commit is contained in:
commit
240ea0f116
|
@ -36,6 +36,11 @@ void Wiimote::RealDisconnect()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Wiimote::IsOpen() const
|
||||||
|
{
|
||||||
|
return IsConnected();
|
||||||
|
}
|
||||||
|
|
||||||
int Wiimote::IORead(unsigned char* buf)
|
int Wiimote::IORead(unsigned char* buf)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -136,10 +136,10 @@ int FindWiimotes(Wiimote** wm, int max_wiimotes)
|
||||||
// Connect to a wiimote with a known address.
|
// Connect to a wiimote with a known address.
|
||||||
bool Wiimote::Connect()
|
bool Wiimote::Connect()
|
||||||
{
|
{
|
||||||
struct sockaddr_l2 addr;
|
if (IsConnected())
|
||||||
|
return false;
|
||||||
if (IsConnected()) return false;
|
|
||||||
|
|
||||||
|
sockaddr_l2 addr;
|
||||||
addr.l2_family = AF_BLUETOOTH;
|
addr.l2_family = AF_BLUETOOTH;
|
||||||
addr.l2_bdaddr = bdaddr;
|
addr.l2_bdaddr = bdaddr;
|
||||||
addr.l2_cid = 0;
|
addr.l2_cid = 0;
|
||||||
|
@ -195,6 +195,13 @@ void Wiimote::RealDisconnect()
|
||||||
if (m_wiimote_thread.joinable())
|
if (m_wiimote_thread.joinable())
|
||||||
m_wiimote_thread.join();
|
m_wiimote_thread.join();
|
||||||
|
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wiimote::Close()
|
||||||
|
{
|
||||||
|
if (IsOpen())
|
||||||
|
{
|
||||||
Host_ConnectWiimote(index, false);
|
Host_ConnectWiimote(index, false);
|
||||||
|
|
||||||
close(out_sock);
|
close(out_sock);
|
||||||
|
@ -203,20 +210,21 @@ void Wiimote::RealDisconnect()
|
||||||
out_sock = -1;
|
out_sock = -1;
|
||||||
in_sock = -1;
|
in_sock = -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Wiimote::IsOpen() const
|
||||||
|
{
|
||||||
|
return out_sock != -1 && in_sock != -1;
|
||||||
|
}
|
||||||
|
|
||||||
int Wiimote::IORead(unsigned char *buf)
|
int Wiimote::IORead(unsigned char *buf)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
|
||||||
fd_set fds;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
if (!IsConnected())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Block select for 1/2000th of a second
|
// Block select for 1/2000th of a second
|
||||||
|
timeval tv;
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = WIIMOTE_DEFAULT_TIMEOUT * 1000;
|
tv.tv_usec = WIIMOTE_DEFAULT_TIMEOUT * 1000;
|
||||||
|
|
||||||
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(in_sock, &fds);
|
FD_SET(in_sock, &fds);
|
||||||
|
|
||||||
|
@ -230,7 +238,7 @@ int Wiimote::IORead(unsigned char *buf)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Read the pending message into the buffer
|
// Read the pending message into the buffer
|
||||||
r = read(in_sock, buf, MAX_PAYLOAD);
|
int r = read(in_sock, buf, MAX_PAYLOAD);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
{
|
{
|
||||||
// Error reading data
|
// Error reading data
|
||||||
|
@ -241,17 +249,17 @@ int Wiimote::IORead(unsigned char *buf)
|
||||||
// This can happen if the bluetooth dongle is disconnected
|
// This can happen if the bluetooth dongle is disconnected
|
||||||
ERROR_LOG(WIIMOTE, "Bluetooth appears to be disconnected. "
|
ERROR_LOG(WIIMOTE, "Bluetooth appears to be disconnected. "
|
||||||
"Wiimote %i will be disconnected.", index + 1);
|
"Wiimote %i will be disconnected.", index + 1);
|
||||||
RealDisconnect();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!r)
|
else if (!r)
|
||||||
{
|
{
|
||||||
// Disconnect
|
// Disconnect
|
||||||
RealDisconnect();
|
Close();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -294,6 +294,11 @@ void Wiimote::RealDisconnect()
|
||||||
ResetEvent(&hid_overlap);
|
ResetEvent(&hid_overlap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Wiimote::IsOpen() const
|
||||||
|
{
|
||||||
|
return IsConnected();
|
||||||
|
}
|
||||||
|
|
||||||
int Wiimote::IORead(unsigned char* buf)
|
int Wiimote::IORead(unsigned char* buf)
|
||||||
{
|
{
|
||||||
DWORD b, r;
|
DWORD b, r;
|
||||||
|
|
|
@ -227,6 +227,11 @@ void Wiimote::RealDisconnect()
|
||||||
ichan = NULL;
|
ichan = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Wiimote::IsOpen() const
|
||||||
|
{
|
||||||
|
return IsConnected();
|
||||||
|
}
|
||||||
|
|
||||||
int Wiimote::IORead(unsigned char *buf)
|
int Wiimote::IORead(unsigned char *buf)
|
||||||
{
|
{
|
||||||
int bytes;
|
int bytes;
|
||||||
|
|
|
@ -240,7 +240,7 @@ void Wiimote::Disconnect()
|
||||||
DisableDataReporting();
|
DisableDataReporting();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wiimote::IsConnected()
|
bool Wiimote::IsConnected() const
|
||||||
{
|
{
|
||||||
return m_connected;
|
return m_connected;
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ void Wiimote::ThreadFunc()
|
||||||
Rumble();
|
Rumble();
|
||||||
|
|
||||||
// main loop
|
// main loop
|
||||||
while (IsConnected())
|
while (IsOpen())
|
||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
while (Write()) {}
|
while (Write()) {}
|
||||||
|
|
|
@ -53,7 +53,8 @@ public:
|
||||||
bool Read();
|
bool Read();
|
||||||
bool Write();
|
bool Write();
|
||||||
bool Connect();
|
bool Connect();
|
||||||
bool IsConnected();
|
bool IsConnected() const;
|
||||||
|
bool IsOpen() const;
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
void DisableDataReporting();
|
void DisableDataReporting();
|
||||||
void Rumble();
|
void Rumble();
|
||||||
|
@ -72,6 +73,9 @@ public:
|
||||||
bdaddr_t bdaddr; // Bluetooth address
|
bdaddr_t bdaddr; // Bluetooth address
|
||||||
int out_sock; // Output socket
|
int out_sock; // Output socket
|
||||||
int in_sock; // Input socket
|
int in_sock; // Input socket
|
||||||
|
|
||||||
|
void Close();
|
||||||
|
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
char devicepath[255]; // Unique wiimote reference
|
char devicepath[255]; // Unique wiimote reference
|
||||||
//ULONGLONG btaddr; // Bluetooth address
|
//ULONGLONG btaddr; // Bluetooth address
|
||||||
|
|
Loading…
Reference in New Issue