Saving real Wiimote state

because that's simpler than reconnecting
This commit is contained in:
John Peterson
2013-06-25 09:24:14 -04:00
committed by Rachel Bryk
parent 748ee50536
commit 0fd3acd152
15 changed files with 815 additions and 64 deletions
+1
View File
@@ -162,6 +162,7 @@ const char* GetLastErrorMsg();
namespace Common
{
inline u8 swap8(u8 _data) {return _data;}
inline u32 swap24(const u8* _data) {return (_data[0] << 16) | (_data[1] << 8) | _data[2];}
#ifdef _WIN32
inline u16 swap16(u16 _data) {return _byteswap_ushort(_data);}
-2
View File
@@ -243,7 +243,6 @@ void SConfig::SaveSettings()
ini.Set("Core", "WiiSDCard", m_WiiSDCard);
ini.Set("Core", "WiiKeyboard", m_WiiKeyboard);
ini.Set("Core", "WiimoteReconnectOnLoad", m_WiimoteReconnectOnLoad);
ini.Set("Core", "WiimoteContinuousScanning", m_WiimoteContinuousScanning);
ini.Set("Core", "WiimoteEnableSpeaker", m_WiimoteEnableSpeaker);
ini.Set("Core", "RunCompareServer", m_LocalCoreStartupParameter.bRunCompareServer);
@@ -400,7 +399,6 @@ void SConfig::LoadSettings()
ini.Get("Core", "WiiSDCard", &m_WiiSDCard, false);
ini.Get("Core", "WiiKeyboard", &m_WiiKeyboard, false);
ini.Get("Core", "WiimoteReconnectOnLoad", &m_WiimoteReconnectOnLoad, true);
ini.Get("Core", "WiimoteContinuousScanning", &m_WiimoteContinuousScanning, false);
ini.Get("Core", "WiimoteEnableSpeaker", &m_WiimoteEnableSpeaker, true);
ini.Get("Core", "RunCompareServer", &m_LocalCoreStartupParameter.bRunCompareServer, false);
-1
View File
@@ -28,7 +28,6 @@ struct SConfig : NonCopyable
// Wii Devices
bool m_WiiSDCard;
bool m_WiiKeyboard;
bool m_WiimoteReconnectOnLoad;
bool m_WiimoteContinuousScanning;
bool m_WiimoteEnableSpeaker;
+2
View File
@@ -504,9 +504,11 @@ void SetState(EState _State)
break;
case CORE_PAUSE:
CCPU::EnableStepping(true); // Break
Wiimote::Pause();
break;
case CORE_RUN:
CCPU::EnableStepping(false);
Wiimote::Resume();
break;
default:
PanicAlertT("Invalid state");
+14 -9
View File
@@ -32,8 +32,7 @@ void Shutdown()
delete *i;
g_plugin.controllers.clear();
// WiimoteReal is shutdown on app exit
//WiimoteReal::Shutdown();
WiimoteReal::Shutdown();
g_controller_interface.Shutdown();
}
@@ -58,6 +57,17 @@ void Initialize(void* const hwnd)
Movie::ChangeWiiPads();
}
void Resume()
{
WiimoteReal::Resume();
}
void Pause()
{
WiimoteReal::Pause();
}
// __________________________________________________________________________________________________
// Function: ControlChannel
// Purpose: An L2CAP packet is passed from the Core to the Wiimote,
@@ -72,11 +82,8 @@ void Initialize(void* const hwnd)
//
void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
{
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number])
if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[_number])
((WiimoteEmu::Wiimote*)g_plugin.controllers[_number])->ControlChannel(_channelID, _pData, _Size);
if (WIIMOTE_SRC_REAL & g_wiimote_sources[_number])
WiimoteReal::ControlChannel(_number, _channelID, _pData, _Size);
}
// __________________________________________________________________________________________________
@@ -93,10 +100,8 @@ void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
//
void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
{
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number])
if (WIIMOTE_SRC_HYBRID & g_wiimote_sources[_number])
((WiimoteEmu::Wiimote*)g_plugin.controllers[_number])->InterruptChannel(_channelID, _pData, _Size);
else
WiimoteReal::InterruptChannel(_number, _channelID, _pData, _Size);
}
// __________________________________________________________________________________________________
+4
View File
@@ -36,6 +36,8 @@ namespace Wiimote
void Shutdown();
void Initialize(void* const hwnd);
void Resume();
void Pause();
unsigned int GetAttached();
void DoState(u8 **ptr, PointerWrap::Mode mode);
@@ -53,6 +55,8 @@ namespace WiimoteReal
void Initialize();
void Shutdown();
void Resume();
void Pause();
void Refresh();
void LoadSettings();
File diff suppressed because it is too large Load Diff
@@ -781,7 +781,10 @@ void Wiimote::Update()
// send data report
if (rptf_size)
{
WiimoteEmu::Spy(this, data, rptf_size);
Core::Callback_WiimoteInterruptChannel(m_index, m_reporting_channel, data, rptf_size);
}
}
void Wiimote::ControlChannel(const u16 _channelID, const void* _pData, u32 _Size)
@@ -853,7 +856,7 @@ void Wiimote::InterruptChannel(const u16 _channelID, const void* _pData, u32 _Si
{
const wm_report* const sr = (wm_report*)hidp->data;
if (WIIMOTE_SRC_HYBRID == g_wiimote_sources[m_index])
if (WIIMOTE_SRC_REAL & g_wiimote_sources[m_index])
{
switch (sr->wm)
{
@@ -24,6 +24,11 @@
#define WIIMOTE_REG_EXT_SIZE 0x100
#define WIIMOTE_REG_IR_SIZE 0x34
namespace WiimoteReal
{
class Wiimote;
}
namespace WiimoteEmu
{
@@ -66,6 +71,8 @@ inline double trim(double a)
class Wiimote : public ControllerEmu
{
friend class WiimoteReal::Wiimote;
friend void Spy(Wiimote* wm_, const void* data_, int size_);
public:
enum
@@ -92,6 +99,7 @@ public:
void ControlChannel(const u16 _channelID, const void* _pData, u32 _Size);
void DoState(PointerWrap& p);
void RealState();
void LoadDefaults(const ControllerInterface& ciface);
@@ -235,6 +243,8 @@ private:
} m_reg_speaker;
};
void Spy(Wiimote* wm_, const void* data_, int size_);
}
#endif
@@ -597,6 +597,8 @@ int _IORead(HANDLE &dev_handle, OVERLAPPED &hid_overlap_read, u8* buf, int index
}
}
WiimoteEmu::Spy(NULL, buf, bytes + 1);
return bytes + 1;
}
@@ -611,6 +613,8 @@ int Wiimote::IORead(u8* buf)
int _IOWrite(HANDLE &dev_handle, OVERLAPPED &hid_overlap_write, enum win_bt_stack_t &stack, const u8* buf, int len)
{
WiimoteEmu::Spy(NULL, buf, len);
switch (stack)
{
case MSBT_STACK_UNKNOWN:
@@ -110,6 +110,22 @@ void Wiimote::DisableDataReporting()
QueueReport(WM_REPORT_MODE, &rpt, sizeof(rpt));
}
void Wiimote::EnableDataReporting(u8 mode)
{
m_last_input_report.clear();
wm_report_mode rpt = {};
rpt.mode = mode;
rpt.all_the_time = 1;
rpt.continuous = 1;
QueueReport(WM_REPORT_MODE, &rpt, sizeof(rpt));
}
void Wiimote::SetChannel(u16 channel)
{
m_channel = channel;
}
void Wiimote::ClearReadQueue()
{
Report rpt;
@@ -314,6 +330,44 @@ void Wiimote::EmuStop()
NOTICE_LOG(WIIMOTE, "Stopping Wiimote data reporting.");
}
void Wiimote::EmuResume()
{
WiimoteEmu::Wiimote *const wm = (WiimoteEmu::Wiimote*)::Wiimote::GetPlugin()->controllers[index];
m_last_input_report.clear();
wm_report_mode rpt = {};
rpt.mode = wm->m_reporting_mode;
rpt.all_the_time = 1;
rpt.continuous = 1;
QueueReport(WM_REPORT_MODE, &rpt, sizeof(rpt));
NOTICE_LOG(WIIMOTE, "Resuming Wiimote data reporting.");
}
void Wiimote::EmuPause()
{
m_last_input_report.clear();
wm_report_mode rpt = {};
rpt.mode = WM_REPORT_CORE;
rpt.all_the_time = 0;
rpt.continuous = 0;
QueueReport(WM_REPORT_MODE, &rpt, sizeof(rpt));
NOTICE_LOG(WIIMOTE, "Pausing Wiimote data reporting.");
}
unsigned int CalculateConnectedWiimotes()
{
unsigned int connected_wiimotes = 0;
for (unsigned int i = 0; i < MAX_WIIMOTES; ++i)
if (g_wiimotes[i])
++connected_wiimotes;
return connected_wiimotes;
}
unsigned int CalculateWantedWiimotes()
{
// Figure out how many real Wiimotes are required
@@ -470,12 +524,26 @@ void Initialize()
g_wiimote_scanner.StartScanning();
else
g_wiimote_scanner.StopScanning();
std::lock_guard<std::recursive_mutex> lk(g_refresh_lock);
g_wiimote_scanner.WantWiimotes(0 != CalculateWantedWiimotes());
g_wiimote_scanner.WantBB(0 != CalculateWantedBB());
// wait for connection because it should exist before state load
int timeout = 100;
std::vector<Wiimote*> found_wiimotes;
Wiimote* found_board = NULL;
g_wiimote_scanner.FindWiimotes(found_wiimotes, found_board);
if (SConfig::GetInstance().m_WiimoteContinuousScanning)
{
while(CalculateWantedWiimotes() && CalculateConnectedWiimotes() < found_wiimotes.size() && timeout)
{
Common::SleepCurrentThread(100);
timeout--;
}
}
if (g_real_wiimotes_initialized)
return;
@@ -485,7 +553,14 @@ void Initialize()
}
void Shutdown(void)
{
{
for (unsigned int i = 0; i < MAX_BBMOTES; ++i)
if (g_wiimotes[i] && g_wiimotes[i]->IsConnected())
g_wiimotes[i]->EmuStop();
// WiimoteReal is shutdown on app exit
return;
g_wiimote_scanner.StopScanning();
std::lock_guard<std::recursive_mutex> lk(g_refresh_lock);
@@ -501,6 +576,20 @@ void Shutdown(void)
HandleWiimoteDisconnect(i);
}
void Resume()
{
for (unsigned int i = 0; i < MAX_BBMOTES; ++i)
if (g_wiimotes[i] && g_wiimotes[i]->IsConnected())
g_wiimotes[i]->EmuResume();
}
void Pause()
{
for (unsigned int i = 0; i < MAX_BBMOTES; ++i)
if (g_wiimotes[i] && g_wiimotes[i]->IsConnected())
g_wiimotes[i]->EmuPause();
}
void ChangeWiimoteSource(unsigned int index, int source)
{
{
@@ -47,6 +47,8 @@ public:
// "handshake" / stop packets
void EmuStart();
void EmuStop();
void EmuResume();
void EmuPause();
// connecting and disconnecting from physical devices
// (using address inserted by FindWiimotes)
@@ -59,6 +61,8 @@ public:
bool Prepare(int index);
void DisableDataReporting();
void EnableDataReporting(u8 mode);
void SetChannel(u16 channel);
void QueueReport(u8 rpt_id, const void* data, unsigned int size);
@@ -138,27 +138,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::DoState(PointerWrap &p)
for (unsigned int i = 0; i < MAX_BBMOTES; i++)
m_WiiMotes[i].DoState(p);
// Reset the connection of real and hybrid wiimotes
if (p.GetMode() == PointerWrap::MODE_READ && SConfig::GetInstance().m_WiimoteReconnectOnLoad)
{
for (unsigned int i = 0; i < MAX_BBMOTES; i++)
{
if (WIIMOTE_SRC_EMU == g_wiimote_sources[i] || WIIMOTE_SRC_NONE == g_wiimote_sources[i])
continue;
// TODO: Selectively clear real wiimote messages if possible. Or create a real wiimote channel and reporting mode pre-setup to vacate the need for m_WiimoteReconnectOnLoad.
m_EventQueue.clear();
if (!m_WiiMotes[i].IsInactive())
{
m_WiiMotes[i].Activate(false);
m_WiiMotes[i].Activate(true);
}
else
{
m_WiiMotes[i].Activate(false);
}
}
}
}
bool CWII_IPC_HLE_Device_usb_oh1_57e_305::RemoteDisconnect(u16 _connectionHandle)
@@ -106,7 +106,6 @@ WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin
wxSlider* const WiiSensBarSens = new wxSlider(this, wxID_ANY, 0, 0, 4, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL);
wxSlider* const WiimoteSpkVolume = new wxSlider(this, wxID_ANY, 0, 0, 127);
wxCheckBox* const WiimoteMotor = new wxCheckBox(this, wxID_ANY, _("Wiimote Motor"));
wxCheckBox* const WiimoteReconnectOnLoad = new wxCheckBox(this, wxID_ANY, _("Reconnect Wiimote on State Loading"));
wxStaticText* const WiiSensBarPosText = new wxStaticText(this, wxID_ANY, _("Sensor Bar Position:"));
wxStaticText* const WiiSensBarSensText = new wxStaticText(this, wxID_ANY, _("IR Sensitivity:"));
@@ -143,13 +142,11 @@ WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin
WiiSensBarSens->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<u32>("BT.SENS"));
WiimoteSpkVolume->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<u8>("BT.SPKV"));
WiimoteMotor->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<bool>("BT.MOT"));
WiimoteReconnectOnLoad->SetValue(SConfig::GetInstance().m_WiimoteReconnectOnLoad);
WiiSensBarPos->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &WiimoteConfigDiag::OnSensorBarPos, this);
WiiSensBarSens->Bind(wxEVT_COMMAND_SLIDER_UPDATED, &WiimoteConfigDiag::OnSensorBarSensitivity, this);
WiimoteSpkVolume->Bind(wxEVT_COMMAND_SLIDER_UPDATED, &WiimoteConfigDiag::OnSpeakerVolume, this);
WiimoteMotor->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnMotor, this);
WiimoteReconnectOnLoad->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnReconnectOnLoad, this);
// "General Settings" layout
@@ -175,7 +172,6 @@ WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin
wxGridSizer* const general_wiimote_sizer = new wxGridSizer(1, 5, 5);
general_wiimote_sizer->Add(WiimoteMotor);
general_wiimote_sizer->Add(WiimoteReconnectOnLoad);
general_sizer->Add(choice_sizer);
general_sizer->Add(general_wiimote_sizer);
@@ -52,11 +52,6 @@ public:
SConfig::GetInstance().m_SYSCONF->SetData("BT.MOT", event.GetInt());
event.Skip();
}
void OnReconnectOnLoad(wxCommandEvent& event)
{
SConfig::GetInstance().m_WiimoteReconnectOnLoad = event.IsChecked();
event.Skip();
}
void OnContinuousScanning(wxCommandEvent& event)
{
SConfig::GetInstance().m_WiimoteContinuousScanning = event.IsChecked();