View Full Version : Xbox 360 Controller EventClient
I wrote an EventClient in C++ for the Xbox 360 Controller for Windows. I've tested it in Windows Vista 32bit. From trac:
"This patch adds the C++ code for an Xbox 360 Controller EventClient for Windows (using XINPUT). A new project is added to the XBMC VSE2008 solution from which the EventClient can be compiled. The EventClient has no user interface - it simply sends the data received from the first connected controller to XBMC listening on localhost (using the "XG" [Xbox gamepad] device map). At the moment, I do not have time to add further features, so I'm submitting the patch as the basic functionality is working correctly."
jhsrennie
2008-11-11, 08:41
Can you post a link to the ticket? I've been struggling to get an eventclient to work and I would be very interested to see your code.
Thanks,
John Rennie
Here's the link to the trac ticket: http://xbmc.org/trac/ticket/5299
To write an EventClient in C++, you use the class CXBMCClient defined in xbmcclient.h. The SendButton method is used to send button presses to XBMC. Be sure to have a look at xbmcclient.h - there you find which flags the SendButton method supports.
That's it in a nutshell. Have a look at the code, it's rather self-explanatory.
jhsrennie
2008-11-12, 12:39
The problem I had was working out what to send. For example I worked out that you have to OR the keycode with 0xF000 by trial and error. Also my example doesn't work unless I include BTN_QUEUE in the flags, but I can't find a description of what this flag means or why it might be necessary. I notice your code does not use it.
John Rennie
I solved the problem of knowing which strings to send for which buttons by looking at ButtonTranslator.cpp (http://xbmc.org/trac/browser/trunk/XBMC/xbmc/ButtonTranslator.cpp) - in the Translate*String functions you can find the names used for the buttons/keys.
I don't know about the BTN_QUEUE flag, though - my code appears to work without it.
Unfortunately I can't test this due to a missing x360 controller but I'm happy that someone tried the event client method. It would be nice if we could get more event clients also for other remotes and together with topfs we might add missing pieces to the event server.
jhsrennie
2008-11-13, 10:42
Having to run separate processes is always going to be clunky. The event server is neat, but I don't think it's ideal for supporting things like IR remotes. I can see a role for controlling XBMC remotely from a different PC, but I doubt this would be a common requirement.
The best solution would be to support event hooks in a dll. This is pretty standard practice in Windows, though I don't know how easy it would be to do cross platform without an untidy maze of #ifdefs.
JR
@jhsrennie: could you be more specific ? On a low scaled htpc, i can evaluate how task switching may be painful, fe while decoding some hd video... but on a reasonably modern box, i'm pretty confident about multitasking a bunch(3-4) of spinning tasks, and still having good response-time... Is the hd decoding, the worst case situation you're afraid of ?
Awen
ultrabrutal
2008-11-24, 17:03
Would it be possible to get it to work on the old Xbox provided you add the wireless receiver via USB available for the pc?
Can't get this patch applied with tortoiseSVN, it doesn't like line 486 for some reason...
Would it be possible to get it to work on the old Xbox provided you add the wireless receiver via USB available for the pc?
I do not know this, but my guess would be: no. You would need to ask someone who is more familiar with the Xbox port of XBMC than me to know for sure, though.
Can't get this patch applied with tortoiseSVN, it doesn't like line 486 for some reason...
Well, the patch should apply cleanly to the SVN version from two months ago, when I submitted it :)
I'll have a look at problem as soon as I can and report back.
Well, the patch should apply cleanly to the SVN version from two months ago, when I submitted it :)
I'll have a look at problem as soon as I can and report back.
Well, to be honest, I tried it 2 months ago and tortoiseSVN didn't like it back then either. I just ignored it as I thought it would be added to SVN anyway.
Last night I thought I would try it again, and it failed. I decided to patch it manually.
I encountered a few problems like the unknown location of xbmcclient.h, so I tried to add it to the headerfiles. That didn't work so I copied it to the xbox360evenclient folder and it compiled (with BuildSetup.bat), but only the eventclient and no XBMC. :P
Thanks for the reply though, I'll wait for an updated patch. :)
ultrabrutal
2009-01-10, 18:36
I do not know this, but my guess would be: no.
Well the XBMC xbox version has the event server built in, so basicly adding a USB receiver to my server and two Xbmc 360 wireless remotes, should make it possible to access these two Xboxes? You see I have 3 xboxes and only one working logitech controller left :( The two Xboxes are close enough for my PC server to be able to work with the USB receiver I think.
Well the XBMC xbox version has the event server built in, so basicly adding a USB receiver to my server and two Xbmc 360 wireless remotes, should make it possible to access these two Xboxes? You see I have 3 xboxes and only one working logitech controller left :( The two Xboxes are close enough for my PC server to be able to work with the USB receiver I think.
Ah, I think I misread your original question. To clarify: I believe it will be impossible to use the XBox360 Controller by connecting the USB receiver directly to the XBox.
On the other hand, using the XBox360 Controller together with the EventClient on Windows and telling the EventClient to send events to the XBMC instance running on the XBox should work! I think this is what you were referring to anyways, I'm sorry that I misunderstood your post!
In any case, I haven't been able to work on updating the patch yet. I hope to be able to do some work on it either this or the next weekend. Sorry about the delay!
Thanks for the reply though, I'll wait for an updated patch. :)
I posted an updated diff to http://xbmc.org/trac/ticket/5299. The diff should now apply cleanly to the SVN version (this time, I checked out a fresh copy and verified this fact).
I posted an updated diff to http://xbmc.org/trac/ticket/5299. The diff should now apply cleanly to the SVN version (this time, I checked out a fresh copy and verified this fact).
Thank you, it patched correctly now. :)
I compiled an installer and installed it, however the controller doesn't work. Am I missing something? (Tested on Vista Home Basic 32bit, Vista Home Premium 64bit)
Thank you, it patched correctly now. :)
I compiled an installer and installed it, however the controller doesn't work. Am I missing something? (Tested on Vista Home Basic 32bit, Vista Home Premium 64bit)
You need to run the Xbox360EventClient.exe program separately. It should be built to project/VS2008Express/Release/Xbox360EventClient.exe.
Thanks a lot for testing this!
You need to run the Xbox360EventClient.exe program separately. It should be built to project/VS2008Express/Release/Xbox360EventClient.exe.
Thanks a lot for testing this!
Confirmed working on both 32bit and 64bit vista. :)
It still has some things missing like the triggers not doing anything, but I guess that has to do with the mapping?
Also, wouldn't it be more elegant if it was integrated in XBMC or is this just a test?
Confirmed working on both 32bit and 64bit vista. :)
Nice :)
It still has some things missing like the triggers not doing anything, but I guess that has to do with the mapping?
Hm, I don't use the triggers so I don't know - they should work in principle. I will investigate this!
Also, wouldn't it be more elegant if it was integrated in XBMC or is this just a test?
As far as I'm aware, this is the new-ish and preferred way to implement input devices for XBMC (see a related wiki entry here (http://xbmc.org/wiki/?title=EventServer)). Also, by seperating input handling and the other XBMC functions, people can run EventClients and EventServers on different machines, enabling for example the use of the XBox360 controller with XBMC running on an XBox (like ultrabrutal described above), which would otherwise be impossible.
People more involved with the XBMC development should of course feel free to correct any errors in the above explanation!
I submitted an updated patch to http://xbmc.org/trac/ticket/5299#comment:7. Note the following:
a bug is fixed which caused the handling of analog triggers and thumbsticks to be incorrect and
the Xbox360EventClient now has to be compiled separately, using the project file in tools/EventClients/Clients/Xbox360 Controller.
I submitted an updated patch to http://xbmc.org/trac/ticket/5299#comment:7. Note the following:
a bug is fixed which caused the handling of analog triggers and thumbsticks to be incorrect and
the Xbox360EventClient now has to be compiled separately, using the project file in tools/EventClients/Clients/Xbox360 Controller.
Thanks! Great work. :)
First off I'd like to say THANKS FRAIN for this awesome EventClient, IMO XBMC without an Xbox-like controller just isn't the same. I don't mind at all starting it up before XBMC Windows, and it works wonderfully. Also THANKS TEAM XBMC for making the awesomesauce media center for free.
I'm using Vista64 and the Microsoft USB Xbox360 wireless dongle with XBMC Atlanis. I'm using Visual Studio 2008 Pro and not Express, so I don't currently have the ability to make my own builds, but I can at very least compile this EventClient. :)
I have no complaints! One very minor difference from XBMC on the Xbox seems to be with the speed of the acceleration/repeat of the shoulder triggers, which is significantly slower than XBMC Xbox. I have noticed that there are timing knobs in the EventClient config menu, so perhaps I will try tuning that and post the values which feel "Xbox-like".
The other more significant difference is that the original patch does not map anything to the "white" and "black" buttons on the Xbox controller, so there is no way to enqueue playlist items or see the playlist. Fortunately the Xbox 360 Wireless controller has two remaining unmapped buttons, the left and right shoulder buttons.
Here's a small patch which makes the left and right shoulder buttons behave like "white" and "black", respectively. I have tested it, and it works as expected.
I'm not sure what arguments I should give diff to create a .patch, so here's the diff.
tools/EventClients/Clients/Xbox360/Xbox360EventClient.cpp
Xbox360EventClient.shoulderbuttons.patch
"
110,111c110,116
< checkButton(cont, client, 12, "lefttrigger");
< checkButton(cont, client, 13, "righttrigger");
---
> // these buttons are not yet mapped in XBMC/xbmc/ButtonTranslator.cpp
> // and therefore are used as "white" and "black" respectively, as white
> // is left of black on the original xbox controller.
> // checkButton(cont, client, 12, "leftshoulderbutton");
> // checkButton(cont, client, 13, "rightshoulderbutton");
> checkButton(cont, client, 12, "white");
> checkButton(cont, client, 13, "black");
"
I'm don't know why things are defined the way they are in ButtonTranslator.cpp, so I'm not sure whether it's more "correct" to do the above commented "leftshoulderbutton" "rightshoulderbutton" names, and define them in ButtonTranslator.cpp to be equivalent in the UI to "white" and "black?"
=darwin
Opened a new ticket #5896 (http://xbmc.org/trac/ticket/5896) with the shoulder button patch. Hopefully it will get added soon. :)
@ frain
I was wondering... would it be hard to implement the eventclient as a windows service that starts and stops with XBMC? I understand if you don't have the time to do it, but maybe it's not much work?
buntsbergh
2009-02-18, 00:23
@frain
Man, you saved my life. I was going to dump XBMC for Windows because everything I tried getting my Wireless 360 controller to work just wasn't working properly. This Event Client was the cherry on top for me. Many thanks!!
@bb10
I tried and created a service using "sc.exe" (see http://support.microsoft.com/kb/251192/en-us)
After turning "Xbox360EventClient.exe" into a service, it works only during service startup. It somehow doesn't signal Windows that the service is loaded and then exits after timing out with error "Error 1053: The service did not respond to the start or control request in a timely fashion"
It probably has to do with "Xbox360EventClient.exe" having an infinite loop in main().
@darwin
Thanks for the patch.
Meanwhile, you can temporary change "Keymap.xml", replacing everything "white" with "leftshoulderbutton" and "black" with "rightshoulderbutton" which also does the trick.
edit: Never mind, just saw that its already included in 17720 (http://xbmc.org/trac/changeset/17720). thanks bb10
Cheers
Bunts
Thanks for the kind words everyone, I am glad that there are people that find my code useful!
Regarding making the EventClient into a Windows service: I don't know too much about Windows programming, and for me the commandline application suffices. I don't think it should be too hard to do, though: If anyone wants to give it a try, I think the following MSDN article on creating Win32 services in C++ might be a good starting point: http://msdn.microsoft.com/en-us/library/ms810429.aspx.
Is this the EventClient they say is in 9.04???
Then Why isn't my 360 controller recognised? I can't even find EventServer in the settings in 9.04...
hansdampf
2009-05-31, 12:05
how do that thing work? i dont know how to compile things. Can someone provide a compiled file, please.
edit: never mind. i found a compiled file somewhere with google.
it works great!
thanks to the programmers!
edit2:
now i have another question.
if xbmc is not in the foreground of the screen. lets say i start a game. then the controller anyhow sends commands to xbmc. this can have confusing results. is this behavior normal, or i am doing something wrong?
now i have another question.
if xbmc is not in the foreground of the screen. lets say i start a game. then the controller anyhow sends commands to xbmc. this can have confusing results. is this behavior normal, or i am doing something wrong?
That's a good question - I was wondering about that issue, but as I don't launch any programs from XBMC (yet) I did not look into the XBMC code to see how this problem could be fixed.
Probably when things like the XBMC Game Library are done, the XBMC EventServer should ignore EventClient input while other programs are running.
Ok, I need an idiots guide on how to start Eventclient...
In the changelog for 9.04.1 I could read:
* Xbox 360 Controller EventClient
But I can't for the life of me find the eventclient.exe that I need to run, neither does XBMC start it automatically when I plug in my Xbox 360 controller.
Please help!
just use eventghost you add the take create switch events plugins and when example what im using it for mpc-hc you create a macro which will make a folder to run in exclusive mode with the event ex:[Task.NewWindow.mplayerc] and in the exclusive folder you put a macro which detect ex:[Task.ClosedWindow.mplayerc] and desactivate the exclusive mode for the folder.
I run xboxeventclient.exe as a service in windowsXP... but the DOS window opens at and remains there opened, is it possible that when i execute the exe doesn't open any window?
Thx for the asnwers
Hi guys,
thanks for this great program. I run it from XP and everything is perfect with XBMC. Now, I would like to launch Dolphin (emulator) from XBMC with the applauncher but without using this event client to control the emu (it have his own way to do it). Is it possible? Right now, when I do that I control dolphin and at the same time XBMC...not very good.