mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-02 19:12:47 +02:00
This changes Linux to control Wiimotes on the interrupt channel. Which in turn allows -TR wiimotes to work in Linux.
This commit is contained in:
parent
30d4259bba
commit
5005d528c4
@ -34,11 +34,6 @@
|
|||||||
#include "WiimoteReal.h"
|
#include "WiimoteReal.h"
|
||||||
#include "Host.h"
|
#include "Host.h"
|
||||||
|
|
||||||
// Identify the wiimote device by its class
|
|
||||||
#define WM_DEV_CLASS_0 0x04
|
|
||||||
#define WM_DEV_CLASS_1 0x25
|
|
||||||
#define WM_DEV_CLASS_2 0x00
|
|
||||||
|
|
||||||
namespace WiimoteReal
|
namespace WiimoteReal
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -95,9 +90,15 @@ int FindWiimotes(Wiimote** wm, int max_wiimotes)
|
|||||||
// Display discovered devices
|
// Display discovered devices
|
||||||
for (i = 0; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i)
|
for (i = 0; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i)
|
||||||
{
|
{
|
||||||
if ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) &&
|
char name[1000];
|
||||||
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
|
memset(name, 0, sizeof(name));
|
||||||
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2))
|
ERROR_LOG(WIIMOTE, "found a device...");
|
||||||
|
if (hci_read_remote_name(device_sock, &scan_info[i].bdaddr, sizeof(name), name, 0) < 0) {
|
||||||
|
ERROR_LOG(WIIMOTE, "name request failed");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ERROR_LOG(WIIMOTE, "device name %s", name);
|
||||||
|
if (IsValidBluetoothName(name))
|
||||||
{
|
{
|
||||||
bool new_wiimote = true;
|
bool new_wiimote = true;
|
||||||
// Determine if this wiimote has already been found.
|
// Determine if this wiimote has already been found.
|
||||||
@ -146,24 +147,24 @@ bool Wiimote::Connect()
|
|||||||
|
|
||||||
// Output channel
|
// Output channel
|
||||||
addr.l2_psm = htobs(WM_OUTPUT_CHANNEL);
|
addr.l2_psm = htobs(WM_OUTPUT_CHANNEL);
|
||||||
if ((out_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
|
if ((cmd_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
|
||||||
connect(out_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0)
|
connect(cmd_sock, (struct 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.");
|
||||||
close(out_sock);
|
close(cmd_sock);
|
||||||
out_sock = -1;
|
cmd_sock = -1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input channel
|
// Input channel
|
||||||
addr.l2_psm = htobs(WM_INPUT_CHANNEL);
|
addr.l2_psm = htobs(WM_INPUT_CHANNEL);
|
||||||
if ((in_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
|
if ((int_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) == -1 ||
|
||||||
connect(in_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0)
|
connect(int_sock, (struct 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.");
|
||||||
close(in_sock);
|
close(int_sock);
|
||||||
close(out_sock);
|
close(cmd_sock);
|
||||||
in_sock = out_sock = -1;
|
int_sock = cmd_sock = -1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,17 +205,17 @@ void Wiimote::Close()
|
|||||||
{
|
{
|
||||||
Host_ConnectWiimote(index, false);
|
Host_ConnectWiimote(index, false);
|
||||||
|
|
||||||
close(out_sock);
|
close(cmd_sock);
|
||||||
close(in_sock);
|
close(int_sock);
|
||||||
|
|
||||||
out_sock = -1;
|
cmd_sock = -1;
|
||||||
in_sock = -1;
|
int_sock = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wiimote::IsOpen() const
|
bool Wiimote::IsOpen() const
|
||||||
{
|
{
|
||||||
return out_sock != -1 && in_sock != -1;
|
return cmd_sock != -1 && int_sock != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Wiimote::IORead(unsigned char *buf)
|
int Wiimote::IORead(unsigned char *buf)
|
||||||
@ -226,19 +227,19 @@ int Wiimote::IORead(unsigned char *buf)
|
|||||||
|
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(in_sock, &fds);
|
FD_SET(int_sock, &fds);
|
||||||
|
|
||||||
if (select(in_sock + 1, &fds, NULL, NULL, &tv) == -1)
|
if (select(int_sock + 1, &fds, NULL, NULL, &tv) == -1)
|
||||||
{
|
{
|
||||||
ERROR_LOG(WIIMOTE, "Unable to select wiimote %i input socket.", index + 1);
|
ERROR_LOG(WIIMOTE, "Unable to select wiimote %i input socket.", index + 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FD_ISSET(in_sock, &fds))
|
if (!FD_ISSET(int_sock, &fds))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Read the pending message into the buffer
|
// Read the pending message into the buffer
|
||||||
int r = read(in_sock, buf, MAX_PAYLOAD);
|
int r = read(int_sock, buf, MAX_PAYLOAD);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
{
|
{
|
||||||
// Error reading data
|
// Error reading data
|
||||||
@ -265,7 +266,7 @@ int Wiimote::IORead(unsigned char *buf)
|
|||||||
|
|
||||||
int Wiimote::IOWrite(unsigned char* buf, int len)
|
int Wiimote::IOWrite(unsigned char* buf, int len)
|
||||||
{
|
{
|
||||||
return write(out_sock, buf, len);
|
return write(int_sock, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // WiimoteReal
|
}; // WiimoteReal
|
||||||
|
@ -44,7 +44,7 @@ Wiimote::Wiimote(const unsigned int _index)
|
|||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
, inputlen(0)
|
, inputlen(0)
|
||||||
#elif defined(__linux__) && HAVE_BLUEZ
|
#elif defined(__linux__) && HAVE_BLUEZ
|
||||||
, out_sock(-1), in_sock(-1)
|
, cmd_sock(-1), int_sock(-1)
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
, dev_handle(0), stack(MSBT_STACK_UNKNOWN)
|
, dev_handle(0), stack(MSBT_STACK_UNKNOWN)
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,8 +71,8 @@ public:
|
|||||||
int inputlen;
|
int inputlen;
|
||||||
#elif defined(__linux__) && HAVE_BLUEZ
|
#elif defined(__linux__) && HAVE_BLUEZ
|
||||||
bdaddr_t bdaddr; // Bluetooth address
|
bdaddr_t bdaddr; // Bluetooth address
|
||||||
int out_sock; // Output socket
|
int cmd_sock; // Command socket
|
||||||
int in_sock; // Input socket
|
int int_sock; // Interrupt socket
|
||||||
|
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
|
|
||||||
// The 4 most significant bits of the first byte of an outgoing command must be
|
// The 4 most significant bits of the first byte of an outgoing command must be
|
||||||
// 0x50 if sending on the command channel and 0xA0 if sending on the interrupt
|
// 0x50 if sending on the command channel and 0xA0 if sending on the interrupt
|
||||||
// channel. On Mac we use interrupt channel; on Windows/Linux, command.
|
// channel. On Mac and Linux we use interrupt channel; on Windows, command.
|
||||||
#ifndef __APPLE__
|
#ifdef _WIN32
|
||||||
#define WM_SET_REPORT 0x50
|
#define WM_SET_REPORT 0x50
|
||||||
#else
|
#else
|
||||||
#define WM_SET_REPORT 0xA0
|
#define WM_SET_REPORT 0xA0
|
||||||
|
Loading…
Reference in New Issue
Block a user