pulseview/0010-MainWindow-Try-to-use-...

61 lines
2.0 KiB
Diff

From b926e4eeef6db657601ebd4bbededdf9d329cdd6 Mon Sep 17 00:00:00 2001
From: Soeren Apel <soeren@apelpie.net>
Date: Sat, 6 Feb 2016 18:07:05 +0100
Subject: [PATCH 10/13] MainWindow: Try to use any available device aside from
demo
Currently, PV will only try to use the previously used device.
However, when first running PV, it will default to demo as
there is no previously used device. In this case, we still
want to use whatever device we can get our hands on so that
the user can start using PV immediately.
---
pv/mainwindow.cpp | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp
index 912ed60..6507133 100644
--- a/pv/mainwindow.cpp
+++ b/pv/mainwindow.cpp
@@ -567,8 +567,9 @@ void MainWindow::select_init_device()
QSettings settings;
map<string, string> dev_info;
list<string> key_list;
+ shared_ptr<devices::HardwareDevice> device;
- // Re-select last used device if possible.
+ // Re-select last used device if possible but only if it's not demo
settings.beginGroup("Device");
key_list.push_back("vendor");
key_list.push_back("model");
@@ -586,8 +587,24 @@ void MainWindow::select_init_device()
dev_info.insert(std::make_pair(key, value));
}
- const shared_ptr<devices::HardwareDevice> device =
- device_manager_.find_device_from_info(dev_info);
+ if (dev_info.count("model") > 0)
+ if (dev_info.at("model").find("Demo device") == std::string::npos)
+ device = device_manager_.find_device_from_info(dev_info);
+
+ // When we can't find a device similar to the one we used last
+ // time and there is at least one device aside from demo, use it
+ if (!device) {
+ for (shared_ptr<devices::HardwareDevice> dev : device_manager_.devices()) {
+ dev_info = device_manager_.get_device_info(dev);
+
+ if (dev_info.count("model") > 0)
+ if (dev_info.at("model").find("Demo device") == std::string::npos) {
+ device = dev;
+ break;
+ }
+ }
+ }
+
select_device(device);
update_device_list();
--
2.4.3