From e462422ef7c99d752dd3505044fbc9c43969a071 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Wed, 8 Jul 2015 04:10:18 +0200 Subject: [PATCH] Wiimote: (Re-)Connect a disconnected emulated Wiimote when a mapped button is pressed. --- Source/Core/Core/HW/Wiimote.cpp | 22 +++++++++---------- Source/Core/Core/HW/Wiimote.h | 2 +- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 22 +++++++++++++++++++ Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h | 5 +++++ .../Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp | 7 +++--- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 378cc6f52f..a49689dd4e 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -114,22 +114,20 @@ void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size // input: _number: [Description needed] // output: none // -void Update(int _number) +void Update(int _number, bool _connected) { - //PanicAlert( "Wiimote_Update" ); - - // if we are on the next input cycle, update output and input - static int _last_number = 4; - if (_number <= _last_number) + if (_connected) { - g_controller_interface.UpdateInput(); + if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) + ((WiimoteEmu::Wiimote*)s_config.controllers[_number])->Update(); + else + WiimoteReal::Update(_number); } - _last_number = _number; - - if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) - ((WiimoteEmu::Wiimote*)s_config.controllers[_number])->Update(); else - WiimoteReal::Update(_number); + { + if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number]) + ((WiimoteEmu::Wiimote*)s_config.controllers[_number])->ConnectOnInput(); + } } // __________________________________________________________________________________________________ diff --git a/Source/Core/Core/HW/Wiimote.h b/Source/Core/Core/HW/Wiimote.h index 4d64f902b3..051d7cc3e8 100644 --- a/Source/Core/Core/HW/Wiimote.h +++ b/Source/Core/Core/HW/Wiimote.h @@ -48,7 +48,7 @@ InputConfig* GetConfig(); void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); -void Update(int _number); +void Update(int _number, bool _connected); } diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 1d54096bc0..2744cd3156 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -249,6 +249,7 @@ void Wiimote::Reset() Wiimote::Wiimote( const unsigned int index ) : m_index(index) + , m_last_connect_request_counter(0) , ir_sin(0) , ir_cos(1) // , m_sound_stream( nullptr ) @@ -876,6 +877,27 @@ void Wiimote::InterruptChannel(const u16 _channelID, const void* _pData, u32 _Si } } +void Wiimote::ConnectOnInput() +{ + if (m_last_connect_request_counter > 0) + { + --m_last_connect_request_counter; + return; + } + + u16 buttons = 0; + m_buttons->GetState(&buttons, button_bitmasks); + m_dpad->GetState(&buttons, dpad_bitmasks); + + if (buttons != 0) + { + Host_ConnectWiimote(m_index, true); + // arbitrary value so it doesn't try to send multiple requests before Dolphin can react + // if Wiimotes are polled at 200Hz then this results in one request being sent per 500ms + m_last_connect_request_counter = 100; + } +} + void Wiimote::LoadDefaults(const ControllerInterface& ciface) { ControllerEmu::LoadDefaults(ciface); diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index f0ce9a5e38..a62d2919cd 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -121,6 +121,7 @@ public: void Update(); void InterruptChannel(const u16 _channelID, const void* _pData, u32 _Size); void ControlChannel(const u16 _channelID, const void* _pData, u32 _Size); + void ConnectOnInput(); void DoState(PointerWrap& p); void RealState(); @@ -239,6 +240,10 @@ private: u8 play; u8 unk_9; } m_reg_speaker; + + // limits the amount of connect requests we send when a button is pressed in disconnected state + u8 m_last_connect_request_counter; + #pragma pack(pop) }; diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp index bfd90e4652..9cf809afdd 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_usb.cpp @@ -15,6 +15,7 @@ #include "Core/IPC_HLE/WII_IPC_HLE.h" #include "Core/IPC_HLE/WII_IPC_HLE_Device_usb.h" #include "Core/IPC_HLE/WII_IPC_HLE_WiiMote.h" +#include "InputCommon/ControllerInterface/ControllerInterface.h" void CWII_IPC_HLE_Device_usb_oh1_57e_305::EnqueueReply(u32 CommandAddress) @@ -490,11 +491,9 @@ u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() if (now - m_last_ticks > interval) { + g_controller_interface.UpdateInput(); for (unsigned int i = 0; i < m_WiiMotes.size(); i++) - if (m_WiiMotes[i].IsConnected()) - { - Wiimote::Update(i); - } + Wiimote::Update(i, m_WiiMotes[i].IsConnected()); m_last_ticks = now; }