-
Notifications
You must be signed in to change notification settings - Fork 48
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
How can you tell when a new controller is connected at runtime? #51
Comments
Hi! It currently isn't really set up for detecting connections made on the fly, I'm afraid. Obviously detecting controllers connected after your game/application starts is important. The current way to do it with JSL is probably to have a "detect controllers" button in your settings, and do this repeatedly automatically when there are no controllers connected (or at the "press start" screen when no one has pressed "start" yet) |
Thanks! I thought of handling it that way (with some sort of Let me know if you already know this wouldn't work. It would save me some time. :) |
Oo, that does sound promising! If you do find some success with it, I'd love it if you could make a PR and it could be included in JSL. I have no idea about performance implications, but it's worth exploring |
Hey @gordonglas , this indeed a great feature to have. @Valkirie and me would also like this added in JSL to make use of it within our open source project called Handheld Companion. Has it already piqued your technical curiosity enough to make a start? |
Hi @CasperH2O !, |
Just a quick update. Unfortunately, calling hid_enumerate every game loop frame destroys the framerate, (and all my test app is doing is rendering the FPS - it has no logic/rendering.) Even calling hid_enumerate every second or so could cause very noticeable stutter in gameplay. The real solution is to call hid_enumerate in a separate thread, but making everything thread-safe (particularly the JoyShock objects) is a whole other issue, and not a quick and easy task. Big changes like this will most likely require a major version increment or fork. I do plan on giving it a try though, so I'll update again when I'm further along. No ETA, unfortunately. |
Hi @gordonglas, just a heads-up that I'm exploring a solution for JoyShockLibrary 3.0. Current strategy is making everything thread safe and making it so that JslConnectDevices doesn't create new ids for already-connected devices. At this stage, JoyShockLibrary likely won't handle automatic detection for the user. But the separate thread is a workable strategy with this change to JslConnectDevices. The best solution probably depends on the OS -- on Windows, watch for WM_DEVICECHANGE events and call JslConnectDevices then. It could even be kicked off on another thread to avoid hitching. |
EDIT: meh, I need more coffee, this isn't a C# project, but you can use the code as inspiration 😅 |
@nefarius, your plug is welcome, and this is a good example of where a user might listen for a connection and call JslConnectDevices. In my tests, just calling JslConnectDevices on WM_DEVICECHANGE also seems to be working fine :) |
Hi, I'm wondering how you can use JSL to tell when a new controller is connected during a game. Or is it assumed that you must have everything connected before initializing JSL?
The text was updated successfully, but these errors were encountered: