]> sigrok.org Git - pulseview.git/commitdiff
MainWindow: Try to use any available device aside from demo
authorSoeren Apel <redacted>
Sat, 6 Feb 2016 17:07:05 +0000 (18:07 +0100)
committerUwe Hermann <redacted>
Thu, 11 Feb 2016 14:08:08 +0000 (15:08 +0100)
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

index 912ed607f200bc431e9772c2514b8d186dd3917b..65071330da07e1d24c5955448ad44efe3f929383 100644 (file)
@@ -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();