summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-08-30 06:26:03 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-08-30 06:26:03 +0200
commit6c5c26e914c2f515f1ca678fa32ab78750b8a4b5 (patch)
treef2b3728b78381607a7ba61baa40c9626a849791d
parent5090466908ddf92b7566f4215985c2e7d7dc93d7 (diff)
win32-joystick: allow for unique selection of joysticks
Distinguish joystick GUIDs to allow selecting one of several with the same name. Issue: #230
-rw-r--r--ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp34
-rw-r--r--ftnoir_tracker_joystick/ftnoir_tracker_joystick.h16
-rw-r--r--ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp4
3 files changed, 50 insertions, 4 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)
diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h
index 0958246a..ab32ec56 100644
--- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h
+++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h
@@ -30,11 +30,12 @@
using namespace options;
struct settings : opts {
- value<QString> joyid;
+ value<QString> joyid, guid;
value<int> joy_1, joy_2, joy_3, joy_4, joy_5, joy_6;
settings() :
opts("tracker-joystick"),
joyid(b, "joy-id", ""),
+ guid(b, "joy-guid", ""),
joy_1(b, "axis-map-1", 1),
joy_2(b, "axis-map-2", 2),
joy_3(b, "axis-map-3", 3),
@@ -44,6 +45,18 @@ struct settings : opts {
{}
};
+template<typename = void>
+QString guid_to_string(const GUID guid)
+{
+ char buf[40] = {0};
+ wchar_t szGuidW[40] = {0};
+
+ StringFromGUID2(guid, szGuidW, 40);
+ WideCharToMultiByte(0, 0, szGuidW, -1, buf, 40, NULL, NULL);
+
+ return QString(buf);
+}
+
class FTNoIR_Tracker : public ITracker
{
public:
@@ -59,6 +72,7 @@ public:
DIDEVICEINSTANCE def;
int iter; // XXX bad style
settings s;
+ QString guid_to_check;
static constexpr int AXIS_MAX = 65535;
};
diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp
index 7200003c..88074fef 100644
--- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp
+++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp
@@ -6,7 +6,8 @@ static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance
auto self = ( TrackerControls* )pContext;
self->guids.push_back(pdidInstance->guidInstance);
- self->ui.joylist->addItem(QString(pdidInstance->tszInstanceName));
+ self->ui.joylist->addItem(QString(pdidInstance->tszInstanceName),
+ guid_to_string(pdidInstance->guidInstance));
return DIENUM_CONTINUE;
}
@@ -49,6 +50,7 @@ fin:
}
void TrackerControls::doOK() {
+ s.guid = ui.joylist->currentData().toString();
s.b->save();
if (tracker)
tracker->reload();