Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several small bug fixes / quality of life improvement #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/data/datautil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ map<const sigrok::Quantity *, Quantity> 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, const sigrok::Quantity *> quantity_sr_quantity_map = {
Expand Down Expand Up @@ -462,6 +463,8 @@ map<Quantity, const sigrok::Quantity *> 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<const sigrok::QuantityFlag *, QuantityFlag> sr_quantity_flag_quantity_flag_map = {
Expand Down
63 changes: 58 additions & 5 deletions src/ui/dialogs/connectdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ using sigrok::Driver;

using sv::devices::HardwareDevice;

Q_DECLARE_METATYPE(const sigrok::ConfigKey *)

namespace sv {
namespace ui {
namespace dialogs {
Expand All @@ -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),
Expand All @@ -79,13 +82,18 @@ ConnectDialog::ConnectDialog(sv::DeviceManager &device_manager,
connect(this, &ConnectDialog::populate_serials_done,
this, &ConnectDialog::populate_serials_finish);

populate_filters();
connect(&filters_, QOverload<int>::of(&QComboBox::activated),
this, &ConnectDialog::filter_selected);

populate_drivers();
connect(&drivers_, QOverload<int>::of(&QComboBox::activated),
this, &ConnectDialog::driver_selected);

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);
Expand Down Expand Up @@ -213,17 +221,50 @@ shared_ptr<HardwareDevice> ConnectDialog::get_selected_device() const
return item->data(Qt::UserRole).value<shared_ptr<HardwareDevice>>();
}

void ConnectDialog::populate_drivers()
void ConnectDialog::populate_drivers(std::set<const sigrok::ConfigKey *> 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<QString, QVariant> 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);
}
}

Expand Down Expand Up @@ -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<const sigrok::ConfigKey *> filters_set;

if (filters_.itemData(index).isValid()) {
QVariant data = filters_.itemData(index);
filters_set.insert(data.value<const sigrok::ConfigKey *>());
}

populate_drivers(filters_set);
}

void ConnectDialog::driver_selected(int index)
{
shared_ptr<Driver> driver =
Expand Down
6 changes: 5 additions & 1 deletion src/ui/dialogs/connectdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ class ConnectDialog : public QDialog
shared_ptr<sv::devices::HardwareDevice> get_selected_device() const;

private:
void populate_drivers();
void populate_drivers(std::set<const sigrok::ConfigKey *> filters_set =
std::set<const sigrok::ConfigKey *>());
void populate_filters();
void populate_serials_start(shared_ptr<sigrok::Driver> driver);
void populate_serials_thread_proc(shared_ptr<sigrok::Driver> 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);
Expand All @@ -99,6 +102,7 @@ private Q_SLOTS:
QWidget form_;
QFormLayout form_layout_;

QComboBox filters_;
QComboBox drivers_;

QRadioButton *radiobtn_usb_;
Expand Down
5 changes: 2 additions & 3 deletions src/ui/dialogs/generatewaveformdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
21 changes: 17 additions & 4 deletions src/ui/views/powerpanelview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down