Clean up Wiiuse to allow less _WIN32 defines. Windows side now spits out regular packets, and takes in regular packets. Like a normal OS should :} This shouldn't break Windows wiimote, Linux Wiimote doesn't work with this revision. Will require the new plugin which doesn't have emulated Wiimote at all.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4591 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Sonicadvance1 2009-11-19 22:47:57 +00:00
parent 651b5addf4
commit 3af4c50af1
13 changed files with 40 additions and 86 deletions

View File

@ -112,9 +112,7 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
/* handshake done */
wm->exp.type = EXP_CLASSIC;
#ifdef WIN32
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif
return 1;
}

View File

@ -96,7 +96,7 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
if (wiiuse_io_read(wm[i])) {
/* propagate the event */
propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1);
propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
evnt += (wm[i]->event != WIIUSE_NONE);
/* clear out the event buffer */
@ -485,12 +485,10 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
exp_changed = 1;
}
#ifdef WIN32
if (!attachment) {
WIIUSE_DEBUG("Setting timeout to normal %i ms.", wm->normal_timeout);
wm->timeout = wm->normal_timeout;
}
#endif
/*
* From now on the remote will only send status packets.
@ -559,10 +557,8 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len) {
disable_expansion(wm);
/* increase the timeout until the handshake completes */
#ifdef WIN32
WIIUSE_DEBUG("Setting timeout to expansion %i ms.", wm->exp_timeout);
wm->timeout = wm->exp_timeout;
#endif
wiiuse_write_data(wm, WM_EXP_MEM_ENABLE, &buf, 1);

View File

@ -85,9 +85,7 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b
wm->event = WIIUSE_GUITAR_HERO_3_CTRL_INSERTED;
wm->exp.type = EXP_GUITAR_HERO_3;
#ifdef WIN32
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif
return 1;
}

View File

@ -272,7 +272,7 @@ int wiiuse_io_read(struct wiimote_t* wm) {
/* block select() for 1/2000th of a second */
tv.tv_sec = 0;
tv.tv_usec = 500;
tv.tv_usec = wm->timeout * 1000; // timeout is in Milliseconds tv_usec is in Microseconds!
FD_ZERO(&fds);
/* only poll it if it is connected */
@ -296,6 +296,7 @@ int wiiuse_io_read(struct wiimote_t* wm) {
if (FD_ISSET(wm->in_sock, &fds))
{
//memset(wm->event_buf, 0, sizeof(wm->event_buf));
/* read the pending message into the buffer */
r = read(wm->in_sock, wm->event_buf, sizeof(wm->event_buf));
if (r == -1) {
@ -309,7 +310,7 @@ int wiiuse_io_read(struct wiimote_t* wm) {
wiiuse_disconnect(wm);
wm->event = WIIUSE_UNEXPECTED_DISCONNECT;
}
return 0;
}
if (!r) {
@ -317,7 +318,7 @@ int wiiuse_io_read(struct wiimote_t* wm) {
wiiuse_disconnected(wm);
return 0;
}
memcpy(wm->event_buf, &wm->event_buf[1], r - 1);
wm->event_buf[0] = 0xa2; // Make sure it's 0xa2, just in case
return 1;
}
return 0;
@ -326,15 +327,8 @@ int wiiuse_io_read(struct wiimote_t* wm) {
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len)
{
if(buf[0] != (WM_SET_REPORT | WM_BT_OUTPUT))
{
// Linux and OSX need this, Windows strips it out
// Only packets from Dolphin don't have the start
// Wiiuse uses ifdefs to add the first byte without you ever knowing it
// Should find out a nice way of doing this, getting windows to stop stripping the packets would be nice
memcpy(buf + 1, buf, len - 1);
buf[0] = (WM_SET_REPORT | WM_BT_OUTPUT);
}
if(buf[0] == 0xa2)
buf[0] = 0x52; // May not be needed. Will be changing/correcting in the next few revisions
return write(wm->out_sock, buf, len);
}

View File

@ -367,25 +367,12 @@ int wiiuse_io_read(struct wiimote_t* wm) {
CFRunLoopRun();
memcpy(wm->event_buf,DataFromWiimote,sizeof(wm->event_buf));
memcpy(wm->event_buf, &wm->event_buf[1], sizeof(wm->event_buf) - 1);
return 1;
}
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
if(buf[0] != (WM_SET_REPORT | WM_BT_OUTPUT))
{
// Linux and OSX need this, Windows strips it out
// Only packets from Dolphin don't have the start
// Wiiuse uses ifdefs to add the first byte without you ever knowing it
// Should find out a nice way of doing this, getting windows to stop stripping the packets would be nice
memcpy(buf + 1, buf, len - 1);
buf[0] = (WM_SET_REPORT | WM_BT_OUTPUT);
}
[cbt writeToWiimote:buf length:len];
return 1;
}

View File

@ -198,6 +198,9 @@ int wiiuse_io_read(struct wiimote_t* wm) {
WIIUSE_WARNING("A wait error occured on reading from wiimote %i.", wm->unid);
return 0;
}
// Move the data over one, so we can add back in 0xa2
memcpy(wm->event_buf[1], &wm->event_buf, sizeof(wm->event_buf));
wm->event_buf[0] = 0xa2; // Put back in the crazy Data that Windows strips out
if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0))
return 0;
@ -219,13 +222,13 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
case WIIUSE_STACK_UNKNOWN:
{
/* try to auto-detect the stack type */
if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) {
if (i = WriteFile(wm->dev_handle, buf + 1, 22, &bytes, &wm->hid_overlap)) {
/* bluesoleil will always return 1 here, even if it's not connected */
wm->stack = WIIUSE_STACK_BLUESOLEIL;
return i;
}
if (i = HidD_SetOutputReport(wm->dev_handle, buf, len)) {
if (i = HidD_SetOutputReport(wm->dev_handle, buf + 1, len - 1)) {
wm->stack = WIIUSE_STACK_MS;
return i;
}
@ -235,10 +238,10 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
}
case WIIUSE_STACK_MS:
return HidD_SetOutputReport(wm->dev_handle, buf, len);
return HidD_SetOutputReport(wm->dev_handle, buf + 1, len - 1);
case WIIUSE_STACK_BLUESOLEIL:
return WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap);
return WriteFile(wm->dev_handle, buf + 1, 22, &bytes, &wm->hid_overlap);
}
return 0;

View File

@ -121,9 +121,7 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
if (nc->js.max.y == 0) nc->js.max.y = nc->js.center.y + 80;
}
#ifdef WIN32
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
#endif
return 1;
}

View File

@ -131,12 +131,13 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
#if !defined(__APPLE__)
wm[i]->dev_handle = 0;
wm[i]->stack = WIIUSE_STACK_UNKNOWN;
wm[i]->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT;
wm[i]->exp_timeout = WIIMOTE_EXP_TIMEOUT;
wm[i]->timeout = wm[i]->normal_timeout;
#endif
#endif
wm[i]->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT;
wm[i]->exp_timeout = WIIMOTE_EXP_TIMEOUT;
wm[i]->timeout = wm[i]->normal_timeout;
wm[i]->state = WIIMOTE_INIT_STATES;
wm[i]->flags = WIIUSE_INIT_FLAGS;
@ -573,12 +574,8 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
byte buf[32]; /* no payload is better than this */
int rumble = 0;
#ifndef WIN32
buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
buf[1] = report_type;
#else
buf[0] = report_type;
#endif
buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
buf[1] = report_type;
switch (report_type) {
case WM_CMD_LED:
@ -594,15 +591,9 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
break;
}
#ifndef WIN32
memcpy(buf+2, msg, len);
if (rumble)
buf[2] |= 0x01;
#else
memcpy(buf+1, msg, len);
if (rumble)
buf[1] |= 0x01;
#endif
memcpy(buf+2, msg, len);
if (rumble)
buf[2] |= 0x01;
#ifdef WITH_WIIUSE_DEBUG
{
@ -618,11 +609,7 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
}
#endif
#ifndef WIN32
return wiiuse_io_write(wm, buf, len+2);
#else
return wiiuse_io_write(wm, buf, len+1);
#endif
return wiiuse_io_write(wm, buf, len+2);
}
@ -753,7 +740,6 @@ void wiiuse_resync(struct wiimote_t* wm) {
* @param exp_timeout The timeout in millisecondsd to wait for an expansion handshake.
*/
void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout) {
#ifdef WIN32
int i;
if (!wm) return;
@ -762,5 +748,4 @@ void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout
wm[i]->normal_timeout = normal_timeout;
wm[i]->exp_timeout = exp_timeout;
}
#endif
}

View File

