Skip to content

Commit

Permalink
Merge pull request #3286 from jloehr/Wiimote-Rumble-LED-Fix
Browse files Browse the repository at this point in the history
Fix Prepare (Set LEDs and Rumble) on Connect and Refresh
  • Loading branch information
phire committed Nov 28, 2015
2 parents 861bd98 + 31a4b2e commit 97cd723
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Source/Core/Core/HW/WiimoteReal/IOdarwin.mm
Expand Up @@ -518,13 +518,13 @@ - (void) l2capChannelData: (IOBluetoothL2CAPChannel *) l2capChannel

if (length > MAX_PAYLOAD) {
WARN_LOG(WIIMOTE, "Dropping packet for Wiimote %i, too large",
wm->m_index + 1);
wm->GetIndex() + 1);
return;
}

if (wm->m_inputlen != -1) {
WARN_LOG(WIIMOTE, "Dropping packet for Wiimote %i, queue full",
wm->m_index + 1);
wm->GetIndex() + 1);
return;
}

Expand Down Expand Up @@ -556,7 +556,7 @@ - (void) l2capChannelClosed: (IOBluetoothL2CAPChannel *) l2capChannel
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();
}
Expand Down
19 changes: 13 additions & 6 deletions Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
Expand Up @@ -338,10 +338,10 @@ void Wiimote::ConnectOnInput()
}
}

void Wiimote::Prepare(int _index)
void Wiimote::Prepare()
{
m_index = _index;
m_need_prepare.store(true);
IOWakeup();
}

bool Wiimote::PrepareOnThread()
Expand Down Expand Up @@ -523,8 +523,11 @@ void WiimoteScanner::ThreadFunc()
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())
{
m_thread_ready.store(false);
Expand Down Expand Up @@ -605,6 +608,11 @@ void Wiimote::ThreadFunc()
DisconnectInternal();
}

int Wiimote::GetIndex() const
{
return m_index;
}

void LoadSettings()
{
std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + WIIMOTE_INI_NAME ".ini";
Expand Down Expand Up @@ -725,9 +733,8 @@ static bool TryToConnectWiimoteN(Wiimote* wm, unsigned int 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);
g_wiimotes[i] = wm;
Host_ConnectWiimote(i, true);
Expand Down Expand Up @@ -840,7 +847,7 @@ void Refresh()
{
if (g_wiimotes[i])
{
g_wiimotes[i]->Prepare(i);
g_wiimotes[i]->Prepare();
}
}

Expand Down
7 changes: 4 additions & 3 deletions Source/Core/Core/HW/WiimoteReal/WiimoteReal.h
Expand Up @@ -60,12 +60,12 @@ class Wiimote : NonCopyable
virtual bool ConnectInternal() = 0;
virtual void DisconnectInternal() = 0;

bool Connect();
bool Connect(int index);

// TODO: change to something like IsRelevant
virtual bool IsConnected() const = 0;

void Prepare(int index);
void Prepare();
bool PrepareOnThread();

void DisableDataReporting();
Expand All @@ -74,10 +74,11 @@ class Wiimote : NonCopyable

void QueueReport(u8 rpt_id, const void* data, unsigned int size);

int m_index;
int GetIndex() const;

protected:
Wiimote();
int m_index;
Report m_last_input_report;
u16 m_channel;
u8 m_last_connect_request_counter;
Expand Down

0 comments on commit 97cd723

Please sign in to comment.