From 7f61dfd155fabf760fc3a953c9bc7b56ba034029 Mon Sep 17 00:00:00 2001 From: Pilatomic Date: Sun, 5 Feb 2023 17:40:56 +0100 Subject: [PATCH 1/4] Add device type filter to ConnectDialog. Only the devices matching the type selected are then listed. The default "Any device type" shows all devices just as before. --- src/ui/dialogs/connectdialog.cpp | 63 +++++++++++++++++++++++++++++--- src/ui/dialogs/connectdialog.hpp | 6 ++- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/ui/dialogs/connectdialog.cpp b/src/ui/dialogs/connectdialog.cpp index 94fdd25a..636f4931 100644 --- a/src/ui/dialogs/connectdialog.cpp +++ b/src/ui/dialogs/connectdialog.cpp @@ -50,6 +50,8 @@ using sigrok::Driver; using sv::devices::HardwareDevice; +Q_DECLARE_METATYPE(const sigrok::ConfigKey *) + namespace sv { namespace ui { namespace dialogs { @@ -61,6 +63,7 @@ ConnectDialog::ConnectDialog(sv::DeviceManager &device_manager, layout_(this), form_(this), form_layout_(&form_), + filters_(&form_), drivers_(&form_), scan_button_(tr("&Scan for devices using driver above"), this), device_list_(this), @@ -79,6 +82,10 @@ ConnectDialog::ConnectDialog(sv::DeviceManager &device_manager, connect(this, &ConnectDialog::populate_serials_done, this, &ConnectDialog::populate_serials_finish); + populate_filters(); + connect(&filters_, QOverload::of(&QComboBox::activated), + this, &ConnectDialog::filter_selected); + populate_drivers(); connect(&drivers_, QOverload::of(&QComboBox::activated), this, &ConnectDialog::driver_selected); @@ -86,6 +93,7 @@ ConnectDialog::ConnectDialog(sv::DeviceManager &device_manager, form_.setLayout(&form_layout_); QVBoxLayout *vbox_drv = new QVBoxLayout; + vbox_drv->addWidget(&filters_); vbox_drv->addWidget(&drivers_); QGroupBox *groupbox_drv = new QGroupBox(tr("Step 1: Choose the driver")); groupbox_drv->setLayout(vbox_drv); @@ -213,17 +221,50 @@ shared_ptr ConnectDialog::get_selected_device() const return item->data(Qt::UserRole).value>(); } -void ConnectDialog::populate_drivers() +void ConnectDialog::populate_drivers(std::set key_filters) { + drivers_.clear(); + for (const auto &entry : device_manager_.context()->drivers()) { auto name = entry.first; auto sr_driver = entry.second; - if (sv::devices::deviceutil::is_supported_driver(sr_driver)) { - drivers_.addItem(QString("%1 (%2)").arg( - sr_driver->long_name().c_str(), name.c_str()), - QVariant::fromValue(sr_driver)); + // No filter -> accept any device + bool device_match_filter = false; + if (key_filters.empty()) + device_match_filter = true; + + // Filters -> accept device that match any filter + else { + for (auto &filter_entry : key_filters) { + if (sr_driver->config_keys().count(filter_entry) > 0) { + device_match_filter = true; + break; + } + } } + + if (sv::devices::deviceutil::is_supported_driver(sr_driver) && + device_match_filter) + drivers_.addItem(QString("%1 (%2)").arg(sr_driver->long_name().c_str(), name.c_str()), + QVariant::fromValue(sr_driver)); + } +} + +void ConnectDialog::populate_filters() +{ + // Create a map so we get items ordered by name + std::map nameToDataMap; + for (const auto &type : sv::devices::deviceutil::device_type_sr_config_key_map) { + QString type_string = sv::devices::deviceutil::format_device_type(type.first); + QVariant data = QVariant::fromValue(type.second); + nameToDataMap[type_string] = data; + } + + // Each known device type is populated as an entry + filters_.addItem("Any device type"); + for (const auto &item : nameToDataMap) { + filters_.addItem(item.first, item.second); } } @@ -378,6 +419,18 @@ void ConnectDialog::scan_pressed() button_box_.button(QDialogButtonBox::Ok)->setDisabled(device_list_.count() == 0); } +void ConnectDialog::filter_selected(int index) +{ + std::set filters_set; + + if (filters_.itemData(index).isValid()) { + QVariant data = filters_.itemData(index); + filters_set.insert(data.value()); + } + + populate_drivers(filters_set); +} + void ConnectDialog::driver_selected(int index) { shared_ptr driver = diff --git a/src/ui/dialogs/connectdialog.hpp b/src/ui/dialogs/connectdialog.hpp index 6304ee0b..0ece27ab 100644 --- a/src/ui/dialogs/connectdialog.hpp +++ b/src/ui/dialogs/connectdialog.hpp @@ -74,13 +74,16 @@ class ConnectDialog : public QDialog shared_ptr get_selected_device() const; private: - void populate_drivers(); + void populate_drivers(std::set filters_set = + std::set()); + void populate_filters(); void populate_serials_start(shared_ptr driver); void populate_serials_thread_proc(shared_ptr driver); void check_available_libs(); void unset_connection(); private Q_SLOTS: + void filter_selected(int index); void driver_selected(int index); void serial_toggled(bool checked); void tcp_toggled(bool checked); @@ -99,6 +102,7 @@ private Q_SLOTS: QWidget form_; QFormLayout form_layout_; + QComboBox filters_; QComboBox drivers_; QRadioButton *radiobtn_usb_; From f4d3914269a483448eaeb901845abe0e1e5b8549 Mon Sep 17 00:00:00 2001 From: Pilatomic Date: Thu, 16 Feb 2023 18:58:08 +0100 Subject: [PATCH 2/4] Power Panel : add device(s) to title --- src/ui/views/powerpanelview.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ui/views/powerpanelview.cpp b/src/ui/views/powerpanelview.cpp index ee8a0088..68f65748 100644 --- a/src/ui/views/powerpanelview.cpp +++ b/src/ui/views/powerpanelview.cpp @@ -85,10 +85,23 @@ PowerPanelView::~PowerPanelView() QString PowerPanelView::title() const { - QString title = tr("Power Panel"); - if (voltage_signal_ && current_signal_) - title = title.append(" ").append(voltage_signal_->display_name()). - append(" / ").append(current_signal_->display_name()); + QString title = tr("Power Panel : "); + if (voltage_signal_ && current_signal_) { + auto voltage_device = voltage_signal_->parent_channel()->parent_device(); + auto current_device = current_signal_->parent_channel()->parent_device(); + + if (voltage_device == current_device) + title = title.append("%1 %2 / %3") + .arg(voltage_device->display_name(session_.device_manager())) + .arg(voltage_signal_->display_name()) + .arg(current_signal_->display_name()); + else + title = title.append("%1 %2 / %3 %4") + .arg(voltage_device->display_name(session_.device_manager())) + .arg(voltage_signal_->display_name()) + .arg(current_device->display_name(session_.device_manager())) + .arg(current_signal_->display_name()); + } return title; } From 8469f5988ae923564f8ec5e8174cba2877e4ba13 Mon Sep 17 00:00:00 2001 From: Pilatomic Date: Thu, 16 Feb 2023 20:58:02 +0100 Subject: [PATCH 3/4] Fixed sawtooth generator period being wrong --- src/ui/dialogs/generatewaveformdialog.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ui/dialogs/generatewaveformdialog.cpp b/src/ui/dialogs/generatewaveformdialog.cpp index e9b6e548..24dbe7c5 100644 --- a/src/ui/dialogs/generatewaveformdialog.cpp +++ b/src/ui/dialogs/generatewaveformdialog.cpp @@ -299,10 +299,9 @@ void GenerateWaveformDialog::accept() else if (w_type == WaveformType::Triangle) value = (std::asin(std::sin(x))) / (pi/2); else if (w_type == WaveformType::Sawtooth) - // y = −arctan(cotan(x)) - value = -1 * std::atan(1 / std::tan(x)) / (pi/2); + value = std::fmod(x / pi, 2.0) - 1.0; else if (w_type == WaveformType::SawtoothInv) - value = std::atan(1 / std::tan(x)) / (pi/2); + value = -std::fmod(x / pi, 2.0) + 1.0; else value = 0; From c10d16baebcfa29103449667134be907a1e6528a Mon Sep 17 00:00:00 2001 From: Pilatomic Date: Fri, 17 Feb 2023 00:18:05 +0100 Subject: [PATCH 4/4] Added missing ElectricCharge Quantity --- src/data/datautil.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/data/datautil.hpp b/src/data/datautil.hpp index f6537549..6a713734 100644 --- a/src/data/datautil.hpp +++ b/src/data/datautil.hpp @@ -425,6 +425,7 @@ map sr_quantity_quantity_map = { { sigrok::Quantity::MASS, Quantity::Mass }, { sigrok::Quantity::HARMONIC_RATIO, Quantity::HarmonicRatio }, { sigrok::Quantity::ENERGY, Quantity::Energy }, + { sigrok::Quantity::ELECTRIC_CHARGE, Quantity::ElectricCharge }, }; map quantity_sr_quantity_map = { @@ -462,6 +463,8 @@ map quantity_sr_quantity_map = { { Quantity::Mass, sigrok::Quantity::MASS }, { Quantity::HarmonicRatio, sigrok::Quantity::HARMONIC_RATIO }, { Quantity::Energy, sigrok::Quantity::ENERGY }, + { Quantity::ElectricCharge, sigrok::Quantity::ELECTRIC_CHARGE }, + }; map sr_quantity_flag_quantity_flag_map = {