Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Exposed Joystick Name, Product ID and Manufacturer ID  (Read 30071 times)

0 Members and 1 Guest are viewing this topic.

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Exposed Joystick Name, Product ID and Manufacturer ID
« on: January 04, 2014, 04:59:41 am »
I've made an update to expose the name, product ID and manufacturer ID for joysticks. This is ticket #152 on Github. The commit with these changes is on my fork of SFML.

I'm a C++ noob so I'd like to get a good code review of this change before doing a pull request. Also, I haven't been able to properly test this on Linux (it compiles in VM but by VM software doesn't allow me to connect USB devices) so I'm not certain it functions properly on that platform. If a pull request is preferrable to this forum post let me know and I can do that.

The Changes

JoystickCaps has been renamed JoystickInfo. In addition to the name change three properties have been added to it:

1. name: the name of the joystick.
2. manufacturerID: the joystick manufacturer's ID.
3. productID: the product ID of the joystick.

sf::Joystick has three new functions that correspond with these values:

1. getName(unsigned int index): return the name of the joystick at index as an sf::String.
2. getManufacturerID(unsigned int index): returns the manufacturer ID at index as an unsigned int.
3. getProductID(unsigned int index): returns the product ID at index as an unsigned int.

Testing

I've been using this update on Mac OS and Windows for awhile and all is well (for me anyway). The Linux implementation compiles but I'm running Ubuntu in a virtual machine and am unable to connect USB devices to it so I cannot put it to the test.

Platforms

On the Mac side of things I'm running 10.7 Lion with Xcode 4.6. I'm compiling with C++11 support using Clang.

On Windows I'm running Windows 8 x64 with Mingw 4.6.2.

On Ubuntu I'm running 13.10 x64 with GCC 4.8.x.

Controllers

I've tested with the following controllers (drivers listed in instances were the manufacturer does not provide one for the platform):

- Xbox 360, wired (Windows, Mac via Tattiebogle v0.08 Driver)
- Xbox 360, wireless (Windows)
- PS3 (Windows via Motioninjoy v0.7 Driver, Mac)
- Wiimote, no attachments, with nunchuck, with classic controller (Mac via WJoy v0.7.1 Driver)



I feel good about the Mac and Windows implementations. Can someone please give the Linux version a try and let me know how/if it works?

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #1 on: January 13, 2014, 12:21:57 am »
This looks good! Sadly I don't have a joystick here to test it.
Maybe you should also leave a note about your fork on the github tracker, so this doesn't get lost in the forum.

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #2 on: January 13, 2014, 04:59:52 am »
This looks good!
:)
Sadly I don't have a joystick here to test it.
:(

I've posted to the #152 ticket on Github with a note about this thread.

As an aside, are you running Linux? In a dual-boot setup with Windows perhaps? I'd like to get something like that setup so I can properly test Linux stuff but all the guides I've read make me a bit worried that I might hose my Windows install.


Fizix

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #3 on: January 13, 2014, 09:16:50 am »
As an aside, are you running Linux? In a dual-boot setup with Windows perhaps? I'd like to get something like that setup so I can properly test Linux stuff but all the guides I've read make me a bit worried that I might hose my Windows install.

Try the Ubuntu windows installer.  You can dual boot without having to change partitions.  And you can even uninstall it if you don't like it.

http://www.ubuntu.com/download/desktop/install-ubuntu-with-windows

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #4 on: January 13, 2014, 10:48:35 am »
If you've got a not too old CPU with virtualization instructions, I'd just use virtualization to boot a Unix installation while you're in Windows (Core 2 Quad is more than enough, although an i-7 will get you almost native speeds).

I'm using Linux Mint inside Virtual Box and it runs flawlessly. No need to worry about dual booting. Although I've used Wubi in the past, I think it might cause problems with newer systems and secure boot. Other than that, it's pretty safe to use, just like any Windows program. Just make sure to stay away from partitioning tools and things such as Grub while under Unix.

Back to the patch:

While I haven't tried it, just out of interest: Do you even have to go through the registry to get the name under Windows? The JOYCAPS structure already got a name field. Although I'm not sure how accurate this is or if it's still populated.

Also not sure about the UNICODE macro magic, since all versions of Windows being supported got the full wide char set implemented (so just use that).

Plus I think it shouldn't return "Unknown Joystick" if a device isn't present/connected at all.
« Last Edit: January 13, 2014, 11:47:18 am by Mario »

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #5 on: January 13, 2014, 06:26:26 pm »
If you've got a not too old CPU with virtualization instructions, I'd just use virtualization to boot a Unix installation while you're in Windows (Core 2 Quad is more than enough, although an i-7 will get you almost native speeds).

I'm using Linux Mint inside Virtual Box and it runs flawlessly. No need to worry about dual booting. Although I've used Wubi in the past, I think it might cause problems with newer systems and secure boot. Other than that, it's pretty safe to use, just like any Windows program. Just make sure to stay away from partitioning tools and things such as Grub while under Unix.

I'll give VirtualBox a try. I've been using Hyper-V as it ships with Win8 Pro but it lacks USB support. I'm running an i7 so it sounds like VB should run great.

Quote
While I haven't tried it, just out of interest: Do you even have to go through the registry to get the name under Windows? The JOYCAPS structure already got a name field. Although I'm not sure how accurate this is or if it's still populated.

Unfortunately you do. I don't remember the exact value JOYCAPS gives but it's something like "USB Joystick" for every device I tried.

Quote
Also not sure about the UNICODE macro magic, since all versions of Windows being supported got the full wide char set implemented (so just use that).

I can switch it but it looked to me like SFML is setting a similar macro via CMake to force Windows to Unicode mode so I was trying to go with the flow there and no require Unicode functions.

Quote
Plus I think it shouldn't return "Unknown Joystick" if a device isn't present/connected at all.

It should only return "Unknown Joystick" if the joystick is connected but we fail to read the name value for some reason. My thought here is that we should return some known value and allow the joystick to function even if we can't suss out the name. Maybe there's a better way to handle this case?

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #6 on: January 13, 2014, 06:28:38 pm »
Quote
Try the Ubuntu windows installer.  You can dual boot without having to change partitions.  And you can even uninstall it if you don't like it.

http://www.ubuntu.com/download/desktop/install-ubuntu-with-windows

That looks awesome! I think I'm going to try VirtualBox first, it being the path of least resistance and all but I do want to get a non-virtualized version of Linux up and running at some point.

Any experience using this with Windows 8 (Win8 seems to frustrate dual-boot setups)?

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #7 on: January 15, 2014, 01:04:21 am »
To answer the question: I also use a virtual machine (VirtualBox) and Ubuntu. The host machine is a win 8. And I didn't run into any problems yet.
@Mario: Parsing the registry seems to be the only option. Laurent said that here.
I also agree that "Unknown Joystick" might be a bit confusing, but that again one should check beforehand with sf::Joystick::isConnected if the Joystick is even connected.
« Last Edit: January 15, 2014, 01:15:28 am by Foaly »

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #8 on: January 16, 2014, 07:35:25 am »
To answer the question: I also use a virtual machine (VirtualBox) and Ubuntu. The host machine is a win 8. And I didn't run into any problems yet.

Lucky you ;) I installed VB and it promptly disabled my ethernet adapter so no internet. "Okay", I thought, I'll just restart. That should fix it! Then Win8 sat at the boot screen for 30 minutes. So I cut the power by holding down the power button...which can apparently cause issue with my SSD such that the system cannot recognize it until you power cycle the SSD which takes an hour. Anyway, there was lots of swearing and I ended up getting myself a nice beer but I did eventually get it to work!

I've made some comments on Github but I'll recap here. On Ubuntu 13.10:

I'm able to get the joystick name no problem ("Microsoft X-Box 360 pad" in this case).
I'm not able to get the vendor or product IDs. It's probably something simple but I'm not seeing it.

Quote
I also agree that "Unknown Joystick" might be a bit confusing, but that again one should check beforehand with sf::Joystick::isConnected if the Joystick is even connected.

So there's two ways this gets set:

1. It's the default value for a new JoystickInfo struct.
2. A joystick gets connected, SFML tries to read the value but errors out for some reason. In this case SFML sets the name to "Unknown Joystick".

After having debugged an issue on Linux that was not obvious because JoystickInfo.name defaulted to "Unknown Joystick" I'm in 100% agreement that this is confusing (was about 96% before ;) ). In the second case I think SFML should set some known, default value that can be interpreted as "I tried and failed".

I've changed the first case to an empty string ("") and left the latter alone.

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #9 on: January 16, 2014, 07:42:52 am »
Also not sure about the UNICODE macro magic, since all versions of Windows being supported got the full wide char set implemented (so just use that).

So I tried removing the _UNICODE macro and explicitly using all the wide char set versions of the functions for reading the registry (e.g., RegQueryValueExW instead of RegQueryValueEx). These work fine except that the registry key REGSTR_VAL_JOYOEMNAME is not wchar_t but rather char_t so I get an error.

Maybe the problem is that I'm using Mingw? It looks to me like Cmake is setting a UNICODE macro when building SFML on Windows but the Mingw headers are using a _UNICODE macro. Does that sound plausible? If that's the case what's the best way to go about handling this situation?

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #10 on: January 17, 2014, 12:55:15 am »
Uh that sucks... I've had a small problem when I updated VirtualBox, but it was a quick fix. Well at least it's working now!
I might be able to get a hold of a joystick, so hopefully I will be able do some testing soon.

About the default value. In my opinion the most self explaining option would be to have the default value of JoystickInfo.name set to "No Joystick". If a new joystick gets connected SFML tries to retrieve the joysticks name and save it. If it fails the name should get set to "Unknown Joystick". And if the joystick gets disconnected the name should be set back to "No Joystick". An empty string might get misinterpreted as no result or something is not working.

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #11 on: January 17, 2014, 02:59:06 am »
Your JoystickInfo.name settings sound good to me. I'll make the change.

It'd be great if you could get a joystick for testing.

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #12 on: January 19, 2014, 11:54:15 pm »
I was able to get a hold of a joystick. Now i just need to find some time :D I will try to do some testing this week.

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #13 on: January 20, 2014, 06:48:23 pm »
I was able to get a hold of a joystick. Now i just need to find some time :D I will try to do some testing this week.

Woohoo! I haven't looked in a few days, but I'm stumped on getting the vendor and product IDs so any thoughts you have there are welcome.

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Exposed Joystick Name, Product ID and Manufacturer ID
« Reply #14 on: January 21, 2014, 12:23:33 am »
I didn't have time to test it, but like suggested on your github tracker I think you have to declare inpid like this:
struct input_id inpid;
Your reference page is a bit unclear in that point, but I think that's what they mean with:
Quote
The argument is a pointer to an input_id structure
and that's how SDL does it. And it would fit to the error you are getting about the arguments begin invalid. Like I said, I couldn't test it though.

edit: also I would rename it to inputID. SFMLs variable names are usually not abriviated and in camelCase.
« Last Edit: January 21, 2014, 12:27:10 am by Foaly »

 

anything