My guess is that it has to do with the update-rates of the joysticks, but I have found no information concerning this or how to retrieve this.
Has anybody a clue for this?
The code (a bit simplyfied):
JOYINFOEX structtmp;
for (int i = JOYSTICKID1; i < (JOYSTICKID1 +16); i++)
{
if (joyGetPosEx(i, &structtmp) == JOYERR_NOERROR) {
JOYINFOEX actualPos;
actualPos.dwSize = sizeof(JOYINFOEX);
actualPos.dwFlags = JOY_RETURNALL;
Sleep(500); //if no sleep -> data is crap after startup, why??
//get button states
if (joyGetPosEx(i, &actualPos) != JOYERR_NOERROR) {
std::cout << "Error reading joystick " << i << std::endl;
continue;;
}
DWORD jb = actualPos.dwButtons;
int button[32];
//get button bit of the 32 buttons
for (unsigned int i = 0; i < 32; i++) {
button[i] = (DWORD)powf(2.0f, i);
if (jb & button[i]) button[i]=1; else button[i]=0;
}
int type = button[31] + button[30] * 2 + button[29] * 4 + button[28] * 8 + button[27] * 16 + button[26] * 32 + button[25] * 64 + button[24] * 128;
std::cout << "Got Joystick: " << i << " of type " << type << std::endl;
}
}
The first call to joyGetPosEx returns garbage for the buttons as well.







