Wiimote: (Re-)Connect a disconnected real Wiimote when a button is pressed.
Where disconnected is defined as: The real physical device is still connected to the PC, but the emulated Wii sees the Wiimote as disconnected.
This commit is contained in:
parent
e462422ef7
commit
5594b107eb
|
@ -127,6 +127,8 @@ void Update(int _number, bool _connected)
|
|||
{
|
||||
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number])
|
||||
((WiimoteEmu::Wiimote*)s_config.controllers[_number])->ConnectOnInput();
|
||||
if (WIIMOTE_SRC_REAL & g_wiimote_sources[_number])
|
||||
WiimoteReal::ConnectOnInput(_number);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ Wiimote::Wiimote()
|
|||
: m_index()
|
||||
, m_last_input_report()
|
||||
, m_channel(0)
|
||||
, m_last_connect_request_counter(0)
|
||||
, m_rumble_state()
|
||||
, m_need_prepare()
|
||||
{}
|
||||
|
@ -299,6 +300,43 @@ void Wiimote::Update()
|
|||
}
|
||||
}
|
||||
|
||||
void Wiimote::ConnectOnInput()
|
||||
{
|
||||
if (m_last_connect_request_counter > 0)
|
||||
{
|
||||
--m_last_connect_request_counter;
|
||||
return;
|
||||
}
|
||||
|
||||
const Report& rpt = ProcessReadQueue();
|
||||
if (rpt.size() >= 4)
|
||||
{
|
||||
switch (rpt[1])
|
||||
{
|
||||
case WM_REPORT_CORE:
|
||||
case WM_REPORT_CORE_ACCEL:
|
||||
case WM_REPORT_CORE_EXT8:
|
||||
case WM_REPORT_CORE_ACCEL_IR12:
|
||||
case WM_REPORT_CORE_EXT19:
|
||||
case WM_REPORT_CORE_ACCEL_EXT16:
|
||||
case WM_REPORT_CORE_IR10_EXT9:
|
||||
case WM_REPORT_CORE_ACCEL_IR10_EXT6:
|
||||
case WM_REPORT_INTERLEAVE1:
|
||||
case WM_REPORT_INTERLEAVE2:
|
||||
// check any button without checking accelerometer data
|
||||
if ((rpt[2] & 0x1F) != 0 || (rpt[3] & 0x9F) != 0)
|
||||
{
|
||||
Host_ConnectWiimote(m_index, true);
|
||||
// see WiimoteEmu::Wiimote::ConnectOnInput(), same idea here
|
||||
m_last_connect_request_counter = 100;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Wiimote::Prepare(int _index)
|
||||
{
|
||||
m_index = _index;
|
||||
|
@ -847,6 +885,18 @@ void Update(int _WiimoteNumber)
|
|||
g_refresh_lock.unlock();
|
||||
}
|
||||
|
||||
void ConnectOnInput(int _WiimoteNumber)
|
||||
{
|
||||
// see Update() above
|
||||
if (!g_refresh_lock.try_lock())
|
||||
return;
|
||||
|
||||
if (g_wiimotes[_WiimoteNumber])
|
||||
g_wiimotes[_WiimoteNumber]->ConnectOnInput();
|
||||
|
||||
g_refresh_lock.unlock();
|
||||
}
|
||||
|
||||
void StateChange(EMUSTATE_CHANGE newState)
|
||||
{
|
||||
//std::lock_guard<std::recursive_mutex> lk(g_refresh_lock);
|
||||
|
|
|
@ -36,6 +36,7 @@ public:
|
|||
void ControlChannel(const u16 channel, const void* const data, const u32 size);
|
||||
void InterruptChannel(const u16 channel, const void* const data, const u32 size);
|
||||
void Update();
|
||||
void ConnectOnInput();
|
||||
|
||||
const Report& ProcessReadQueue();
|
||||
|
||||
|
@ -80,6 +81,7 @@ protected:
|
|||
Wiimote();
|
||||
Report m_last_input_report;
|
||||
u16 m_channel;
|
||||
u8 m_last_connect_request_counter;
|
||||
|
||||
private:
|
||||
void ClearReadQueue();
|
||||
|
@ -154,6 +156,7 @@ extern Wiimote *g_wiimotes[MAX_BBMOTES];
|
|||
void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size);
|
||||
void ControlChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size);
|
||||
void Update(int _WiimoteNumber);
|
||||
void ConnectOnInput(int _WiimoteNumber);
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
void StateChange(EMUSTATE_CHANGE newState);
|
||||
|
|
Loading…
Reference in New Issue