From: Soeren Apel Date: Sat, 6 Feb 2016 17:07:05 +0000 (+0100) Subject: MainWindow: Try to use any available device aside from demo X-Git-Tag: pulseview-0.4.0~343 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b926e4eeef6db657601ebd4bbededdf9d329cdd6;p=pulseview.git 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. --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 912ed607..65071330 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -567,8 +567,9 @@ void MainWindow::select_init_device() QSettings settings; map dev_info; list key_list; + shared_ptr 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 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 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();