diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-08-30 06:26:03 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-08-30 06:26:03 +0200 |
commit | 6c5c26e914c2f515f1ca678fa32ab78750b8a4b5 (patch) | |
tree | f2b3728b78381607a7ba61baa40c9626a849791d /ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp | |
parent | 5090466908ddf92b7566f4215985c2e7d7dc93d7 (diff) |
win32-joystick: allow for unique selection of joysticks
Distinguish joystick GUIDs to allow selecting one of several with the
same name.
Issue: #230
Diffstat (limited to 'ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp')
-rw-r--r-- | ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp index 45cf2f10..ac374aa8 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp @@ -82,6 +82,17 @@ static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance if (stop) { + if (self->guid_to_check.size()) + { + QString guid = guid_to_string(pdidInstance->guidInstance); + if (guid != self->guid_to_check) + { + return DIENUM_CONTINUE; + } + else + qDebug() << "guid ok" << self->guid_to_check; + } + (void) self->g_pDI->CreateDevice( pdidInstance->guidInstance, &self->g_pJoystick, NULL); qDebug() << "device" << static_cast<QString>(self->s.joyid); } @@ -103,13 +114,32 @@ void FTNoIR_Tracker::start_tracker(QFrame* frame) goto fail; } + guid_to_check = s.guid; + if( FAILED( hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, this, DIEDFL_ATTACHEDONLY))) { - qDebug() << "enum2"; - goto fail; + if (guid_to_check.isEmpty()) + { + qDebug() << "enum1"; + goto fail; + } + } + + if (!g_pJoystick && guid_to_check.size()) + { + guid_to_check = ""; + + if( FAILED( hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, + EnumJoysticksCallback, + this, + DIEDFL_ATTACHEDONLY))) + { + qDebug() << "enum2"; + goto fail; + } } if (!g_pJoystick) |