• Create Account

### #Actualdoeme

Posted 13 October 2012 - 06:00 AM

Thank you all for the help and the hints. We've ruled bad soldering-connections almost out, by creating a few more devices of the same type and the all behave the exact same. On the average we're now down to waiting 20ms per joystick (even with multiple connected joysticks) until we get useful signals, by modifiying the code in a way that it only waits until we get something other than 0.

Further modifications by enumerating all joysticks first and then querying them in a separate loop yielded even better results with no need to sleep at all. (modified code below). So our guess is now that the microcontroller has a few ms to get ready to deliver the signals over usb. We will check this next week more in depth, but for now the solution is satisfying for our needs, even without being 100% sure of the cause. Again, thanks for all the help and input from you guys.

JOYINFOEX structtmp;
structtmp.dwSize = sizeof(JOYINFOEX);
structtmp.dwFlags = JOY_RETURNALL;
std::vector<int> connectedJoysticks;
// first enumerate all joysticks
for (int i = JOYSTICKID1; i < (JOYSTICKID1 +16); i++)
{
if (joyGetPosEx(i, &structtmp) == JOYERR_NOERROR) {
connectedJoysticks.push_back(i);
}
}
// then read the buttons only for the connected ones
for(unsigned int i = 0; i < connectedJoysticks.size(); i++)
{
JOYINFOEX actualPos;
actualPos.dwSize = sizeof(JOYINFOEX);
actualPos.dwFlags = JOY_RETURNALL;
int type = 0;
while(type == 0)
{
//get button states
if (joyGetPosEx(connectedJoysticks[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;
}
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;
}



### #1doeme

Posted 12 October 2012 - 03:19 AM

Thank you all for the help and the hints. We've ruled bad soldering-connections almost out, by creating a few more devices of the same type and the all behave the exact same. On the average we're now down to waiting 20ms per joystick (even with multiple connected joysticks) until we get useful signals, by using the modifiying the code in a way that it only waits until we get something other than 0.

Further modifications by enumerating all joysticks first and then querying them in a separate loop yielded even better results with no need to sleep at all. (modified code below). So our guess is now that the microcontroller has a few ms to get ready to deliver the signals over usb. We will check this next week more in depth, but for now the solution is satisfying for our needs, even without being 100% sure of the cause. Again, thanks for all the help and input from you guys.

JOYINFOEX structtmp;
structtmp.dwSize = sizeof(JOYINFOEX);
structtmp.dwFlags = JOY_RETURNALL;
std::vector<int> connectedJoysticks;
// first enumerate all joysticks
for (int i = JOYSTICKID1; i < (JOYSTICKID1 +16); i++)
{
if (joyGetPosEx(i, &structtmp) == JOYERR_NOERROR) {
connectedJoysticks.push_back(i);
}
}
// then read the buttons only for the connected ones
for(unsigned int i = 0; i < connectedJoysticks.size(); i++)
{
JOYINFOEX actualPos;
actualPos.dwSize = sizeof(JOYINFOEX);
actualPos.dwFlags = JOY_RETURNALL;
int type = 0;
while(type == 0)
{
//get button states
if (joyGetPosEx(connectedJoysticks[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;
}
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;
}



PARTNERS