From 086fc2d81a68fe70c5897fbe6a1db0e1ba6df4cd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 6 Apr 2017 04:44:48 +0200 Subject: tracker/steamvr: determine device uniqueness harder Use "type-model-serial" as the discriminator. The API might present a single device with two types as the same model and serial or something similarly stupid. --- tracker-steamvr/steamvr.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'tracker-steamvr/steamvr.cpp') diff --git a/tracker-steamvr/steamvr.cpp b/tracker-steamvr/steamvr.cpp index 901c4241..2552be56 100644 --- a/tracker-steamvr/steamvr.cpp +++ b/tracker-steamvr/steamvr.cpp @@ -181,7 +181,7 @@ void steamvr::start_tracker(QFrame*) if (!v) { QMessageBox::warning(nullptr, - tr("Valve SteamVR init error"), device_list::strerror(e), + tr("SteamVR init error"), device_list::strerror(e), QMessageBox::Close, QMessageBox::NoButton); return; } @@ -194,20 +194,30 @@ void steamvr::start_tracker(QFrame*) if (sz == 0) { QMessageBox::warning(nullptr, - tr("Valve SteamVR init error"), + tr("SteamVR init error"), tr("No HMD connected"), QMessageBox::Close, QMessageBox::NoButton); return; } + device_index = -1; + for (const device_spec& spec : specs) { - if (serial == "" || serial == spec.serial) + if (serial == "" || serial == spec.to_string()) { device_index = int(spec.k); break; } } + + if (device_index == -1) + { + QMessageBox::warning(nullptr, + tr("SteamVR init error"), + tr("Can't find device with that serial"), + QMessageBox::Close, QMessageBox::NoButton); + } }); } @@ -267,8 +277,7 @@ steamvr_dialog::steamvr_dialog() device_list list; for (const device_spec& spec : list.devices()) - ui.device->addItem(QStringLiteral("<%3> %1 [%2]").arg(spec.model).arg(spec.serial).arg(spec.type), - QVariant(spec.serial)); + ui.device->addItem(spec.to_string(), spec.to_string()); tie_setting(s.device_serial, ui.device); } @@ -284,4 +293,11 @@ void steamvr_dialog::doCancel() close(); } + + +QString device_spec::to_string() const +{ + return QStringLiteral("<%1> %2 [%3]").arg(type).arg(model).arg(serial); +} + OPENTRACK_DECLARE_TRACKER(steamvr, steamvr_dialog, steamvr_metadata) -- cgit v1.2.3