From 9a1fbe586d1ab9985a9d27e6e116e284cd733934 Mon Sep 17 00:00:00 2001 From: Billiard26 Date: Sat, 18 Sep 2010 16:43:43 +0000 Subject: [PATCH] New Wiimote Plugin: Fix Emulated Wiimote Problem.(fixes issue 3230) Made the "Connected to X Wiimotes" text update on all tabs when clicking "Refresh"/"Pair Up". Some other cleanup. git-svn-id: http://dolphin-emu.googlecode.com/svn/trunk@6216 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../ControllerInterface/DInput/DInputJoystick.cpp | 10 +++--- .../Plugin_WiimoteNew/Src/WiimoteConfigDiag.cpp | 41 +++++++++++++--------- .../Plugin_WiimoteNew/Src/WiimoteConfigDiag.h | 16 ++++----- .../Src/WiimoteEmu/EmuSubroutines.cpp | 23 +++++------- .../Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteHid.h | 15 ++++++-- .../Plugins/Plugin_WiimoteNew/Src/WiimoteNew.cpp | 11 ++---- 6 files changed, 63 insertions(+), 53 deletions(-) diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp index f88e90b1c..f2a4f5561 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp @@ -435,6 +435,12 @@ bool Joystick::UpdateInput() bool Joystick::UpdateOutput() { size_t ok_count = 0; + + DIEFFECT eff; + ZeroMemory(&eff, sizeof(eff)); + eff.dwSize = sizeof(DIEFFECT); + eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; + std::vector::iterator i = m_state_out.begin(), e = m_state_out.end(); @@ -444,10 +450,6 @@ bool Joystick::UpdateOutput() { if (i->size) { - DIEFFECT eff; - ZeroMemory(&eff, sizeof(eff)); - eff.dwSize = sizeof(DIEFFECT); - eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; eff.cbTypeSpecificParams = i->size; eff.lpvTypeSpecificParams = i->params; // set params and start effect diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteConfigDiag.cpp b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteConfigDiag.cpp index f39f786ea..5ac1e9ee3 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteConfigDiag.cpp +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteConfigDiag.cpp @@ -16,16 +16,16 @@ WiimoteConfigPage::WiimoteConfigPage(wxWindow* const parent, const int index) , m_index(index) { // input source - m_input_src_choice = new wxChoice(this, -1, wxDefaultPosition); - m_input_src_choice->Append(wxT("None")); - m_input_src_choice->Append(wxT("Emulated Wiimote")); - m_input_src_choice->Append(wxT("Real Wiimote")); - m_input_src_choice->Append(wxT("Hybrid Wiimote")); - m_input_src_choice->Select(g_wiimote_sources[m_index]); - _connect_macro_(m_input_src_choice, WiimoteConfigPage::SelectSource, wxEVT_COMMAND_CHOICE_SELECTED, this); + const wxString src_choices[] = { wxT("None"), + wxT("Emulated Wiimote"), wxT("Real Wiimote"), wxT("Hybrid Wiimote") }; + + wxChoice* const input_src_choice = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, + sizeof(src_choices)/sizeof(*src_choices), src_choices); + input_src_choice->Select(g_wiimote_sources[m_index]); + _connect_macro_(input_src_choice, WiimoteConfigPage::SelectSource, wxEVT_COMMAND_CHOICE_SELECTED, this); wxStaticBoxSizer* const input_src_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("Input Source")); - input_src_sizer->Add(m_input_src_choice, 1, wxEXPAND | wxALL, 5); + input_src_sizer->Add(input_src_choice, 1, wxEXPAND | wxALL, 5); // emulated wiimote wxButton* const configure_wiimote_emu_btn = new wxButton(this, -1, wxT("Configure")); @@ -34,18 +34,17 @@ WiimoteConfigPage::WiimoteConfigPage(wxWindow* const parent, const int index) _connect_macro_(configure_wiimote_emu_btn, WiimoteConfigDiag::ConfigEmulatedWiimote, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent()); // real wiimote - m_connected_wiimotes_txt = new wxStaticText(this, -1, wxEmptyString); - m_connected_wiimotes_txt->SetLabel(ConnectedWiimotesString()); + connected_wiimotes_txt = new wxStaticText(this, -1, ConnectedWiimotesString()); wxButton* const refresh_btn = new wxButton(this, -1, wxT("Refresh"), wxDefaultPosition); - _connect_macro_(refresh_btn, WiimoteConfigPage::RefreshRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, this); + _connect_macro_(refresh_btn, WiimoteConfigDiag::RefreshRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent()); wxStaticBoxSizer* const wiimote_real_sizer = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Real Wiimote")); wiimote_real_sizer->AddStretchSpacer(1); - wiimote_real_sizer->Add(m_connected_wiimotes_txt, 0, wxALIGN_CENTER | wxBOTTOM | wxLEFT | wxRIGHT, 5); + wiimote_real_sizer->Add(connected_wiimotes_txt, 0, wxALIGN_CENTER | wxBOTTOM | wxLEFT | wxRIGHT, 5); #ifdef _WIN32 wxButton* const pairup_btn = new wxButton(this, -1, wxT("Pair Up"), wxDefaultPosition); - _connect_macro_(pairup_btn, WiimoteConfigPage::PairUpRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, this); + _connect_macro_(pairup_btn, WiimoteConfigDiag::PairUpRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent()); wiimote_real_sizer->Add(pairup_btn, 0, wxALIGN_CENTER | wxBOTTOM, 5); #endif wiimote_real_sizer->Add(refresh_btn, 0, wxALIGN_CENTER, 5); @@ -95,8 +94,15 @@ void WiimoteConfigDiag::ConfigEmulatedWiimote(wxCommandEvent& event) m_emu_config_diag->Destroy(); } +void WiimoteConfigDiag::UpdateGUI() +{ + for (size_t p = 0; p < m_pad_notebook->GetPageCount(); ++p) + ((WiimoteConfigPage*)m_pad_notebook->GetPage(p))-> + connected_wiimotes_txt->SetLabel(ConnectedWiimotesString()); +} + #ifdef _WIN32 -void WiimoteConfigPage::PairUpRealWiimotes(wxCommandEvent& event) +void WiimoteConfigDiag::PairUpRealWiimotes(wxCommandEvent& event) { const int paired = WiimoteReal::PairUp(); @@ -105,6 +111,7 @@ void WiimoteConfigPage::PairUpRealWiimotes(wxCommandEvent& event) // Will this message be anoying? //PanicAlert("Paired %d wiimotes.", paired); WiimoteReal::Refresh(); + UpdateGUI(); } else if (paired < 0) PanicAlert("A supported bluetooth device was not found!\n" @@ -112,16 +119,16 @@ void WiimoteConfigPage::PairUpRealWiimotes(wxCommandEvent& event) } #endif -void WiimoteConfigPage::RefreshRealWiimotes(wxCommandEvent& event) +void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent& event) { WiimoteReal::Refresh(); - m_connected_wiimotes_txt->SetLabel(ConnectedWiimotesString()); + UpdateGUI(); } void WiimoteConfigPage::SelectSource(wxCommandEvent& event) { // should be kinda fine, maybe should just set when user clicks OK, w/e change it later - g_wiimote_sources[m_index] = m_input_src_choice->GetSelection(); + g_wiimote_sources[m_index] = event.GetInt(); } void WiimoteConfigDiag::Save(wxCommandEvent& event) diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteConfigDiag.h b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteConfigDiag.h index 75c3e482a..cc17bc2c3 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteConfigDiag.h +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteConfigDiag.h @@ -20,27 +20,27 @@ class WiimoteConfigPage : public wxNotebookPage public: WiimoteConfigPage(wxWindow* const parent, const int index); -#ifdef _WIN32 - void PairUpRealWiimotes(wxCommandEvent& event); -#endif - void RefreshRealWiimotes(wxCommandEvent& event); - void SelectSource(wxCommandEvent& event); + wxStaticText* connected_wiimotes_txt; + private: const int m_index; - - wxStaticText* m_connected_wiimotes_txt; - wxChoice* m_input_src_choice; }; class WiimoteConfigDiag : public wxDialog { public: WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin); + +#ifdef _WIN32 + void PairUpRealWiimotes(wxCommandEvent& event); +#endif + void RefreshRealWiimotes(wxCommandEvent& event); void ConfigEmulatedWiimote(wxCommandEvent& event); void Save(wxCommandEvent& event); + void UpdateGUI(); private: InputPlugin& m_plugin; diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/EmuSubroutines.cpp b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/EmuSubroutines.cpp index 23eec2d41..fe457477e 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/EmuSubroutines.cpp +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/EmuSubroutines.cpp @@ -93,7 +93,7 @@ void Wiimote::HidOutputReport(const wm_report* const sr, const bool send_ack) // wiibrew: // In every single Output Report, bit 0 (0x01) of the first byte controls the Rumble feature. - m_rumble_on = (sr->data[0] & 0x01) != 0; + m_rumble_on = sr->rumble; switch (sr->wm) { @@ -105,7 +105,6 @@ void Wiimote::HidOutputReport(const wm_report* const sr, const bool send_ack) case WM_LEDS : // 0x11 //INFO_LOG(WIIMOTE, "Set LEDs: 0x%02x", sr->data[0]); m_status.leds = sr->data[0] >> 4; - return; // no ack break; case WM_REPORT_MODE : // 0x12 @@ -114,18 +113,16 @@ void Wiimote::HidOutputReport(const wm_report* const sr, const bool send_ack) case WM_IR_PIXEL_CLOCK : // 0x13 //INFO_LOG(WIIMOTE, "WM IR Clock: 0x%02x", sr->data[0]); - //m_ir_clock = (sr->data[0] & 0x04) ? 1 : 0; - - if (0 == (sr->data[0] & 0x02)) // only ack if 0x02 bit is set + //m_ir_clock = sr->enable; + if (false == sr->ack) return; break; case WM_SPEAKER_ENABLE : // 0x14 //INFO_LOG(WIIMOTE, "WM Speaker Enable: 0x%02x", sr->data[0]); //PanicAlert( "WM Speaker Enable: %d", sr->data[0] ); - m_status.speaker = (sr->data[0] & 0x04) ? 1 : 0; - - if (0 == (sr->data[0] & 0x02)) // only ack if 0x02 bit is set + m_status.speaker = sr->enable; + if (false == sr->ack) return; break; @@ -159,9 +156,8 @@ void Wiimote::HidOutputReport(const wm_report* const sr, const bool send_ack) if (sr->data[0] & 0x04) memset(&m_channel_status, 0, sizeof(m_channel_status)); #endif - m_speaker_mute = (sr->data[0] & 0x04) ? 1 : 0; - - if (0 == (sr->data[0] & 0x02)) // only ack if 0x02 bit is set + m_speaker_mute = sr->enable; + if (false == sr->ack) return; break; @@ -170,9 +166,8 @@ void Wiimote::HidOutputReport(const wm_report* const sr, const bool send_ack) // This enables or disables the IR lights, we update the global variable g_IR // so that WmRequestStatus() knows about it //INFO_LOG(WIIMOTE, "WM IR Enable: 0x%02x", sr->data[0]); - m_status.ir = (sr->data[0] & 0x04) ? 1 : 0; - - if (0 == (sr->data[0] & 0x02)) // only ack if 0x02 bit is set + m_status.ir = sr->enable; + if (false == sr->ack) return; break; diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteHid.h b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteHid.h index a472920a0..f08f88524 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteHid.h +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/WiimoteHid.h @@ -136,9 +136,20 @@ struct wm_drums_extension u16 bt; // buttons }; -struct wm_report { +struct wm_report +{ u8 wm; - u8 data[0]; + union + { + u8 data[0]; + struct + { + u8 rumble : 1; // enable/disable rumble + // only valid for certain reports + u8 ack : 1; // respond with an ack + u8 enable : 1; // enable/disable certain features + }; + }; }; #define WM_RUMBLE 0x10 diff --git a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteNew.cpp b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteNew.cpp index 8367c4754..79370bd95 100644 --- a/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteNew.cpp +++ b/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteNew.cpp @@ -23,16 +23,14 @@ #define PLUGIN_VERSION 0x0100 -#define PLUGIN_NAME "Dolphin Wiimote New Incomplete" -#ifdef DEBUGFAST +#define PLUGIN_NAME "Dolphin Wiimote New" +#if defined(DEBUGFAST) #define PLUGIN_FULL_NAME PLUGIN_NAME" (DebugFast)" -#else -#ifdef _DEBUG +#elif defined(_DEBUG) #define PLUGIN_FULL_NAME PLUGIN_NAME" (Debug)" #else #define PLUGIN_FULL_NAME PLUGIN_NAME #endif -#endif // plugin globals InputPlugin g_plugin( "WiimoteNew", "Wiimote", "Wiimote" ); @@ -49,11 +47,8 @@ class wxDLLApp : public wxApp IMPLEMENT_APP_NO_MAIN(wxDLLApp) WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst); -// copied from GCPad HINSTANCE g_hInstance; -#endif -#ifdef _WIN32 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { switch (fdwReason) -- 2.11.4.GIT