Buffered joystick input always empty

Started by
0 comments, last by joe_bubamara 15 years, 11 months ago
I am trying to change my input from immidiate to buffered. I have setuped everything according to docs, but number of read items is always 0. In my init joystick routine I have this code to set buffer size:

    // Set BUFFERSIZE.
    DIPROPDWORD dipbs;

    dipbs.diph.dwSize       = sizeof( dipdw ); 
    dipbs.diph.dwHeaderSize = sizeof( dipdw.diph ); 
    dipbs.diph.dwObj        = 0;
    dipbs.diph.dwHow        = DIPH_DEVICE;
    dipbs.dwData            = BUFFERSIZE; // Arbitary buffer size
    joystick->SetProperty( DIPROP_BUFFERSIZE, &dipbs.diph );
and then when I read input I have this code:
void buffered_joystick()
{
	int status;
	DWORD buffsize = BUFFERSIZE;
	DIDEVICEOBJECTDATA buffer[BUFFERSIZE];

	for(int i=0; i < num_joysticks; i++){
		pads->Poll();
		status = pads->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), buffer, &buffsize,0);
		if(status == DI_BUFFEROVERFLOW)
			puts("overflow");
		if(status == DI_OK){
			puts("read ok");
			if(buffsize != 0)
				printf("number of items: %l\n",buffsize);
			for(int j = 0; j < buffsize; j++){
				// do something here ....
			}
		}
}
(this is just very simplified version to illustrate my problem). Now I do get DI_OK status all the time, but buffsize is always set to 0, which means 0 events are read. I have no problems when reading with GetDeviceState. What can be problem with buffered read?
Advertisement
shiiiiit,

so lame misstake, buffer size variable has to be reset per device in for-loop :-)

DWORD buffsize = BUFFERSIZE; <-- had to be in for loop before call to GetDeviceData; I can't believe I was so blind ...

It works awesome, and it solves problem of multiple keypresses, if you remember my previous post about polling gamepad :-).

This topic is closed to new replies.

Advertisement