void ChangeWiimoteSource(unsigned int index, int source) { g_wiimote_sources[index] = source; { // kill real connection (or swap to different slot) std::lock_guard<std::mutex> lk(g_wiimotes_mutex); Wiimote* wm = g_wiimotes[index]; if (wm) { g_wiimotes[index] = nullptr; // First see if we can use this real Wiimote in another slot. TryToConnectWiimote(wm); } // else, just disconnect the Wiimote HandleWiimoteDisconnect(index); } // reconnect to the emulator Host_ConnectWiimote(index, false); if (WIIMOTE_SRC_EMU & source) Host_ConnectWiimote(index, true); }
void ChangeWiimoteSource(unsigned int index, int source) { { std::lock_guard<std::recursive_mutex> lk(g_refresh_lock); g_wiimote_sources[index] = source; g_wiimote_scanner.WantWiimotes(0 != CalculateWantedWiimotes()); g_wiimote_scanner.WantBB(0 != CalculateWantedBB()); // kill real connection (or swap to different slot) DoneWithWiimote(index); } // reconnect to the emulator Host_ConnectWiimote(index, false); if (WIIMOTE_SRC_EMU & source) Host_ConnectWiimote(index, true); }
// Read the Wiimote once void Update(int _WiimoteNumber) { std::lock_guard<std::recursive_mutex> lk(g_refresh_lock); if (g_wiimotes[_WiimoteNumber]) g_wiimotes[_WiimoteNumber]->Update(); // Wiimote::Update() may remove the Wiimote if it was disconnected. if (!g_wiimotes[_WiimoteNumber]) { Host_ConnectWiimote(_WiimoteNumber, false); } }
static bool TryToConnectWiimoteToSlot(Wiimote* wm, unsigned int i) { if (WIIMOTE_SRC_REAL & g_wiimote_sources[i] && !g_wiimotes[i]) { if (wm->Connect(i)) { NOTICE_LOG(WIIMOTE, "Connected to Wiimote %i.", i + 1); g_wiimotes[i] = wm; Host_ConnectWiimote(i, true); } return true; } return false; }
// Read the Wiimote once void Update(int _WiimoteNumber) { // Try to get a lock and return without doing anything if we fail // This avoids deadlocks when adding a Wiimote during continuous scan if(!g_refresh_lock.try_lock()) return; if (g_wiimotes[_WiimoteNumber]) g_wiimotes[_WiimoteNumber]->Update(); // Wiimote::Update() may remove the Wiimote if it was disconnected. if (!g_wiimotes[_WiimoteNumber]) { Host_ConnectWiimote(_WiimoteNumber, false); } g_refresh_lock.unlock(); }
// Read the Wiimote once void Update(int wiimote_number) { // Try to get a lock and return without doing anything if we fail // This avoids blocking the CPU thread if (!g_wiimotes_mutex.try_lock()) return; if (g_wiimotes[wiimote_number]) g_wiimotes[wiimote_number]->Update(); // Wiimote::Update() may remove the Wiimote if it was disconnected. if (!g_wiimotes[wiimote_number]) { Host_ConnectWiimote(wiimote_number, false); } g_wiimotes_mutex.unlock(); }
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; } } }