I'm trying to add some basic controller support for WedNESday. The only problem is I'm very confused about the SetProperty function and what it does and why it is needed. I am using my PS3's Dualshock 3 controller (which I know works because Project64 picks it up just fine). The only thing I want to do is to be able to read back which buttons have been pressed, not anything fancy like the motion sensors.
Here is what I have done;
Code:
DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &lpDI, NULL);
lpDI->EnumDevices(0, DIEnumKbdProc, &pvRef, DIEDFL_ALLDEVICES);
lpDI->CreateDevice(PS3GUID, &lpDIDevice, NULL);
lpDIDevice->SetDataFormat(&c_dfDIJoystick);
lpDIDevice->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
int BufferSize = 1000;
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_BYID ;
dipdw.dwData = BufferSize;
lpDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);
lpDIDevice->Acquire();
lpDIDevice->GetDeviceState(sizeof(Buttons), &Buttons);
But whenever I make that call to GetDeviceState I always get DIERR_INVALIDPARAMS in return. What am I doing wrong?
Two things:
1) Your code isn't doing error checking on each of the calls, so there's no guarantee that GetDeviceState() is the responsible for the error. Consider using the FAILED() function/macro, or handle the results yourself using a variable declared as type HRESULT.
All of those functions you're using return an HRESULT, which you're not checking for. :-)
2) Try changing DISCL_FOREGROUND to DISCL_BACKGROUND (I doubt this is the problem, but I did read about one individual who got back DIERR_INVALIDPARAMS as a result of such).
I think #1 will disclose the root of the problem.
In other words, "Help, I'm making a recipe blindfolded. I put all the ingredients in, mix them up, put them in the oven, but all I get is a mess. Am I setting the oven temperature wrong?"
blargg wrote:
In other words, "Help, I'm making a recipe blindfolded. I put all the ingredients in, mix them up, put them in the oven, but all I get is a mess. Am I setting the oven temperature wrong?"
I understand your feeling but I feel this comment is a little bit harsh since the original message was posted in the newbie help center forum which imply the poster may not know well about this technology and asked for help.
But that's my personal perception of your comment. Not meant to start a war or something. We are all newbies once in a while when we start to tackle some new technologies and we should not forget about this.
A blindfold is a good illustration of the handicap that ignoring error return values imposes.
blargg wrote:
A blindfold is a good illustration of the handicap that ignoring error return values imposes.
Oh.. I didn't get it that way. Maybe it's because I'm not english native and didn't catch the meaning. Sorry if I was rude myself with my comment
LMFAO
The code you see above has had all of the error checking
removed from it, as not to fill the post up too much...
GetDeviceState is what returns DIERR_INVALIDPARAMS. Changing DISCL_FOREGROUND to DISCL_BACKGROUND had no effect.
...and yes, blargg you were a little harsh.
Edit: Yes, its just GetDeviceState that is going wrong. But I am not too sure about the point of GetProperty.
no, blargg was not too harsh ( kinda funny). always be specific. i know i am not the best at posting. i got it last week :P
if your removed the error checking, you changed the code.
small stuff like this may or may not be a good idea. there is a thread on the sdl list about and empty main() crashing... how can no code crash? problem seems to be in the header file. point: never assume.
Is anybody actually gonna answer my original post or what.
WedNESday wrote:
Is anybody actually gonna answer my original post or what.
What is "Buttons" ? I assume its a DIJOYSTATE ...
right?
[Edit:
you might find some useful scraps of info in this article.]
Thank you mozz, finally a half-decent answer. Ok so now I know that GetDeviceState works, and that everywhere I read mentions SetProperty, but this is the only thing that I have not yet implemented, because it makes no sense to me. Whenever I use GetDeviceState the buttons always read back as 0's, and I'm getting no more error messages, even when I do call SetProperty.
Edit: Now SetProperty tells me that data cannot be buffered from the device until it is polled using IDirectInputDevice2::Poll.
Not that anybody cares anymore...
It now says that I must Poll the device before I can use SetProperty. However, in order to do that I must acquire the device which I do, but SetProperty will no work when the device is currently acquired. So I unacquire the device and just get a 'Device not polled message'.
Fixed it now. Dropped SetProperty altogether and called Poll before every call to GetDeviceState. I had to get a pointer to another DirectInput interface before I could do that though. Never mind because I know for a fact that nobodyisevergonnareadthispostanyway...
Btw my credit card number is 2455 3252 7899 4655, expiry 12/11...
I shot JFK >>AND<< JR...
I am also the Lindberg baby...
*orders Domino's with WedNESday's credit card number*
Congrats on getting it figured out : D
WedNESday wrote:
Never mind because I know for a fact that nobodyisevergonnareadthispostanyway...
I read all the post everyday even if I'm not interested in the subject in it.
Can I order a powerpak with your credit card?
Thanks Banshaku. Gentlemen, spend like its 1999!!!!!!!!!!!!!!!!!
I too read everything here, even if it isn't useful for me... This message board is fantastic, its professionnalism amaze me and I'm astonished of teh global high knowledge of the people here, like tepples, blargg, newrisingsun, kevtris and so many others... So everything I read here, even if itsn't useful for me, will likely learn me something.