Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a background thread to detect the GC adapter #2330

Merged
merged 2 commits into from May 1, 2015

Conversation

mathieui
Copy link
Member

This should take care of connecting/disconnecting the GC adapter while dolphin is running; previously, dolphin would simply disable the functionality if the adapter wasn’t available on startup.

The thread polls libusb every 500ms if no adapter is found, and it receives a callback from the controller window where it displays the current adapter status (Found/Not Found/Driver not detected).

Why it's not perfect:

  • Due to how it works, we can only detect that an adapter has been disconnected when in-game, because otherwise we don't read from the device. (adding a thread which sole goal would be to make sure an adapter is connected seems overkill)
  • An option to enable/disable the thread is possible; but is it necessary? (or maybe I should disable it when the direct connect option is unchecked)


wxCheckBox* const gamecube_adapter = new wxCheckBox(this, wxID_ANY, _("Direct Connect"));
gamecube_adapter->Bind(wxEVT_CHECKBOX, &ControllerConfigDiag::OnGameCubeAdapter, this);
m_adapter_status = new wxStaticText(this, wxID_ANY, _(""));

This comment was marked as off-topic.

@mathieui mathieui force-pushed the background-gc-adapter-scan branch 2 times, most recently from 8e987ad to a5984a7 Compare April 26, 2015 22:54
@skidau
Copy link
Contributor

skidau commented Apr 27, 2015

Probably should disable the thread when the direct connect option is unchecked.

@comex
Copy link
Contributor

comex commented Apr 28, 2015

There should not be an option to run the thread (as opposed to disabling direct connection entirely), as there would be no point changing it.

Can you please use the libusb hotplug API where available? I don't think it supports Windows, but it supports the other major operating systems. This avoids the delay of polling.

I haven't really looked at the code, but I don't understand why you would need an additional thread to ensure the device stays connected when you already have one that detects if it is connected.

@mathieui
Copy link
Member Author

@comex the Read() thread does not detect anything, it merely performs a dumb read & copy, adding stuff into that loop may add undesirable latency to inputs. However using the hotplug API is a good idea (but still needs a thread on its own, because hotplug needs blocking or frequent calls to handle_events()), so I'm working on integrating both solutions (the first one I coded and the hotplug) and use whichever is available on the platform using the libusb capabilities.

@JMC47
Copy link
Contributor

JMC47 commented Apr 30, 2015

Is there anything else blocking on this? It's pretty great.

static std::thread s_adapter_detect_thread;
static Common::Flag s_adapter_detect_thread_running;

static std::function<void(void)> s_detect_callback;

This comment was marked as off-topic.

This scanning thread either polls libusb or checks every 500ms for a
change depending on host capabilities. The GC Adapter can now be plugged
and unplugged at any time when dolphin is open, it will be used if the
direct connect option is set.
skidau added a commit that referenced this pull request May 1, 2015
Add a background thread to detect the GC adapter
@skidau skidau merged commit 9348b2e into dolphin-emu:master May 1, 2015
@solidshredder
Copy link

There definitely needs to be an option to disable this thread. It was causing false button presses on my USB DInput Logitech PS3 controller when emulating the classic controller on Wii. It was driving me mad so I decided to track down the exact update that introduced this bug.

@mathieui
Copy link
Member Author

see pr #2744

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants