Sign in to follow this  
code_swimmer

DirectInput

Recommended Posts

code_swimmer    122
Hello everyone! This is my first post so please inform me if I do not adhere to the forum etiquette. I am writing a class to read generic usb gamepads/joysticks mainly as a wrapper to xna but I am trying to make it general purpose. I am using BufferedInput to make my class event base, but I am also adding a custom poll function to retrieve immediate values. First, I wanted to get all available axes/buttons/pov etc. So I enumerate through the device objects and add them to a list along with it's name (Button 1, Axis X, etc). This works great, and when I read the BufferedInput I can cross reference everything against my list to see which input was changed. However, my last 4 buttons are not in the Objects collection of the device, yet they are in the BufferedInput. Does anyone have experience using BufferedInput or know of a better way to accomplish this? I apologize for the long post, but I have been all over the internet trying to see if this has occurred to anyone else.

Share this post


Link to post
Share on other sites
code_swimmer    122
Maybe some code would help:


foreach (DeviceObjectInstance doi in m_device.Objects)
{
if (!GamePadObjects.ContainsKey(doi.Offset)) GamePadObjects.Add(doi.Offset, doi.Name);
}


And the code to read the BufferedInput:

BufferedDataCollection bdc;
bdc = m_device.GetBufferedData();
if (bdc != null)
{
foreach (BufferedData bd in bdc)
{
if (Objects.ContainsKey(bd.Offset))
{
Console.WriteLine(Objects[bd.Offset] + " = " + bd.Data);
}
else
{
Console.WriteLine("Unknown Input Object: " + bd.Offset);
}
}
}


If the BufferedData (bd) object's offset is in the list then everything is fine, I am getting correct results (ie Button 1, Button 2, etc). My test controller has four more buttons that are registering in the BufferedInput but not in the m_device.Objects collection. I can read the buttons using a traditional Poll and reading the JoystickState but this does not tell me what axes are being used and such, only how many it has. Please help!!!

Share this post


Link to post
Share on other sites
code_swimmer    122
Well I did consider using the raw usb hid library but that is way beyond my expertise, and it seems like an overly complicated method for achieving my goal, when I plan on using the XNA framework for the rest of my engine.

Share this post


Link to post
Share on other sites
MJP    19788
Quote:
Original post by lonewolff
Waiting for the compulsory abuse from Evil Steve regarding the use of DirectInput....


Nah he'd only do that if he were using DirectInput for keyboard and mouse input, which isn't the case here. :P

Share this post


Link to post
Share on other sites
code_swimmer    122
Quote:
Original post by MJP
Perhaps you should have a look at this?


Thank you, I will definitely look at the source for that. It's not the approach I really wanted to take, but seems to be the most efficient.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this