mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 16:19:28 +01:00
Merge pull request #2170 from skidau/pad-origin
Moved the gcpad calibration from construction to runtime.
This commit is contained in:
commit
da56582ba0
@ -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)
|
||||
|
@ -114,7 +114,6 @@ struct SConfig : NonCopyable
|
||||
// Input settings
|
||||
bool m_BackgroundInput;
|
||||
bool m_GameCubeAdapter;
|
||||
bool m_GameCubeAdapterThread;
|
||||
|
||||
SysConf* m_SYSCONF;
|
||||
|
||||
|
@ -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<u8*>(&m_Origin);
|
||||
for (int i = 0; i < (int)sizeof(SOrigin); i++)
|
||||
{
|
||||
@ -282,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)
|
||||
{
|
||||
|
@ -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,19 +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);
|
||||
if (size != 0x05)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -400,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<std::mutex> 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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user