Esempio n. 1
0
void WiimoteScanner::ThreadFunc()
{
  Common::SetCurrentThreadName("Wiimote Scanning Thread");

  NOTICE_LOG(WIIMOTE, "Wiimote scanning thread has started.");

  while (m_scan_thread_running.IsSet())
  {
    m_scan_mode_changed_event.WaitFor(std::chrono::milliseconds(500));

    CheckForDisconnectedWiimotes();

    if (m_scan_mode.load() == WiimoteScanMode::DO_NOT_SCAN)
      continue;

    for (const auto& backend : m_scanner_backends)
    {
      if (CalculateWantedWiimotes() != 0 || CalculateWantedBB() != 0)
      {
        std::vector<Wiimote*> found_wiimotes;
        Wiimote* found_board = nullptr;
        backend->FindWiimotes(found_wiimotes, found_board);
        {
          std::lock_guard<std::mutex> lk(g_wiimotes_mutex);
          std::for_each(found_wiimotes.begin(), found_wiimotes.end(), TryToConnectWiimote);
          if (found_board)
            TryToConnectBalanceBoard(found_board);
        }
      }
      else
      {
        backend->Update();  // Does stuff needed to detect disconnects on Windows
      }
    }

    if (m_scan_mode.load() == WiimoteScanMode::SCAN_ONCE)
      m_scan_mode.store(WiimoteScanMode::DO_NOT_SCAN);
  }

  NOTICE_LOG(WIIMOTE, "Wiimote scanning thread has stopped.");
}
Esempio n. 2
0
void WiimoteScanner::ThreadFunc()
{
	Common::SetCurrentThreadName("Wiimote Scanning Thread");

	NOTICE_LOG(WIIMOTE, "Wiimote scanning has started.");

	while (m_run_thread.load())
	{
		std::vector<Wiimote*> found_wiimotes;
		Wiimote* found_board = nullptr;

		//NOTICE_LOG(WIIMOTE, "In loop");

		if (m_want_wiimotes.load() || m_want_bb.load())
		{
			FindWiimotes(found_wiimotes, found_board);
		}
		else
		{
			// Does stuff needed to detect disconnects on Windows
			Update();
		}

		//NOTICE_LOG(WIIMOTE, "After update");

		// TODO: this is a fairly lame place for this
		CheckForDisconnectedWiimotes();

		if (m_want_wiimotes.load())
			HandleFoundWiimotes(found_wiimotes);

		if (m_want_bb.load() && found_board)
			TryToConnectBalanceBoard(found_board);

		//std::this_thread::yield();
		Common::SleepCurrentThread(500);
	}

	NOTICE_LOG(WIIMOTE, "Wiimote scanning has stopped.");
}
Esempio n. 3
0
// This is called from the GUI thread
void Refresh()
{
	g_wiimote_scanner.StopScanning();

	{
		std::unique_lock<std::recursive_mutex> lk(g_refresh_lock);
		std::vector<Wiimote*> found_wiimotes;
		Wiimote* found_board = nullptr;

		if (0 != CalculateWantedWiimotes() || 0 != CalculateWantedBB())
		{
			// Don't hang Dolphin when searching
			lk.unlock();
			g_wiimote_scanner.FindWiimotes(found_wiimotes, found_board);
			lk.lock();
		}

		CheckForDisconnectedWiimotes();

		// Brief rumble for already connected Wiimotes.
		// Don't do this for Balance Board as it doesn't have rumble anyway.
		for (int i = 0; i < MAX_WIIMOTES; ++i)
		{
			if (g_wiimotes[i])
			{
				g_wiimotes[i]->Prepare(i);
			}
		}

		HandleFoundWiimotes(found_wiimotes);
		if (found_board)
			TryToConnectBalanceBoard(found_board);
	}

	Initialize();
}