mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 23:29:44 -06:00
More attempts at fixing Windows and OS X.
This commit is contained in:
@ -178,6 +178,9 @@ bool Wiimote::IsConnected() const
|
|||||||
return cmd_sock != -1;// && int_sock != -1;
|
return cmd_sock != -1;// && int_sock != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// positive = read packet
|
||||||
|
// negative = didn't read packet
|
||||||
|
// zero = error
|
||||||
int Wiimote::IORead(u8* buf)
|
int Wiimote::IORead(u8* buf)
|
||||||
{
|
{
|
||||||
// Block select for 1/2000th of a second
|
// Block select for 1/2000th of a second
|
||||||
|
@ -148,12 +148,9 @@ std::vector<Wiimote*> WiimoteScanner::FindWiimotes(size_t max_wiimotes)
|
|||||||
{
|
{
|
||||||
PairUp();
|
PairUp();
|
||||||
|
|
||||||
std::vector<Wiimote*> wiimotes;
|
|
||||||
|
|
||||||
GUID device_id;
|
GUID device_id;
|
||||||
HANDLE dev;
|
HANDLE dev;
|
||||||
HDEVINFO device_info;
|
HDEVINFO device_info;
|
||||||
int found_wiimotes = 0;
|
|
||||||
DWORD len;
|
DWORD len;
|
||||||
SP_DEVICE_INTERFACE_DATA device_data;
|
SP_DEVICE_INTERFACE_DATA device_data;
|
||||||
PSP_DEVICE_INTERFACE_DETAIL_DATA detail_data = NULL;
|
PSP_DEVICE_INTERFACE_DETAIL_DATA detail_data = NULL;
|
||||||
@ -167,13 +164,11 @@ std::vector<Wiimote*> WiimoteScanner::FindWiimotes(size_t max_wiimotes)
|
|||||||
// Get all hid devices connected
|
// Get all hid devices connected
|
||||||
device_info = SetupDiGetClassDevs(&device_id, NULL, NULL, (DIGCF_DEVICEINTERFACE | DIGCF_PRESENT));
|
device_info = SetupDiGetClassDevs(&device_id, NULL, NULL, (DIGCF_DEVICEINTERFACE | DIGCF_PRESENT));
|
||||||
|
|
||||||
for (int index = 0; found_wiimotes < max_wiimotes; ++index)
|
std::vector<Wiimote*> wiimotes;
|
||||||
|
for (int index = 0; wiimotes.size() < max_wiimotes; ++index)
|
||||||
{
|
{
|
||||||
if (detail_data)
|
free(detail_data);
|
||||||
{
|
detail_data = NULL;
|
||||||
free(detail_data);
|
|
||||||
detail_data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Query the next hid device info
|
// Query the next hid device info
|
||||||
if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data))
|
if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data))
|
||||||
@ -188,7 +183,10 @@ std::vector<Wiimote*> WiimoteScanner::FindWiimotes(size_t max_wiimotes)
|
|||||||
if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL))
|
if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
auto const wm = new Wiimote;
|
||||||
|
|
||||||
// Open new device
|
// Open new device
|
||||||
|
#if 0
|
||||||
dev = CreateFile(detail_data->DevicePath,
|
dev = CreateFile(detail_data->DevicePath,
|
||||||
(GENERIC_READ | GENERIC_WRITE),
|
(GENERIC_READ | GENERIC_WRITE),
|
||||||
(FILE_SHARE_READ | FILE_SHARE_WRITE),
|
(FILE_SHARE_READ | FILE_SHARE_WRITE),
|
||||||
@ -199,18 +197,15 @@ std::vector<Wiimote*> WiimoteScanner::FindWiimotes(size_t max_wiimotes)
|
|||||||
// Get device attributes
|
// Get device attributes
|
||||||
attr.Size = sizeof(attr);
|
attr.Size = sizeof(attr);
|
||||||
HidD_GetAttributes(dev, &attr);
|
HidD_GetAttributes(dev, &attr);
|
||||||
|
|
||||||
// Find an unused slot
|
|
||||||
unsigned int k = 0;
|
|
||||||
auto const wm = new Wiimote;
|
|
||||||
wm->dev_handle = dev;
|
wm->dev_handle = dev;
|
||||||
|
#endif
|
||||||
wm->devicepath = detail_data->DevicePath;
|
wm->devicepath = detail_data->DevicePath;
|
||||||
|
|
||||||
wiimotes.push_back(wm);
|
wiimotes.push_back(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (detail_data)
|
free(detail_data);
|
||||||
free(detail_data);
|
|
||||||
|
|
||||||
SetupDiDestroyDeviceInfoList(device_info);
|
SetupDiDestroyDeviceInfoList(device_info);
|
||||||
|
|
||||||
@ -219,6 +214,8 @@ std::vector<Wiimote*> WiimoteScanner::FindWiimotes(size_t max_wiimotes)
|
|||||||
|
|
||||||
bool WiimoteScanner::IsReady() const
|
bool WiimoteScanner::IsReady() const
|
||||||
{
|
{
|
||||||
|
// TODO: don't search for a radio each time
|
||||||
|
|
||||||
BLUETOOTH_FIND_RADIO_PARAMS radioParam;
|
BLUETOOTH_FIND_RADIO_PARAMS radioParam;
|
||||||
radioParam.dwSize = sizeof(radioParam);
|
radioParam.dwSize = sizeof(radioParam);
|
||||||
|
|
||||||
@ -241,7 +238,7 @@ bool Wiimote::Connect()
|
|||||||
{
|
{
|
||||||
dev_handle = CreateFile(devicepath.c_str(),
|
dev_handle = CreateFile(devicepath.c_str(),
|
||||||
(GENERIC_READ | GENERIC_WRITE),
|
(GENERIC_READ | GENERIC_WRITE),
|
||||||
(FILE_SHARE_READ | FILE_SHARE_WRITE),
|
/*(FILE_SHARE_READ | FILE_SHARE_WRITE)*/ 0,
|
||||||
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||||
|
|
||||||
if (dev_handle == INVALID_HANDLE_VALUE)
|
if (dev_handle == INVALID_HANDLE_VALUE)
|
||||||
@ -281,8 +278,13 @@ bool Wiimote::IsConnected() const
|
|||||||
return dev_handle != 0;
|
return dev_handle != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// positive = read packet
|
||||||
|
// negative = didn't read packet
|
||||||
|
// zero = error
|
||||||
int Wiimote::IORead(unsigned char* buf)
|
int Wiimote::IORead(unsigned char* buf)
|
||||||
{
|
{
|
||||||
|
*buf = 0;
|
||||||
|
|
||||||
DWORD b;
|
DWORD b;
|
||||||
if (!ReadFile(dev_handle, buf, MAX_PAYLOAD, &b, &hid_overlap))
|
if (!ReadFile(dev_handle, buf, MAX_PAYLOAD, &b, &hid_overlap))
|
||||||
{
|
{
|
||||||
@ -291,7 +293,6 @@ int Wiimote::IORead(unsigned char* buf)
|
|||||||
if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED))
|
if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED))
|
||||||
{
|
{
|
||||||
// Remote disconnect
|
// Remote disconnect
|
||||||
Disconnect();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,24 +300,23 @@ int Wiimote::IORead(unsigned char* buf)
|
|||||||
if (r == WAIT_TIMEOUT)
|
if (r == WAIT_TIMEOUT)
|
||||||
{
|
{
|
||||||
// Timeout - cancel and continue
|
// Timeout - cancel and continue
|
||||||
|
|
||||||
if (*buf)
|
if (*buf)
|
||||||
WARN_LOG(WIIMOTE, "Packet ignored. This may indicate a problem (timeout is %i ms).",
|
WARN_LOG(WIIMOTE, "Packet ignored. This may indicate a problem (timeout is %i ms).",
|
||||||
WIIMOTE_DEFAULT_TIMEOUT);
|
WIIMOTE_DEFAULT_TIMEOUT);
|
||||||
|
|
||||||
CancelIo(dev_handle);
|
CancelIo(dev_handle);
|
||||||
ResetEvent(hid_overlap.hEvent);
|
ResetEvent(hid_overlap.hEvent);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (r == WAIT_FAILED)
|
else if (r == WAIT_FAILED)
|
||||||
{
|
{
|
||||||
WARN_LOG(WIIMOTE, "A wait error occured on reading from wiimote %i.", index + 1);
|
WARN_LOG(WIIMOTE, "A wait error occured on reading from wiimote %i.", index + 1);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetOverlappedResult(dev_handle, &hid_overlap, &b, 0))
|
if (!GetOverlappedResult(dev_handle, &hid_overlap, &b, 0))
|
||||||
{
|
{
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,7 +378,6 @@ int Wiimote::IOWrite(const u8* buf, int len)
|
|||||||
{
|
{
|
||||||
// Semaphore timeout
|
// Semaphore timeout
|
||||||
NOTICE_LOG(WIIMOTE, "WiimoteIOWrite[MSBT_STACK_MS]: Unable to send data to wiimote");
|
NOTICE_LOG(WIIMOTE, "WiimoteIOWrite[MSBT_STACK_MS]: Unable to send data to wiimote");
|
||||||
Disconnect();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,6 +417,8 @@ int PairUp(bool unpair)
|
|||||||
radioParam.dwSize = sizeof(radioParam);
|
radioParam.dwSize = sizeof(radioParam);
|
||||||
|
|
||||||
HANDLE hRadio;
|
HANDLE hRadio;
|
||||||
|
|
||||||
|
// TODO: save radio(s) in the WiimoteScanner constructor
|
||||||
|
|
||||||
// Enumerate BT radios
|
// Enumerate BT radios
|
||||||
HBLUETOOTH_RADIO_FIND hFindRadio = Bth_BluetoothFindFirstRadio(&radioParam, &hRadio);
|
HBLUETOOTH_RADIO_FIND hFindRadio = Bth_BluetoothFindFirstRadio(&radioParam, &hRadio);
|
||||||
|
@ -213,16 +213,10 @@ bool Wiimote::Connect()
|
|||||||
// Disconnect a wiimote.
|
// Disconnect a wiimote.
|
||||||
void Wiimote::Disconnect()
|
void Wiimote::Disconnect()
|
||||||
{
|
{
|
||||||
if (!IsConnected())
|
|
||||||
return;
|
|
||||||
|
|
||||||
NOTICE_LOG(WIIMOTE, "Disconnecting wiimote %i", index + 1);
|
NOTICE_LOG(WIIMOTE, "Disconnecting wiimote %i", index + 1);
|
||||||
|
|
||||||
m_connected = false;
|
m_connected = false;
|
||||||
|
|
||||||
if (m_wiimote_thread.joinable())
|
|
||||||
m_wiimote_thread.join();
|
|
||||||
|
|
||||||
[btd closeConnection];
|
[btd closeConnection];
|
||||||
[ichan release];
|
[ichan release];
|
||||||
[cchan release];
|
[cchan release];
|
||||||
|
Reference in New Issue
Block a user