2008-12-08 05:25:12 +00:00
|
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
|
2009-02-04 00:06:11 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
2009-01-25 23:07:15 +00:00
|
|
|
|
// Includes
|
2009-02-04 00:06:11 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2009-01-25 23:07:15 +00:00
|
|
|
|
#include <iostream> // System
|
2009-02-09 13:10:29 +00:00
|
|
|
|
#include <queue>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
#include "wiiuse.h"
|
|
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
#include "Thread.h"
|
2009-01-25 23:07:15 +00:00
|
|
|
|
#include "StringUtil.h"
|
|
|
|
|
#include "ConsoleWindow.h"
|
2009-02-01 13:01:50 +00:00
|
|
|
|
#include "Timer.h"
|
2009-02-09 13:10:29 +00:00
|
|
|
|
#include "pluginspecs_wiimote.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
#include "wiimote_hid.h"
|
2009-01-25 23:07:15 +00:00
|
|
|
|
#include "main.h"
|
2009-01-28 16:09:08 +00:00
|
|
|
|
#include "Config.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include "EmuMain.h"
|
2009-01-31 01:18:57 +00:00
|
|
|
|
#include "EmuDefinitions.h"
|
2009-01-28 16:09:08 +00:00
|
|
|
|
#define EXCLUDE_H // Avoid certain declarations in wiimote_real.h
|
2009-01-25 23:07:15 +00:00
|
|
|
|
#include "wiimote_real.h"
|
2009-01-26 07:01:43 +00:00
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
|
#include "ConfigDlg.h"
|
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
extern SWiimoteInitialize g_WiimoteInitialize;
|
2009-01-25 23:07:15 +00:00
|
|
|
|
////////////////////////////////////////
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace WiiMoteReal
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
// Forwarding
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
class CWiiMote;
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#ifdef _WIN32
|
2009-01-25 23:07:15 +00:00
|
|
|
|
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#else
|
2009-01-25 23:07:15 +00:00
|
|
|
|
void* ReadWiimote_ThreadFunc(void* arg);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
// Variable declarations
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
wiimote_t** g_WiiMotesFromWiiUse = NULL;
|
|
|
|
|
Common::Thread* g_pReadThread = NULL;
|
|
|
|
|
int g_NumberOfWiiMotes;
|
|
|
|
|
CWiiMote* g_WiiMotes[MAX_WIIMOTES];
|
|
|
|
|
bool g_Shutdown = false;
|
2009-02-03 07:43:52 +00:00
|
|
|
|
bool g_ThreadGoing = false;
|
2009-01-25 23:07:15 +00:00
|
|
|
|
bool g_LocalThread = true;
|
2009-02-03 00:59:26 +00:00
|
|
|
|
bool g_IRSensing = false;
|
2009-01-28 16:09:08 +00:00
|
|
|
|
bool g_MotionSensing = false;
|
2009-02-01 13:01:50 +00:00
|
|
|
|
u64 g_UpdateTime = 0;
|
|
|
|
|
int g_UpdateCounter = 0;
|
2009-02-01 14:58:44 +00:00
|
|
|
|
bool g_RunTemporary = false;
|
2009-02-05 00:02:54 +00:00
|
|
|
|
int g_RunTemporaryCountdown = 0;
|
2009-02-03 00:59:26 +00:00
|
|
|
|
u8 g_EventBuffer[32];
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
// Probably this class should be in its own file
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
class CWiiMote
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
// On create and on uncreate
|
|
|
|
|
// ---------------
|
|
|
|
|
CWiiMote(u8 _WiimoteNumber, wiimote_t* _pWiimote)
|
|
|
|
|
: m_WiimoteNumber(_WiimoteNumber)
|
|
|
|
|
, m_channelID(0)
|
|
|
|
|
, m_pWiiMote(_pWiimote)
|
|
|
|
|
, m_pCriticalSection(NULL)
|
|
|
|
|
, m_LastReportValid(false)
|
|
|
|
|
{
|
|
|
|
|
m_pCriticalSection = new Common::CriticalSection();
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
//wiiuse_set_leds(m_pWiiMote, WIIMOTE_LED_4);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
// F|RES: i dunno if we really need this
|
|
|
|
|
CancelIo(m_pWiiMote->dev_handle);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
virtual ~CWiiMote()
|
|
|
|
|
{
|
|
|
|
|
delete m_pCriticalSection;
|
|
|
|
|
};
|
|
|
|
|
//////////////////////
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
//////////////////////////////////////////
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Queue raw HID data from the core to the wiimote
|
2009-01-25 23:07:15 +00:00
|
|
|
|
// ---------------
|
|
|
|
|
void SendData(u16 _channelID, const u8* _pData, u32 _Size)
|
|
|
|
|
{
|
|
|
|
|
m_channelID = _channelID;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
m_pCriticalSection->Enter();
|
|
|
|
|
{
|
|
|
|
|
SEvent WriteEvent;
|
2009-02-01 13:01:50 +00:00
|
|
|
|
memcpy(WriteEvent.m_PayLoad, _pData + 1, _Size - 1);
|
2009-01-25 23:07:15 +00:00
|
|
|
|
m_EventWriteQueue.push(WriteEvent);
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
|
//std::string Temp = ArrayToString(WriteEvent.m_PayLoad, 28, 0, 30);
|
|
|
|
|
//Console::Print("Wiimote Write:\n%s\n", Temp.c_str());
|
2009-01-25 23:07:15 +00:00
|
|
|
|
}
|
|
|
|
|
m_pCriticalSection->Leave();
|
|
|
|
|
}
|
|
|
|
|
/////////////////////
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
|
//////////////////////////////////////////////////
|
2009-02-01 13:01:50 +00:00
|
|
|
|
/* Read and write data to the Wiimote */
|
2009-01-25 23:07:15 +00:00
|
|
|
|
// ---------------
|
|
|
|
|
void ReadData()
|
|
|
|
|
{
|
|
|
|
|
m_pCriticalSection->Enter();
|
|
|
|
|
|
|
|
|
|
// Send data to the Wiimote
|
|
|
|
|
if (!m_EventWriteQueue.empty())
|
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
//Console::Print("Writing data to the Wiimote\n");
|
2009-01-25 23:07:15 +00:00
|
|
|
|
SEvent& rEvent = m_EventWriteQueue.front();
|
2009-02-09 13:10:29 +00:00
|
|
|
|
wiiuse_io_write(m_pWiiMote, (byte*)rEvent.m_PayLoad, MAX_PAYLOAD);
|
2009-01-25 23:07:15 +00:00
|
|
|
|
m_EventWriteQueue.pop();
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
|
|
|
|
#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
|
2009-01-25 23:07:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pCriticalSection->Leave();
|
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Read data from wiimote (but don't send it to the core, just filter and queue)
|
|
|
|
|
if (wiiuse_io_read(m_pWiiMote))
|
|
|
|
|
{
|
|
|
|
|
const byte* pBuffer = m_pWiiMote->event_buf;
|
|
|
|
|
|
|
|
|
|
// Check if we have a channel (connection) if so save the data...
|
|
|
|
|
if (m_channelID > 0)
|
2009-01-28 16:09:08 +00:00
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
m_pCriticalSection->Enter();
|
2009-01-28 16:09:08 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Filter out data reports
|
|
|
|
|
if (pBuffer[0] >= 0x30)
|
2009-01-28 16:09:08 +00:00
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Copy Buffer to LastReport
|
|
|
|
|
memcpy(m_LastReport.m_PayLoad, pBuffer, MAX_PAYLOAD);
|
|
|
|
|
m_LastReportValid = true;
|
2009-01-28 16:09:08 +00:00
|
|
|
|
}
|
2009-02-01 13:01:50 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Copy Buffer to ImportantEvent
|
|
|
|
|
SEvent ImportantEvent;
|
|
|
|
|
memcpy(ImportantEvent.m_PayLoad, pBuffer, MAX_PAYLOAD);
|
2009-01-28 16:09:08 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Put it in the read queue right away
|
|
|
|
|
m_EventReadQueue.push(ImportantEvent);
|
|
|
|
|
}
|
|
|
|
|
m_pCriticalSection->Leave();
|
2009-01-28 16:09:08 +00:00
|
|
|
|
}
|
2009-02-01 13:01:50 +00:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
/* Debugging
|
|
|
|
|
//if(GetAsyncKeyState('V'))
|
|
|
|
|
{
|
|
|
|
|
std::string Temp = ArrayToString(pBuffer, 20, 0, 30);
|
|
|
|
|
Console::Print("Data: %s\n", Temp.c_str());
|
|
|
|
|
} */
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2009-01-25 23:07:15 +00:00
|
|
|
|
};
|
|
|
|
|
/////////////////////
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
// Send queued data to the core
|
|
|
|
|
// ---------------
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
// Thread function
|
|
|
|
|
m_pCriticalSection->Enter();
|
|
|
|
|
|
|
|
|
|
if (m_EventReadQueue.empty())
|
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Send the data report
|
2009-01-25 23:07:15 +00:00
|
|
|
|
if (m_LastReportValid) SendEvent(m_LastReport);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Send a 0x20, 0x21 or 0x22 report
|
2009-01-25 23:07:15 +00:00
|
|
|
|
SendEvent(m_EventReadQueue.front());
|
|
|
|
|
m_EventReadQueue.pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pCriticalSection->Leave();
|
|
|
|
|
};
|
|
|
|
|
/////////////////////
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
// Clear events
|
|
|
|
|
// ---------------
|
|
|
|
|
void ClearEvents()
|
|
|
|
|
{
|
|
|
|
|
while (!m_EventReadQueue.empty())
|
|
|
|
|
m_EventReadQueue.pop();
|
|
|
|
|
while (!m_EventWriteQueue.empty())
|
|
|
|
|
m_EventWriteQueue.pop();
|
|
|
|
|
}
|
|
|
|
|
/////////////////////
|
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
private:
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
struct SEvent
|
|
|
|
|
{
|
|
|
|
|
SEvent()
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-25 23:07:15 +00:00
|
|
|
|
memset(m_PayLoad, 0, MAX_PAYLOAD);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-25 23:07:15 +00:00
|
|
|
|
byte m_PayLoad[MAX_PAYLOAD];
|
2008-12-08 05:25:12 +00:00
|
|
|
|
};
|
2009-01-25 23:07:15 +00:00
|
|
|
|
typedef std::queue<SEvent> CEventQueue;
|
|
|
|
|
|
|
|
|
|
u8 m_WiimoteNumber; // Just for debugging
|
|
|
|
|
u16 m_channelID;
|
2009-02-01 13:01:50 +00:00
|
|
|
|
CEventQueue m_EventReadQueue; // Read from Wiimote
|
|
|
|
|
CEventQueue m_EventWriteQueue; // Write to Wiimote
|
2009-01-25 23:07:15 +00:00
|
|
|
|
Common::CriticalSection* m_pCriticalSection;
|
|
|
|
|
bool m_LastReportValid;
|
|
|
|
|
SEvent m_LastReport;
|
|
|
|
|
wiimote_t* m_pWiiMote; // This is g_WiiMotesFromWiiUse[]
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Send queued data to the core
|
2009-01-25 23:07:15 +00:00
|
|
|
|
// ---------------
|
|
|
|
|
void SendEvent(SEvent& _rEvent)
|
|
|
|
|
{
|
|
|
|
|
// We don't have an answer channel
|
|
|
|
|
if (m_channelID == 0) return;
|
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Check event buffer
|
2009-01-25 23:07:15 +00:00
|
|
|
|
u8 Buffer[1024];
|
|
|
|
|
u32 Offset = 0;
|
|
|
|
|
hid_packet* pHidHeader = (hid_packet*)(Buffer + Offset);
|
|
|
|
|
Offset += sizeof(hid_packet);
|
|
|
|
|
pHidHeader->type = HID_TYPE_DATA;
|
|
|
|
|
pHidHeader->param = HID_PARAM_INPUT;
|
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Create the buffer
|
2009-01-25 23:07:15 +00:00
|
|
|
|
memcpy(&Buffer[Offset], _rEvent.m_PayLoad, MAX_PAYLOAD);
|
2009-02-04 06:40:05 +00:00
|
|
|
|
/* This Offset value is not exactly correct like it is for the emulated Wiimote reports. It's
|
|
|
|
|
often to big, but I guess that's okay. The game will know how big the actual data is. */
|
2009-01-25 23:07:15 +00:00
|
|
|
|
Offset += MAX_PAYLOAD;
|
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Send it
|
|
|
|
|
g_WiimoteInitialize.pWiimoteInput(m_channelID, Buffer, Offset);
|
2009-01-31 01:18:57 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Debugging
|
2009-02-27 23:44:15 +00:00
|
|
|
|
// ReadDebugging(false, Buffer, Offset);
|
2009-01-25 23:07:15 +00:00
|
|
|
|
}
|
|
|
|
|
/////////////////////
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
// Function Definitions
|
|
|
|
|
//******************************************************************************
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
void SendAcc(u8 _ReportID)
|
|
|
|
|
{
|
|
|
|
|
byte DataAcc[MAX_PAYLOAD];
|
|
|
|
|
|
|
|
|
|
DataAcc[0] = 0x22; // Report 0x12
|
|
|
|
|
DataAcc[1] = 0x00; // Core buttons
|
|
|
|
|
DataAcc[2] = 0x00;
|
|
|
|
|
DataAcc[3] = _ReportID; // Reporting mode
|
|
|
|
|
|
|
|
|
|
wiiuse_io_write(WiiMoteReal::g_WiiMotesFromWiiUse[0], (byte*)DataAcc, MAX_PAYLOAD);
|
|
|
|
|
|
|
|
|
|
std::string Temp = ArrayToString(DataAcc, 28, 0, 30);
|
|
|
|
|
Console::Print("SendAcc: %s\n", Temp.c_str());
|
|
|
|
|
|
|
|
|
|
//22 00 00 _reportID 00
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear any potential queued events
|
|
|
|
|
void ClearEvents()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < g_NumberOfWiiMotes; i++)
|
|
|
|
|
g_WiiMotes[i]->ClearEvents();
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// Flash lights, and if connecting, also rumble
|
|
|
|
|
void FlashLights(bool Connect)
|
|
|
|
|
{
|
|
|
|
|
if(Connect) wiiuse_rumble(WiiMoteReal::g_WiiMotesFromWiiUse[0], 1);
|
|
|
|
|
wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[0], WIIMOTE_LED_1 | WIIMOTE_LED_2 | WIIMOTE_LED_3 | WIIMOTE_LED_4);
|
2009-02-03 22:06:18 +00:00
|
|
|
|
sleep(100);
|
2009-01-29 08:35:29 +00:00
|
|
|
|
if(Connect) wiiuse_rumble(WiiMoteReal::g_WiiMotesFromWiiUse[0], 0);
|
|
|
|
|
|
|
|
|
|
// End with light 1 or 4
|
|
|
|
|
if(Connect)
|
|
|
|
|
wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[0], WIIMOTE_LED_1);
|
|
|
|
|
else
|
|
|
|
|
wiiuse_set_leds(WiiMoteReal::g_WiiMotesFromWiiUse[0], WIIMOTE_LED_4);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
int Initialize()
|
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Return if already initialized
|
2009-01-25 23:07:15 +00:00
|
|
|
|
if (g_RealWiiMoteInitialized) return g_NumberOfWiiMotes;
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Clear the wiimote classes
|
2009-01-25 23:07:15 +00:00
|
|
|
|
memset(g_WiiMotes, 0, sizeof(CWiiMote*) * MAX_WIIMOTES);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
// Call Wiiuse.dll
|
|
|
|
|
g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
|
2009-02-09 13:10:29 +00:00
|
|
|
|
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, MAX_WIIMOTES, 5);
|
2009-02-01 14:58:44 +00:00
|
|
|
|
if (g_NumberOfWiiMotes > 0) g_RealWiiMotePresent = true;
|
|
|
|
|
Console::Print("Found No of Wiimotes: %i\n", g_NumberOfWiiMotes);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Remove the wiiuse_poll() threshold
|
|
|
|
|
wiiuse_set_accel_threshold(g_WiiMotesFromWiiUse[0], 0);
|
|
|
|
|
|
2009-02-04 00:06:11 +00:00
|
|
|
|
// Set the sensor bar position, this should only affect the internal wiiuse api functions
|
2009-02-01 14:58:44 +00:00
|
|
|
|
wiiuse_set_ir_position(g_WiiMotesFromWiiUse[0], WIIUSE_IR_ABOVE);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-12 16:43:35 +00:00
|
|
|
|
// Set flags
|
|
|
|
|
//wiiuse_set_flags(g_WiiMotesFromWiiUse[0], NULL, WIIUSE_SMOOTHING);
|
|
|
|
|
|
2009-02-04 00:06:11 +00:00
|
|
|
|
// I don't seem to need wiiuse_connect() in Windows. But Linux needs it.
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
int Connect = wiiuse_connect(g_WiiMotesFromWiiUse, MAX_WIIMOTES);
|
|
|
|
|
Console::Print("Connected: %i\n", Connect);
|
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// If we are connecting from the config window without a game running we flash the lights
|
2009-02-04 00:06:11 +00:00
|
|
|
|
if (!g_EmulatorRunning && g_RealWiiMotePresent) FlashLights(true);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-26 14:13:27 +00:00
|
|
|
|
// Create Wiimote classes
|
2009-01-25 23:07:15 +00:00
|
|
|
|
for (int i = 0; i < g_NumberOfWiiMotes; i++)
|
|
|
|
|
g_WiiMotes[i] = new CWiiMote(i + 1, g_WiiMotesFromWiiUse[i]);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
// Create a new thread and start listening for Wiimote data
|
2009-01-25 23:07:15 +00:00
|
|
|
|
if (g_NumberOfWiiMotes > 0)
|
|
|
|
|
g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-01 14:58:44 +00:00
|
|
|
|
// If we are not using the emulated wiimote we can run the thread temporary until the data has beeen copied
|
|
|
|
|
if(g_Config.bUseRealWiimote) g_RunTemporary = true;
|
|
|
|
|
|
2009-02-20 09:57:17 +00:00
|
|
|
|
/* Allocate memory and copy the Wiimote eeprom accelerometer neutral values to g_Eeprom. Unlike with
|
|
|
|
|
and extension we have to do this here, because this data is only read once when the Wiimote
|
|
|
|
|
is connected. Also, we can't change the neutral values the wiimote will report, I think, unless
|
|
|
|
|
we update its eeprom? In any case it's probably better to let the current calibration be where it
|
|
|
|
|
is and adjust the global values after that to avoid overwriting critical data on any Wiimote. */
|
2009-02-01 14:58:44 +00:00
|
|
|
|
byte *data = (byte*)malloc(sizeof(byte) * sizeof(WiiMoteEmu::EepromData_0));
|
|
|
|
|
wiiuse_read_data(g_WiiMotesFromWiiUse[0], data, 0, sizeof(WiiMoteEmu::EepromData_0));
|
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
// Don't run the Wiimote thread if no wiimotes were found
|
|
|
|
|
if (g_NumberOfWiiMotes > 0) g_Shutdown = false;
|
2009-02-01 14:58:44 +00:00
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
// Initialized, even if we didn't find a Wiimote
|
|
|
|
|
g_RealWiiMoteInitialized = true;
|
2009-02-03 07:43:52 +00:00
|
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
|
return g_NumberOfWiiMotes;
|
2009-01-25 23:07:15 +00:00
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
void DoState(void* ptr, int mode) {}
|
|
|
|
|
|
|
|
|
|
void Shutdown(void)
|
|
|
|
|
{
|
2009-02-03 04:03:56 +00:00
|
|
|
|
// Stop the loop in the thread
|
2009-02-20 22:04:52 +00:00
|
|
|
|
g_Shutdown = true;
|
2009-02-03 04:03:56 +00:00
|
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
|
// Stop the thread
|
|
|
|
|
if (g_pReadThread != NULL)
|
|
|
|
|
{
|
|
|
|
|
delete g_pReadThread;
|
|
|
|
|
g_pReadThread = NULL;
|
|
|
|
|
}
|
2009-01-25 23:07:15 +00:00
|
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
|
// Delete the wiimotes
|
|
|
|
|
for (int i = 0; i < g_NumberOfWiiMotes; i++)
|
|
|
|
|
{
|
|
|
|
|
delete g_WiiMotes[i];
|
|
|
|
|
g_WiiMotes[i] = NULL;
|
|
|
|
|
}
|
2009-01-25 23:07:15 +00:00
|
|
|
|
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// Flash flights
|
2009-02-20 22:04:52 +00:00
|
|
|
|
if (!g_EmulatorRunning && g_RealWiiMotePresent)
|
|
|
|
|
FlashLights(false);
|
2009-01-26 07:01:43 +00:00
|
|
|
|
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// Clean up wiiuse
|
|
|
|
|
wiiuse_cleanup(g_WiiMotesFromWiiUse, g_NumberOfWiiMotes);
|
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
// Uninitialized
|
|
|
|
|
g_RealWiiMoteInitialized = false;
|
2009-01-26 07:01:43 +00:00
|
|
|
|
g_RealWiiMotePresent = false;
|
2009-01-25 23:07:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
|
|
|
|
|
{
|
2009-01-26 07:01:43 +00:00
|
|
|
|
//Console::Print("Real InterruptChannel\n");
|
2009-01-25 23:07:15 +00:00
|
|
|
|
g_WiiMotes[0]->SendData(_channelID, (const u8*)_pData, _Size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
|
|
|
|
|
{
|
2009-01-26 07:01:43 +00:00
|
|
|
|
//Console::Print("Real ControlChannel\n");
|
2009-01-25 23:07:15 +00:00
|
|
|
|
g_WiiMotes[0]->SendData(_channelID, (const u8*)_pData, _Size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
|
// Read the Wiimote once
|
|
|
|
|
// ---------------
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2009-01-26 07:01:43 +00:00
|
|
|
|
//Console::Print("Real Update\n");
|
2009-01-25 23:07:15 +00:00
|
|
|
|
for (int i = 0; i < g_NumberOfWiiMotes; i++)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-25 23:07:15 +00:00
|
|
|
|
g_WiiMotes[i]->Update();
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-25 23:07:15 +00:00
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-25 23:07:15 +00:00
|
|
|
|
//////////////////////////////////
|
2009-01-28 16:09:08 +00:00
|
|
|
|
/* Continuously read the Wiimote status. However, the actual sending of data occurs in Update(). If we are
|
2009-02-01 13:01:50 +00:00
|
|
|
|
not currently using the real Wiimote we allow the separate ReadWiimote() function to run. Wo don't use
|
|
|
|
|
them at the same time to avoid a potential collision. */
|
2009-01-25 23:07:15 +00:00
|
|
|
|
// ---------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#ifdef _WIN32
|
2009-01-25 23:07:15 +00:00
|
|
|
|
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#else
|
2009-01-25 23:07:15 +00:00
|
|
|
|
void *ReadWiimote_ThreadFunc(void* arg)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#endif
|
2009-01-25 23:07:15 +00:00
|
|
|
|
{
|
|
|
|
|
while (!g_Shutdown)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-02-03 07:43:52 +00:00
|
|
|
|
// We need g_ThreadGoing to do a manual WaitForSingleObject() from the configuration window
|
|
|
|
|
g_ThreadGoing = true;
|
2009-02-01 14:58:44 +00:00
|
|
|
|
if(g_Config.bUseRealWiimote && !g_RunTemporary)
|
2009-01-25 23:07:15 +00:00
|
|
|
|
for (int i = 0; i < g_NumberOfWiiMotes; i++) g_WiiMotes[i]->ReadData();
|
2009-02-01 13:01:50 +00:00
|
|
|
|
else
|
2009-01-25 23:07:15 +00:00
|
|
|
|
ReadWiimote();
|
2009-02-03 07:43:52 +00:00
|
|
|
|
g_ThreadGoing = false;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-25 23:07:15 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
////////////////////
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
}; // end of namespace
|
|
|
|
|
|