@ -38,7 +38,7 @@
#ifndef WIIUSE_H_INCLUDED
#define WIIUSE_H_INCLUDED
#define WITH_WIIUSE_DEBUG
#ifdef _WIN32
/* windows */
#include <windows.h>
@ -213,10 +213,8 @@ typedef enum ir_position_t {
* This is left over from an old hack, but it may actually
* be a useful feature to keep so it wasn't removed.
*/
#ifdef WIN32
#define WIIMOTE_DEFAULT_TIMEOUT 10
#define WIIMOTE_EXP_TIMEOUT 10
#endif
#define WIIMOTE_DEFAULT_TIMEOUT 10
#define WIIMOTE_EXP_TIMEOUT 10
typedef unsigned char byte;
typedef char sbyte;
@ -590,10 +588,10 @@ typedef struct wiimote_t {
WCONST HANDLE dev_handle; /**< HID handle */
WCONST OVERLAPPED hid_overlap; /**< overlap handle */
WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */
#endif
WCONST int timeout; /**< read timeout */
WCONST byte normal_timeout; /**< normal timeout */
WCONST byte exp_timeout; /**< timeout for expansion handshake */
#endif
WCONST int state; /**< various state flags */
WCONST byte leds; /**< currently lit leds */

View File

@ -121,8 +121,8 @@ vars.AddVariables(
ignorecase = 2
),
PathVariable('wxconfig', 'Path to the wxconfig', None),
('CC', 'The c compiler', 'gcc'),
('CXX', 'The c++ compiler', 'g++'),
('CC', 'The c compiler', 'gcc-4.4'),
('CXX', 'The c++ compiler', 'g++-4.4'),
)
if sys.platform == 'win32':

View File

@ -1854,7 +1854,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandDeleteStoredLinkKey(u8* _Input)
SendEventCommandComplete(HCI_CMD_DELETE_STORED_LINK_KEY, &Reply, sizeof(hci_delete_stored_link_key_rp));
ERROR_LOG(WII_IPC_WIIMOTE, "HCI: CommandDeleteStoredLinkKey... Probablu the security for linking has failed. Could be a problem with loading the SCONF");
ERROR_LOG(WII_IPC_WIIMOTE, "HCI: CommandDeleteStoredLinkKey... Probably the security for linking has failed. Could be a problem with loading the SCONF");
PanicAlert("HCI: CommandDeleteStoredLinkKey... Probably the security for linking has failed. Could be a problem with loading the SCONF");
}

View File

@ -690,7 +690,7 @@ void CWII_IPC_HLE_WiiMote::SendConfigurationRequest(u16 scid, u16* MTU, u16* Flu
void CWII_IPC_HLE_WiiMote::SDPSendServiceSearchResponse(u16 cid, u16 TransactionID, u8* pServiceSearchPattern, u16 MaximumServiceRecordCount)
{
// verify block... we hanlde search pattern for HID service only
// verify block... we handle search pattern for HID service only
{
CBigEndianBuffer buffer(pServiceSearchPattern);
_dbg_assert_(WII_IPC_WIIMOTE, buffer.Read8(0) == SDP_SEQ8); // data sequence

View File

@ -100,7 +100,8 @@ void SendData(u16 _channelID, const u8* _pData, u32 _Size)
m_pCriticalSection->Enter();
{
SEvent WriteEvent;
memcpy(WriteEvent.m_PayLoad, _pData + 1, _Size - 1);
memcpy(WriteEvent.m_PayLoad, _pData, _Size);
WriteEvent._Size = _Size - 1;
m_EventWriteQueue.push(WriteEvent);
// Debugging
@ -121,15 +122,10 @@ void ReadData()
{
//DEBUG_LOG(WIIMOTE, "Writing data to the Wiimote");
SEvent& rEvent = m_EventWriteQueue.front();
wiiuse_io_write(m_pWiiMote, (byte*)rEvent.m_PayLoad, MAX_PAYLOAD);
wiiuse_io_write(m_pWiiMote, (byte*)rEvent.m_PayLoad, rEvent._Size);
m_EventWriteQueue.pop();
#ifdef _WIN32
// Debugging. Move the data one step to the right first.
memcpy(rEvent.m_PayLoad + 1, rEvent.m_PayLoad, sizeof(rEvent.m_PayLoad) - 1);
rEvent.m_PayLoad[0] = 0xa2;
InterruptDebugging(false, rEvent.m_PayLoad);
#endif
}
m_pCriticalSection->Leave();
@ -145,17 +141,17 @@ void ReadData()
m_pCriticalSection->Enter();
// Filter out data reports
if (pBuffer[0] >= 0x30)
if (pBuffer[1] >= 0x30)
{
// Copy Buffer to LastReport
memcpy(m_LastReport.m_PayLoad, pBuffer, MAX_PAYLOAD);
memcpy(m_LastReport.m_PayLoad, pBuffer + 1, MAX_PAYLOAD);
m_LastReportValid = true;
}
else
{
// Copy Buffer to ImportantEvent
SEvent ImportantEvent;
memcpy(ImportantEvent.m_PayLoad, pBuffer, MAX_PAYLOAD);
memcpy(ImportantEvent.m_PayLoad, pBuffer + 1, MAX_PAYLOAD);
// Put it in the read queue right away
m_EventReadQueue.push(ImportantEvent);
@ -206,6 +202,7 @@ private:
memset(m_PayLoad, 0, MAX_PAYLOAD);
}
byte m_PayLoad[MAX_PAYLOAD];
u32 _Size;
};
typedef std::queue<SEvent> CEventQueue;
@ -213,10 +210,10 @@ private:
u16 m_channelID;
CEventQueue m_EventReadQueue; // Read from Wiimote
CEventQueue m_EventWriteQueue; // Write to Wiimote
bool m_LastReportValid;
SEvent m_LastReport;
wiimote_t* m_pWiiMote; // This is g_WiiMotesFromWiiUse[]
Common::CriticalSection* m_pCriticalSection;
bool m_LastReportValid;
// Send queued data to the core
void SendEvent(SEvent& _rEvent)