From 9663c82b7fa8ec54ece3045b41bbc4a53db8bb0b Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 29 Dec 2012 14:57:10 +0000 Subject: [PATCH] Initial manual connect dialog with a serial port selector --- CMakeLists.txt | 2 + pv/dialogs/connect.cpp | 114 +++++++++++++++++++++++++++++++++++++++++ pv/dialogs/connect.h | 67 ++++++++++++++++++++++++ pv/mainwindow.cpp | 16 ++++++ pv/mainwindow.h | 3 ++ 5 files changed, 202 insertions(+) create mode 100644 pv/dialogs/connect.cpp create mode 100644 pv/dialogs/connect.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d093be7..7db89f81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,7 @@ set(pulseview_SOURCES pv/data/signaldata.cpp pv/data/snapshot.cpp pv/dialogs/about.cpp + pv/dialogs/connect.cpp pv/dialogs/deviceoptions.cpp pv/prop/double.cpp pv/prop/enum.cpp @@ -122,6 +123,7 @@ set(pulseview_HEADERS pv/samplingbar.h pv/sigsession.h pv/dialogs/about.h + pv/dialogs/connect.h pv/view/cursor.h pv/view/header.h pv/view/ruler.h diff --git a/pv/dialogs/connect.cpp b/pv/dialogs/connect.cpp new file mode 100644 index 00000000..03a03f26 --- /dev/null +++ b/pv/dialogs/connect.cpp @@ -0,0 +1,114 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012-2013 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "connect.h" + +extern "C" { +/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */ +#define __STDC_FORMAT_MACROS +#include +#include +} + +namespace pv { +namespace dialogs { + +Connect::Connect(QWidget *parent) : + QDialog(parent), + _layout(this), + _form(this), + _form_layout(&_form), + _drivers(&_form), + _serial_device(&_form), + _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, + Qt::Horizontal, this) +{ + setWindowTitle(tr("Connect to Device")); + + connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); + connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); + + populate_drivers(); + connect(&_drivers, SIGNAL(activated(int)), + this, SLOT(device_selected(int))); + + _form.setLayout(&_form_layout); + _form_layout.addRow(tr("Driver"), &_drivers); + + _form_layout.addRow(tr("Serial Port"), &_serial_device); + + unset_connection(); + + setLayout(&_layout); + _layout.addWidget(&_form); + _layout.addWidget(&_button_box); +} + +void Connect::populate_drivers() +{ + struct sr_dev_driver **drivers = sr_driver_list(); + for (int i = 0; drivers[i]; ++i) + _drivers.addItem(QString("%1 (%2)").arg( + drivers[i]->longname).arg(drivers[i]->name), + qVariantFromValue((void*)drivers[i])); +} + +void Connect::device_selected(int index) +{ + const int *hwopts; + const struct sr_hwcap_option *hwo; + sr_dev_driver *const driver = (sr_dev_driver*)_drivers.itemData( + index).value(); + + unset_connection(); + + if ((sr_config_list(driver, SR_CONF_SCAN_OPTIONS, + (const void **)&hwopts, NULL) == SR_OK) && hwopts) { + + for (int i = 0; hwopts[i]; i++) { + switch(hwopts[i]) { + case SR_CONF_SERIALCOMM: + set_serial_connection(); + break; + + default: + continue; + } + + break; + } + } +} + +void Connect::unset_connection() +{ + _serial_device.hide(); + _form_layout.labelForField(&_serial_device)->hide(); +} + +void Connect::set_serial_connection() +{ + _serial_device.show(); + _form_layout.labelForField(&_serial_device)->show(); +} + + +} // namespace dialogs +} // namespace pv diff --git a/pv/dialogs/connect.h b/pv/dialogs/connect.h new file mode 100644 index 00000000..443f6e07 --- /dev/null +++ b/pv/dialogs/connect.h @@ -0,0 +1,67 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012-2013 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PULSEVIEW_PV_CONNECT_H +#define PULSEVIEW_PV_CONNECT_H + +#include +#include +#include +#include +#include +#include + +namespace pv { +namespace dialogs { + +class Connect : public QDialog +{ + Q_OBJECT + +public: + Connect(QWidget *parent); + +private: + void populate_drivers(); + +private slots: + void device_selected(int index); + + void unset_connection(); + + void set_serial_connection(); + +private: + QVBoxLayout _layout; + + QWidget _form; + QFormLayout _form_layout; + + QComboBox _drivers; + + QLineEdit _serial_device; + + QDialogButtonBox _button_box; +}; + +} // namespace dialogs +} // namespace pv + +#endif // PULSEVIEW_PV_CONNECT_H diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 99e54568..82087ee0 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -33,6 +33,7 @@ #include "mainwindow.h" #include "samplingbar.h" #include "dialogs/about.h" +#include "dialogs/connect.h" #include "view/view.h" /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */ @@ -100,6 +101,15 @@ void MainWindow::setup_ui() _menu_file->addSeparator(); + _action_connect = new QAction(this); + _action_connect->setText(QApplication::translate( + "MainWindow", "&Connect to Device...", 0, + QApplication::UnicodeUTF8)); + _action_connect->setObjectName(QString::fromUtf8("actionConnect")); + _menu_file->addAction(_action_connect); + + _menu_file->addSeparator(); + _action_quit = new QAction(this); _action_quit->setText(QApplication::translate( "MainWindow", "&Quit", 0, QApplication::UnicodeUTF8)); @@ -195,6 +205,12 @@ void MainWindow::on_actionOpen_triggered() load_file(file_name); } +void MainWindow::on_actionConnect_triggered() +{ + dialogs::Connect dlg(this); + dlg.exec(); +} + void MainWindow::on_actionQuit_triggered() { close(); diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 32b8f6f3..993c6084 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -60,6 +60,7 @@ private: QMenuBar *_menu_bar; QMenu *_menu_file; QAction *_action_open; + QAction *_action_connect; QAction *_action_quit; QMenu *_menu_view; @@ -82,6 +83,8 @@ private slots: void on_actionOpen_triggered(); void on_actionQuit_triggered(); + void on_actionConnect_triggered(); + void on_actionViewZoomIn_triggered(); void on_actionViewZoomOut_triggered(); -- 2.30.2