From dee6a0498082a1f1ec8bc890a8c0f257f3a53b65 Mon Sep 17 00:00:00 2001 From: skidau Date: Thu, 5 Mar 2015 23:06:19 +1100 Subject: [PATCH 1/4] Moved the gcpad calibration from construction to runtime --- Source/Core/Core/HW/SI_DeviceGCController.cpp | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/Source/Core/Core/HW/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI_DeviceGCController.cpp index a05e54148f..5fcd50aaa0 100644 --- a/Source/Core/Core/HW/SI_DeviceGCController.cpp +++ b/Source/Core/Core/HW/SI_DeviceGCController.cpp @@ -24,35 +24,8 @@ CSIDevice_GCController::CSIDevice_GCController(SIDevices device, int _iDeviceNum , m_TButtonCombo(0) , m_LastButtonCombo(COMBO_NONE) { - GCPadStatus pad_origin; - memset(&m_Origin, 0, sizeof(SOrigin)); - memset(&pad_origin, 0, sizeof(GCPadStatus)); - - pad_origin.button = 0x00; - pad_origin.stickX = 0x80; // center - pad_origin.stickY = 0x80; - pad_origin.substickX = 0x80; - pad_origin.substickY = 0x80; - pad_origin.triggerLeft = 0x1F; // 0-30 is the lower deadzone - pad_origin.triggerRight = 0x1F; - // Dunno if we need to do this, game/lib should set it? m_Mode = 0x03; - -#if defined(__LIBUSB__) || defined (_WIN32) - if (SI_GCAdapter::IsDetected()) - { - SI_GCAdapter::Input(ISIDevice::m_iDeviceNumber, &pad_origin); - } -#endif - - m_Origin.uButton = pad_origin.button; - m_Origin.uOriginStickX = pad_origin.stickX; - m_Origin.uOriginStickY = pad_origin.stickY; - m_Origin.uSubStickStickX = pad_origin.substickX; - m_Origin.uSubStickStickY = pad_origin.substickY; - m_Origin.uTrigger_L = pad_origin.triggerLeft; - m_Origin.uTrigger_R = pad_origin.triggerRight; } int CSIDevice_GCController::RunBuffer(u8* _pBuffer, int _iLength) @@ -87,6 +60,21 @@ int CSIDevice_GCController::RunBuffer(u8* _pBuffer, int _iLength) case CMD_ORIGIN: { INFO_LOG(SERIALINTERFACE, "PAD - Get Origin"); + + GCPadStatus pad_origin; + memset(&m_Origin, 0, sizeof(SOrigin)); + memset(&pad_origin, 0, sizeof(GCPadStatus)); + + pad_origin = GetPadStatus(); + + m_Origin.uButton = pad_origin.button; + m_Origin.uOriginStickX = pad_origin.stickX; + m_Origin.uOriginStickY = pad_origin.stickY; + m_Origin.uSubStickStickX = pad_origin.substickX; + m_Origin.uSubStickStickY = pad_origin.substickY; + m_Origin.uTrigger_L = pad_origin.triggerLeft; + m_Origin.uTrigger_R = pad_origin.triggerRight; + u8* pCalibration = reinterpret_cast(&m_Origin); for (int i = 0; i < (int)sizeof(SOrigin); i++) { From e5277a5f49673afa854aa3fcd14919e9debd97a1 Mon Sep 17 00:00:00 2001 From: skidau Date: Thu, 5 Mar 2015 23:11:48 +1100 Subject: [PATCH 2/4] Ignore invalid rumble data sent over Netplay to the GC Adapter --- Source/Core/Core/HW/SI_GCAdapter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/HW/SI_GCAdapter.cpp b/Source/Core/Core/HW/SI_GCAdapter.cpp index 795054c61f..bae96a1ccf 100644 --- a/Source/Core/Core/HW/SI_GCAdapter.cpp +++ b/Source/Core/Core/HW/SI_GCAdapter.cpp @@ -376,7 +376,8 @@ void Output(int chan, u8 rumble_command) if (SConfig::GetInstance().m_GameCubeAdapterThread) { libusb_interrupt_transfer(s_handle, s_endpoint_out, rumble, sizeof(rumble), &size, 16); - if (size != 0x05) + // Netplay sends invalid data which results in size = 0x00. Ignore it. + if (size != 0x05 && size != 0x00) { INFO_LOG(SERIALINTERFACE, "error writing rumble (size: %d)", size); Shutdown(); From 4cf4cee30ecfa6958342bcf954663932b65716a2 Mon Sep 17 00:00:00 2001 From: skidau Date: Thu, 5 Mar 2015 23:30:43 +1100 Subject: [PATCH 3/4] Removed the GC Adapter "Use Thread" option as it was not useful. --- Source/Core/Core/ConfigManager.cpp | 2 - Source/Core/Core/ConfigManager.h | 1 - Source/Core/Core/HW/SI_GCAdapter.cpp | 84 ++----------------- .../Core/DolphinWX/ControllerConfigDiag.cpp | 8 -- Source/Core/DolphinWX/ControllerConfigDiag.h | 5 -- 5 files changed, 7 insertions(+), 93 deletions(-) diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 0fbce5fae6..1d3a598624 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -353,7 +353,6 @@ void SConfig::SaveCoreSettings(IniFile& ini) core->Set("GFXBackend", m_LocalCoreStartupParameter.m_strVideoBackend); core->Set("GPUDeterminismMode", m_LocalCoreStartupParameter.m_strGPUDeterminismMode); core->Set("GameCubeAdapter", m_GameCubeAdapter); - core->Set("GameCubeAdapterThread", m_GameCubeAdapterThread); } void SConfig::SaveMovieSettings(IniFile& ini) @@ -595,7 +594,6 @@ void SConfig::LoadCoreSettings(IniFile& ini) core->Get("GFXBackend", &m_LocalCoreStartupParameter.m_strVideoBackend, ""); core->Get("GPUDeterminismMode", &m_LocalCoreStartupParameter.m_strGPUDeterminismMode, "auto"); core->Get("GameCubeAdapter", &m_GameCubeAdapter, true); - core->Get("GameCubeAdapterThread", &m_GameCubeAdapterThread, true); } void SConfig::LoadMovieSettings(IniFile& ini) diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 054e04a1ac..80f0523208 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -114,7 +114,6 @@ struct SConfig : NonCopyable // Input settings bool m_BackgroundInput; bool m_GameCubeAdapter; - bool m_GameCubeAdapterThread; SysConf* m_SYSCONF; diff --git a/Source/Core/Core/HW/SI_GCAdapter.cpp b/Source/Core/Core/HW/SI_GCAdapter.cpp index bae96a1ccf..64568ad052 100644 --- a/Source/Core/Core/HW/SI_GCAdapter.cpp +++ b/Source/Core/Core/HW/SI_GCAdapter.cpp @@ -43,26 +43,6 @@ static u8 s_endpoint_out = 0; static u64 s_last_init = 0; -#if defined(_WIN32) -#define LIBUSB_CALL WINAPI -#else -#define LIBUSB_CALL -#endif -extern "C" -{ - void LIBUSB_CALL read_callback(libusb_transfer* transfer); -} - -static void HandleEvents() -{ - timeval tv = {1, 0}; - while (s_adapter_thread_running.IsSet()) - { - libusb_handle_events_timeout_completed(s_libusb_context, &tv, NULL); - Common::YieldCPU(); - } -} - static void Read() { while (s_adapter_thread_running.IsSet()) @@ -225,28 +205,14 @@ void AddGCAdapter(libusb_device* device) unsigned char payload = 0x13; libusb_interrupt_transfer(s_handle, s_endpoint_out, &payload, sizeof(payload), &tmp, 16); - if (SConfig::GetInstance().m_GameCubeAdapterThread) - { - s_adapter_thread_running.Set(true); - s_adapter_thread = std::thread(Read); - } - else - { - s_irq_transfer_read = libusb_alloc_transfer(0); - s_irq_transfer_write = libusb_alloc_transfer(0); - libusb_fill_interrupt_transfer(s_irq_transfer_read, s_handle, s_endpoint_in, s_controller_payload_swap, sizeof(s_controller_payload_swap), read_callback, NULL, 0); - libusb_submit_transfer(s_irq_transfer_read); - - s_adapter_thread_running.Set(true); - s_adapter_thread = std::thread(HandleEvents); - } + s_adapter_thread_running.Set(true); + s_adapter_thread = std::thread(Read); s_detected = true; } void Shutdown() { - Reset(); if (s_libusb_context) @@ -263,26 +229,11 @@ void Reset() if (!SConfig::GetInstance().m_GameCubeAdapter) return; - if (!SConfig::GetInstance().m_GameCubeAdapterThread) - { - - if (s_irq_transfer_read) - libusb_cancel_transfer(s_irq_transfer_read); - if (s_irq_transfer_write) - libusb_cancel_transfer(s_irq_transfer_write); - } - if (s_adapter_thread_running.TestAndClear()) { s_adapter_thread.join(); } - if (!SConfig::GetInstance().m_GameCubeAdapterThread) - { - libusb_free_transfer(s_irq_transfer_read); - libusb_free_transfer(s_irq_transfer_write); - } - if (s_handle) { libusb_release_interface(s_handle, 0); @@ -373,20 +324,12 @@ void Output(int chan, u8 rumble_command) unsigned char rumble[5] = { 0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2], s_controller_rumble[3] }; int size = 0; - if (SConfig::GetInstance().m_GameCubeAdapterThread) + libusb_interrupt_transfer(s_handle, s_endpoint_out, rumble, sizeof(rumble), &size, 16); + // Netplay sends invalid data which results in size = 0x00. Ignore it. + if (size != 0x05 && size != 0x00) { - libusb_interrupt_transfer(s_handle, s_endpoint_out, rumble, sizeof(rumble), &size, 16); - // Netplay sends invalid data which results in size = 0x00. Ignore it. - if (size != 0x05 && size != 0x00) - { - INFO_LOG(SERIALINTERFACE, "error writing rumble (size: %d)", size); - Shutdown(); - } - } - else - { - libusb_fill_interrupt_transfer(s_irq_transfer_write, s_handle, s_endpoint_out, rumble, sizeof(rumble), NULL, &size, 16); - libusb_submit_transfer(s_irq_transfer_write); + INFO_LOG(SERIALINTERFACE, "error writing rumble (size: %d)", size); + Shutdown(); } } } @@ -401,17 +344,4 @@ bool IsDriverDetected() return !s_libusb_driver_not_supported; } -void LIBUSB_CALL read_callback(libusb_transfer *transfer) -{ - if (transfer->status == LIBUSB_TRANSFER_COMPLETED) - { - { - std::lock_guard lk(s_mutex); - s_controller_payload_size = transfer->actual_length; - memcpy(s_controller_payload, s_controller_payload_swap, s_controller_payload_size); - } - libusb_submit_transfer(s_irq_transfer_read); - } -} - } // end of namespace SI_GCAdapter diff --git a/Source/Core/DolphinWX/ControllerConfigDiag.cpp b/Source/Core/DolphinWX/ControllerConfigDiag.cpp index 6dec417c1c..909f70b1b1 100644 --- a/Source/Core/DolphinWX/ControllerConfigDiag.cpp +++ b/Source/Core/DolphinWX/ControllerConfigDiag.cpp @@ -152,11 +152,7 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateGamecubeSizer() wxCheckBox* const gamecube_adapter = new wxCheckBox(this, wxID_ANY, _("Direct Connect")); gamecube_adapter->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnGameCubeAdapter, this); - wxCheckBox* const gamecube_adapter_thread = new wxCheckBox(this, wxID_ANY, _("Use Thread")); - gamecube_adapter_thread->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnGameCubeAdapterThread, this); - gamecube_adapter_sizer->Add(gamecube_adapter, 0, wxEXPAND); - gamecube_adapter_sizer->Add(gamecube_adapter_thread, 0, wxEXPAND); gamecube_adapter_group->Add(gamecube_adapter_sizer, 0, wxEXPAND); gamecube_static_sizer->Add(gamecube_adapter_group, 0, wxEXPAND); @@ -169,17 +165,13 @@ wxStaticBoxSizer* ControllerConfigDiag::CreateGamecubeSizer() gamecube_adapter->SetLabelText(_("Adapter Not Detected")); gamecube_adapter->SetValue(false); gamecube_adapter->Disable(); - gamecube_adapter_thread->SetValue(false); - gamecube_adapter_thread->Disable(); } else { gamecube_adapter->SetValue(SConfig::GetInstance().m_GameCubeAdapter); - gamecube_adapter_thread->SetValue(SConfig::GetInstance().m_GameCubeAdapterThread); if (Core::GetState() != Core::CORE_UNINITIALIZED) { gamecube_adapter->Disable(); - gamecube_adapter_thread->Disable(); } } #endif diff --git a/Source/Core/DolphinWX/ControllerConfigDiag.h b/Source/Core/DolphinWX/ControllerConfigDiag.h index 6a226eb1e0..ea31226359 100644 --- a/Source/Core/DolphinWX/ControllerConfigDiag.h +++ b/Source/Core/DolphinWX/ControllerConfigDiag.h @@ -64,11 +64,6 @@ public: SConfig::GetInstance().m_GameCubeAdapter = event.IsChecked(); event.Skip(); } - void OnGameCubeAdapterThread(wxCommandEvent& event) - { - SConfig::GetInstance().m_GameCubeAdapterThread = event.IsChecked(); - event.Skip(); - } private: wxStaticBoxSizer* CreateGamecubeSizer(); From 203c64e66d7c0de24377c8cdbb78dfd709bf1d13 Mon Sep 17 00:00:00 2001 From: skidau Date: Thu, 5 Mar 2015 23:57:18 +1100 Subject: [PATCH 4/4] Changed the GC Adapter rumble command to work like other controllers. --- Source/Core/Core/HW/SI_DeviceGCController.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/HW/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI_DeviceGCController.cpp index 5fcd50aaa0..4e923c1f21 100644 --- a/Source/Core/Core/HW/SI_DeviceGCController.cpp +++ b/Source/Core/Core/HW/SI_DeviceGCController.cpp @@ -270,7 +270,13 @@ void CSIDevice_GCController::SendCommand(u32 _Cmd, u8 _Poll) const u8 numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber); #if defined(__LIBUSB__) || defined (_WIN32) - SI_GCAdapter::Output(numPAD, command.Parameter1 & 0xff); + if (numPAD < 4) + { + if (uType == 1 && uStrength > 2) + SI_GCAdapter::Output(numPAD, 1); + else + SI_GCAdapter::Output(numPAD, 0); + } #endif if (numPAD < 4) {