Fix Prepare (Set LEDs and Rumble) on Connect and Refresh

m_need_prepare needs to be set before the Device thread is started.
Otherwise the thread blocks on IORead and the LEDs and Rumble is executed
after the user presses a button on the Wiimote.
Also the Prepare-Call on Refresh doesn't need to reset the Index, because it is
set once on the initial Connect/Prepare. Therefore the index assignment
was refactored.
This commit is contained in:
Julian Löhr 2015-11-12 17:57:33 +01:00
parent 662e4fcca0
commit 31a4b2ed03
3 changed files with 20 additions and 12 deletions

View File

@ -518,13 +518,13 @@ void WiimoteDarwinHid::RemoveCallback(void* context, IOReturn result, void*)
if (length > MAX_PAYLOAD) { if (length > MAX_PAYLOAD) {
WARN_LOG(WIIMOTE, "Dropping packet for Wiimote %i, too large", WARN_LOG(WIIMOTE, "Dropping packet for Wiimote %i, too large",
wm->m_index + 1); wm->GetIndex() + 1);
return; return;
} }
if (wm->m_inputlen != -1) { if (wm->m_inputlen != -1) {
WARN_LOG(WIIMOTE, "Dropping packet for Wiimote %i, queue full", WARN_LOG(WIIMOTE, "Dropping packet for Wiimote %i, queue full",
wm->m_index + 1); wm->GetIndex() + 1);
return; return;
} }
@ -556,7 +556,7 @@ void WiimoteDarwinHid::RemoveCallback(void* context, IOReturn result, void*)
return; return;
} }
WARN_LOG(WIIMOTE, "Lost channel to Wiimote %i", wm->m_index + 1); WARN_LOG(WIIMOTE, "Lost channel to Wiimote %i", wm->GetIndex() + 1);
wm->DisconnectInternal(); wm->DisconnectInternal();
} }

View File

@ -338,10 +338,10 @@ void Wiimote::ConnectOnInput()
} }
} }
void Wiimote::Prepare(int _index) void Wiimote::Prepare()
{ {
m_index = _index;
m_need_prepare.store(true); m_need_prepare.store(true);
IOWakeup();
} }
bool Wiimote::PrepareOnThread() bool Wiimote::PrepareOnThread()
@ -523,8 +523,11 @@ void WiimoteScanner::ThreadFunc()
NOTICE_LOG(WIIMOTE, "Wiimote scanning has stopped."); NOTICE_LOG(WIIMOTE, "Wiimote scanning has stopped.");
} }
bool Wiimote::Connect() bool Wiimote::Connect(int index)
{ {
m_index = index;
m_need_prepare.store(true);
if (!m_run_thread.load()) if (!m_run_thread.load())
{ {
m_thread_ready.store(false); m_thread_ready.store(false);
@ -605,6 +608,11 @@ void Wiimote::ThreadFunc()
DisconnectInternal(); DisconnectInternal();
} }
int Wiimote::GetIndex() const
{
return m_index;
}
void LoadSettings() void LoadSettings()
{ {
std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + WIIMOTE_INI_NAME ".ini"; std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + WIIMOTE_INI_NAME ".ini";
@ -725,9 +733,8 @@ static bool TryToConnectWiimoteN(Wiimote* wm, unsigned int i)
{ {
if (WIIMOTE_SRC_REAL & g_wiimote_sources[i] && !g_wiimotes[i]) if (WIIMOTE_SRC_REAL & g_wiimote_sources[i] && !g_wiimotes[i])
{ {
if (wm->Connect()) if (wm->Connect(i))
{ {
wm->Prepare(i);
NOTICE_LOG(WIIMOTE, "Connected to Wiimote %i.", i + 1); NOTICE_LOG(WIIMOTE, "Connected to Wiimote %i.", i + 1);
g_wiimotes[i] = wm; g_wiimotes[i] = wm;
Host_ConnectWiimote(i, true); Host_ConnectWiimote(i, true);
@ -840,7 +847,7 @@ void Refresh()
{ {
if (g_wiimotes[i]) if (g_wiimotes[i])
{ {
g_wiimotes[i]->Prepare(i); g_wiimotes[i]->Prepare();
} }
} }

View File

@ -60,12 +60,12 @@ public:
virtual bool ConnectInternal() = 0; virtual bool ConnectInternal() = 0;
virtual void DisconnectInternal() = 0; virtual void DisconnectInternal() = 0;
bool Connect(); bool Connect(int index);
// TODO: change to something like IsRelevant // TODO: change to something like IsRelevant
virtual bool IsConnected() const = 0; virtual bool IsConnected() const = 0;
void Prepare(int index); void Prepare();
bool PrepareOnThread(); bool PrepareOnThread();
void DisableDataReporting(); void DisableDataReporting();
@ -74,10 +74,11 @@ public:
void QueueReport(u8 rpt_id, const void* data, unsigned int size); void QueueReport(u8 rpt_id, const void* data, unsigned int size);
int m_index; int GetIndex() const;
protected: protected:
Wiimote(); Wiimote();
int m_index;
Report m_last_input_report; Report m_last_input_report;
u16 m_channel; u16 m_channel;
u8 m_last_connect_request_counter; u8 m_last_connect_request_counter;